提供了一套JSSDK可以让网站基于淘宝开发些应用,JSSDK必须要在服务端进行签名,淘宝提供了.net,java,python和php的签名demo,由于需要,我写了个用nodejs实现的签名demo,给有需要的人使用。
var crypto = require('crypto');
var config = require('./../appconfig').Config;
/**
* Sign taobao api`.
*
* [@param](/user/param) {appkey} Key
* [@param](/user/param) {appsecret} Secret
* [@api](/user/api) public
*/
var Sign = function (appkey,appsecret) {
var timestamp = new Date().getTime();
var message = appsecret + "app_key" + appkey + "timestamp" + timestamp + appsecret;
var sign = SignByHmacMd5(message, appsecret);
return{
timestamp:timestamp,
sign:sign
}
}
var SignByHmacMd5 = function (message, secret) {
var hmac = crypto.createHmac("md5", secret);
var result= hmac.update(message).digest('hex');
return result;
}
exports.SignTaobao=Sign;
appconfig中的代码如下
exports.Config={
AppKey:"淘宝分配的appkey",
AppSecret:"淘宝分配的appsecret"
};
3 回复
为什么我生成的不对呢?提示:{"error_response":{"code":25,"msg":"Invalid signature","sub_code":"","sub_msg":""}}@mz121star
@mz121star 你的登陆组件 index_jssdk.hbs 怎么不能显示数据啊?提示{"error_response":{"code":11,"msg":"Insufficient isv permissions","sub_code":"isv.permission-api-package-limit","sub_msg":"scope ids is 207 274 287 10403 10407"}}