微信公众平台开发者认证,node

纯属分享

app.js

var express = require('express');
var path = require('path');
var app = express();
var port = process.env.port||; var wx = require('./admin/wx/wx.js'); //token认证--get请求
app.get('/wx',wx.token);

wx.js

var config = require('./config/config.js');
var API = require('wechat-api');
var url = require("url");
var crypto = require("crypto");
function wx(){
//token认证
this.token = function(req,res){
function sha1(str){
var md5sum = crypto.createHash("sha1");
md5sum.update(str);
str = md5sum.digest("hex");
return str;
}
var query = url.parse(req.url,true).query;
var signature = query.signature;
var echostr = query.echostr;
var timestamp = query['timestamp'];
var nonce = query.nonce;
var oriArray = new Array();
oriArray[] = nonce;
oriArray[] = timestamp;
oriArray[] = "weixin";//这里是你在微信开发者中心页面里填的token,而不是****
oriArray.sort();
var original = oriArray.join('');
var scyptoString = sha1(original);
if(signature == scyptoString){
res.end(echostr);
console.log("确认成功!");
}else {
res.end("false");
console.log("失败!");
}
}
}
module.exports = new wx();
上一篇:微信公众平台开发者中心服务器配置Token验证失败问题


下一篇:微信公众号开发者模式自定义菜单 node