Triment / blog

0 stars 0 forks source link

微信公众号服务器校验 #78

Open Triment opened 1 year ago

Triment commented 1 year ago

微信公众号服务器校验

app.get('/signature', async (request, reply) => {
    const { signature, timestamp, nonce, echostr } = request.query as any
    const array = ['bjshengtao9637', timestamp, nonce].sort()
    const hash = createHash('sha1')
    console.log(array)
    hash.update(array.join(''))
    if (hash.digest('hex') === signature) {
      reply.send(echostr)
    } else {
      reply.send('Invalid signature')
    }
  })