const express = require(‘express’);
const sha1 = require(‘sha1’);
const app = express();
console.config = {
appID: ‘wx6fc8cd13eeb0bdd8’,
appsecret: ‘48bc4b28efd4514d9073df59634ffa78’,
token: ‘Conan2008’
}
app.use((req,res,next) => {
console.log(req.query);
const {signature,echostr,timestamp,nonce} = req.query;
const {token} = config;
const arr = [timestamp,nonce,token];
const arrSort = arr.sort();
// console.log(arrSort);
const str = arr.join(‘’);
// console.log(str);
const sha1Str = sha1(str);
// console.log(sha1Str);
if (sha1Str === signature) {
res.send(echostr);
}else {
res.end(‘error’);
}
})
app.listen(3000,() => console.log(‘server start successful!’));
###############################################################
###############################################################
需要使用ngrok,下载地址:
https://ngrok.com/download
命令: ngrok http 3000
###微信公众平台测试号配置