美文网首页
微信公众号验证token koa2

微信公众号验证token koa2

作者: jeek_lai | 来源:发表于2019-01-24 16:37 被阅读0次
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';

  }

});

相关文章

网友评论

      本文标题:微信公众号验证token koa2

      本文链接:https://www.haomeiwen.com/subject/aphujqtx.html