-
-
Save ubaid-me/fd508ee526d77fb33a56133aa571d219 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
// run it using ngrok | |
var url = require('url'), | |
crypto = require('crypto'), | |
querystring = require('querystring'), | |
http = require('http'), | |
port = 3000; | |
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