码迷,mamicode.com
首页 > 微信 > 详细

微信公众号

时间:2018-01-22 19:29:25      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:style   port   分享图片   weixin   sort   list   def   post   check   

开启服务器配置:

  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 * as crypto 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

转载自~~~我找不到地址了,反正这一段是抄的

技术分享图片

微信公众号

标签:style   port   分享图片   weixin   sort   list   def   post   check   

原文地址:https://www.cnblogs.com/insight0912/p/8330000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!