zoukankan      html  css  js  c++  java
  • node(koa)微信公众号接口认证

    使用微信测试号, 花生壳内网穿透

    需要注意 token 两边都是自定义, 需要保持一致,

    const Koa = require('koa')
    const sha1 = require('sha1')
    
    const app = new Koa()
    
    const config = {
      wechat: {
        appID: '', //填写你自己的appID
        appSecret: '',  //填写你自己的appSecret
        token: ''  //填写你自己的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')
    })

    微信测试号地址  点击验证  显示配置成功即可

  • 相关阅读:
    NOI2021 题解
    CF605E Intergalaxy Trips
    P4762 [CERC2014]Virus synthesis
    特征向量与特征值
    uoj
    NOI 2021
    [NOI2011] NOI 嘉年华 【DP】
    CF1264D(组合数)
    绝对不咕
    题解 SP11985 【GOT
  • 原文地址:https://www.cnblogs.com/lfqcode/p/9628438.html
Copyright © 2011-2022 走看看