node(koa2)微信公众号接口认证
使用微信测试号, 花生壳内网穿透,
需要注意 token 两边都是自定义, 需要保持一致
代码实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| const Koa = require('koa') const sha1 = require('sha1')
const app = new Koa()
const config = { wechat: { appID: '', appSecret: '', token: '' } }
app.use(async (ctx) => { const token = config.wechat.token const signature = ctx.request.query.signature const nonce = ctx.request.query.nonce const timestamp = ctx.request.query.timestamp const echostr = ctx.request.query.echostr let str = [token, timestamp, nonce].sort().join('') const sha = sha1(str) ctx.body = sha === signature ? echostr + '' : 'failed' })
app.listen(8999, () => { console.log('node started port 8999') })
|
点击验证,显示配置成功即可 测试地址
广告
阿里云活动云服务器低至
1核-2G-1M,1年89元,3年229。
2核-4G-3M,2年469元,3年799。
2核-8G-5M,3年899元。
新老客户都有优惠
点击查看详情/购买
腾讯云现在活动
1核 2G 1M 88一年
2核 4G 5M 3年只要998。
点击查看详情/购买
如有问题可联系 Email:afacode@outlook.com 或 微信:afacode