Socket
Book a DemoInstallSign in
Socket

cxtkapi

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cxtkapi

微信小程序版淘点金api对接模块

latest
Source
npmnpm
Version
0.1.5
Version published
Maintainers
1
Created
Source

微信小程序版淘客淘点金api对接模块

众所周知,微信是不允许连接淘宝的任何链接的。并且,微信小程序也不允许使用window对象下面的一些方法,所以淘宝官方提供的tkapi是无法在微信小程序里使用的。于是,便有了我们的CxTkapi模块。

方法名类型说明
init实例方法初始化,需提供pid、etProxy、referer
getLink实例方法获取淘客链接
clear静态方法清除淘客身份信息缓存

安装

nodejs方式安装

npm install cxtkapi

bower方式安装

bower install cxtkapi

使用

注:使用该模块之前,我们得先有一台已注册到微信小程序里的合法https服务器。该服务器用于向淘宝请求etcode(我也不知道官方名叫什么,暂且这么叫)。其功能仅仅是代理请求:TKURL即可(:TKURL为内部用关键字,全大写,冒号不可省略)。

require方式

var CxTkapi = require('cxtkapi');
var tk = new CxTkapi;
tk.init({
    pid: 'mm_00000000_11111111_22222222', // 淘客pid
    etProxy: 'https://[yourhost]/?url=:TKURL', // 代理地址
    referer: 'https://[yourhost]/clothing/list.html' // 虚拟引用地址
});
// 获取淘客链接
tk.getLink('http://detail.tmall.com/item.htm?id=888888666666', function(url){
    console.log(url); // 输出淘客链接
});

引入方式

<script src="bower_components/cxtkapi/dist/cxtkapi.min.js"></script>
<script>
var tk = new CxTkapi;
tk.init({
    pid: 'mm_00000000_11111111_22222222', // 淘客pid
    etProxy: 'https://[yourhost]/?url=:TKURL', // 代理地址
    referer: 'https://[yourhost]/clothing/list.html' // 虚拟引用地址
});
// 获取淘客链接
tk.getLink('http://detail.tmall.com/item.htm?id=888888666666', function(url){
    console.log(url); // 输出淘客链接
});
</script>

清理

官方原版tkapi是把淘客的身份信息放到cookies里的,而微信小程序里我们使用的是storage。由于storage是不过期的,目前还不清楚不过期的身份信息会不会对淘客造成什么不良影响,所以建议使用完成后进行缓存清理。 建议的做法是放到微信小程序onLaunch阶段,这样每次启动都将获得一个新的身份信息。 示例如下:

App({
    onLaunch: function () {
        CxTkapi.clear(); // 清除淘客身份信息缓存
    }
})

更多

CxTkapi - github主页

issue

FAQs

Package last updated on 10 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.