nodejs关联公众号验证代码

微信开发文档

// 对接代码

const token = 'xxx', // 自定义,与公众号设置的一致 signature = ctx.query.signature, timestamp = ctx.query.timestamp, nonce = ctx.query.nonce // 字典排序 const arr = [token, timestamp, nonce].sort() const sha1 = crypto.createHash('sha1') sha1.update(arr.join('')) const result = sha1.digest('hex') if (result === signature) { ctx.body = ctx.query.echostr } else { ctx.body = { code: -1, msg: "fail" } }
原文地址:https://www.cnblogs.com/chefweb/p/10729560.html