
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
众所周知,微信是不允许连接淘宝的任何链接的。并且,微信小程序也不允许使用window对象下面的一些方法,所以淘宝官方提供的tkapi是无法在微信小程序里使用的。于是,便有了我们的CxTkapi模块。
方法名 | 类型 | 说明 |
---|---|---|
init | 实例方法 | 初始化,需提供pid、etProxy、referer |
getLink | 实例方法 | 获取淘客链接 |
clear | 静态方法 | 清除淘客身份信息缓存 |
npm install cxtkapi
bower install cxtkapi
注:使用该模块之前,我们得先有一台已注册到微信小程序里的合法https服务器。该服务器用于向淘宝请求etcode(我也不知道官方名叫什么,暂且这么叫)。其功能仅仅是代理请求:TKURL
即可(:TKURL为内部用关键字,全大写,冒号不可省略)。
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主页
FAQs
微信小程序版淘点金api对接模块
The npm package cxtkapi receives a total of 0 weekly downloads. As such, cxtkapi popularity was classified as not popular.
We found that cxtkapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.