如题 已经参考过http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html 里面6条提示 唯一不同就是url 不是动态获取,但我的测试链接肯定不会变的呀。 下面是代码,参考了官方说明文档的nodejs demo (我是使用nodejs+express+ubuntu+腾讯云)
var raw = function(args) {
var keys = Object.keys(args);
keys = keys.sort()
var newArgs = {};
keys.forEach(function(key) {
newArgs[key.toLowerCase()] = args[key];
});
var string = '';
for (var k in newArgs) {
string += '&' + k + '=' + newArgs[k];
}
string = string.substr(1);
return string;
};
var sign = function(ticket, url, noncestr, timestamp) {
var ret = {
jsapi_ticket: ticket,
noncestr: noncestr,
timestamp: timestamp,
url: url
};
// console.log('ret is:', ret)
// console.log('noncestr is:', noncestr)
var string = raw(ret);
shaObj = new jsSHA(string, 'TEXT');
ret.signature = shaObj.getHash('SHA-1', 'HEX');
return ret.signature;
};
4 回复