一、server.js文件
const express = require('express')
const app = express()
const crypto = require('crypto') //引入node内置加密模块
const randomstring = require('randomstring') //引入第三方产生随机字符串模块,来产生nonceStr
const axios = require('axios') //请求获取access_token对应的接口(查看文档)
const hash = require('./model/hash.js') //引入封装的hash加密模块
const appId = 'wxff781f2d374c2a1a'
const appSecret ='04dd0125daf8ae53d0448513fe6428e9'
const path=require('path')
const ejs = require('ejs') //引入ejs模板引擎
app.set(path.join(__dirname,'./views'),'views')
app.set('view engine','ejs')
//********************************* token验证 ***************************/
app.get('/token',(req,res)=>{
// http://hmx.nat300.top/token
console.log(req.query)
let token = 'hahaha' // 对应的 token == 'haha'
let {
signature,echostr,timestamp,nonce} = req.query // signature = timestamp + nonce + token
let str = [timestamp,nonce,token].sort(