const config = {
wechat: {
appID: '', //公众号里面取
AppSecret: '', //公众号里面取
token: '' //自定义的token
}
}
app.use(async (ctx,next)=>{
console.log(ctx.query);
const token = config.wechat.token;
const signature = ctx.query.signature;
const nonce = ctx.query.nonce;
const timestamp = ctx.query.timestamp;
const echostr = ctx.query.echostr;
console.log("parameters");
console.log( "signature: " + signature );
console.log( "nonce: " + nonce );
console.log( "timestamp: " + timestamp );
console.log( "echostr: " + echostr);
let str = [token, timestamp, nonce].sort().join('');
let sha = sha1(str);
console.log(sha, signature);
if(sha == signature){
ctx.body = echostr;
} else {
ctx.body = 'wrong';
}
});
网友评论