微信公眾號
阿新 • • 發佈:2018-01-22
sta 找不到 list echo turn com 配置 一段 服務器配置
開啟服務器配置:
index.ts
import * as url from ‘url‘ import * as express from ‘express‘ import wechat from ‘./wechat‘ let app = express() app.get(‘/‘,function(req,res){ console.log(req.url) wechat(req,res) }) app.listen(80)
wechat.ts
import * as url from ‘url‘ import * as http from ‘http‘ import * ascrypto from ‘crypto‘ function wechat(req:Request,res:Response){ var query = url.parse(req.url,true).query; var signature = query.signature; var timestamp = query.timestamp; var nonce = query.nonce; var echostr = query.echostr;
//"weixin"需要跟配置時保持一致 if(check(timestamp,nonce,signature,"weixin")){ res.end(echostr); }else{ res.end("It is not from weixin"); } }; function check(timestamp:number,nonce:any,signature:any,token:any){ var currSign,tmp; tmp = [token,timestamp,nonce].sort().join(""); currSign = crypto.createHash("sha1").update(tmp).digest("hex"); return (currSign === signature); }; export default wechat
轉載自~~~我找不到地址了,反正這一段是抄的
微信公眾號