利用node+BAE搭建微信平台,token总是获取失败》》》》谁有好的文章来推荐学习下,感激
利用node+BAE搭建微信平台,token总是获取失败》》》》谁有好的文章来推荐学习下,感激
5 回复
没,你可以百度去找找吧
官方 有 demo
/**
* Created by hp on 2014/10/10.
*/
var crypto = require('crypto');
/**
* 验证token
* @param req
* @param res
*/
function validateToken(req, res) {
var query = req.query;
var signature = query.signature;//微信服务器加密字符串
var echostr = query.echostr;//随机字符串
var timestamp = query['timestamp'];//时间戳
var nonce = query.nonce;//nonce
var oriArray = new Array();
oriArray[0] = nonce;
oriArray[1] = timestamp;
oriArray[2] = "hale";//token
oriArray.sort();
var original = oriArray[0]+oriArray[1]+oriArray[2];
console.log("Original Str:"+original);
console.log("signature:"+signature);
var scyptoString = sha1(original);//将三个参数拼接加密字符串,并与服务器发送的字符串对比
if (signature == scyptoString) {
res.send(echostr);
}
else {
res.send("Bad Token!");
}
}
/**
* sha1加密
* @param str
* @returns {*}
*/
function sha1(str) {
var md5sum = crypto.createHash('sha1');
md5sum.update(str);
str = md5sum.digest('hex');
return str;
}
/**
* 重新获取access_token
* @type {validateToken}
*/
function getAccessToken(){
var appid = "";
var appsecret = "";
var url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=fdgf&secret=dfdsgfrf";
}
exports.validateToken = validateToken;
看wechat/wechat-api
@JacksonTian 楼上正确。