Last active
January 31, 2018 23:50
-
-
Save bitristan/10885044 to your computer and use it in GitHub Desktop.
open wechat verify with node js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = require('url'), | |
crypto = require('crypto'), | |
querystring = require('querystring'), | |
http = require('http'), | |
port = 18080; | |
var token = '***your token'; | |
http.createServer(function(req, res) { | |
if (req.method === 'GET') { | |
var queryObj = querystring.parse(url.parse(req.url).query); | |
var signature = queryObj.signature, | |
timestamp = queryObj.timestamp, | |
nonce = queryObj.nonce, | |
echostr = queryObj.echostr; | |
var sha1 = crypto.createHash('sha1'), | |
sha1Str = sha1.update([token, timestamp, nonce].sort().join('')).digest('hex'); | |
console.log("my signature: " + sha1Str); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
return res.end((sha1Str === signature) ? echostr : ''); | |
} | |
res.end(); | |
}).listen(port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment