node 微信公众号开发token验证

var http = require("http"),
    url = require("url"),
    crypto = require("crypto");
http.createServer(function(req, res) {
    res.writeHead(200, { "Content-Type": "text/html; charset=UTF-8" });
    var query = url.parse(req.url, true).query,
        token = "webxie",
        array = [token, query.timestamp, query.nonce],
        key = array.sort().join(""),
        sha1 = crypto.createHash("sha1").update(key).digest("hex");
    if (sha1 == query.signature) { res.write(query.echostr); } else { res.write("Error, Token verification failed."); } res.end();
}).listen(80);

参考
http://www.05935.com/dai/665750/
http://blog.csdn.net/sinat_29843547/article/details/49183291
http://blog.csdn.net/yy64578537/article/details/69950819
https://segmentfault.com/a/1190000003012131

你可能感兴趣的:(node 微信公众号开发token验证)