nodejs微信公众号教程

教程

登录微信公众平台 开发 基本配置

服务器配置 主要是taken和服务器地址的配置

服务器端代码

    var express = require('express');
    var crypto = require('crypto');
    
    var myconfig = {
      weixin: {
    taken: 'abc123'
      }
    };
    
    
    var app = express();
    
    app.get('/', function (req, res) {
      var signature = req.query.signature,
      timestamp = req.query.timestamp,
      noce = req.query.noce,
      echosrt = req.query.echosrt;
    
      var tempstr = [myconfig.weixin.taken,timestamp,noce].sort().join('');
      //加密方式选择sha1
      var hashCode = crypto.createHash('sha1');
      var resultCode = hashCode.update(tempstr,'utf8').digest('hex');
    
      if(resultCode === signature){
    res.send(echosrt)
      } else {
    res.send('fail')
      }
    
    })
    
    app.listen(8080,'127.0.0.1');

你可能感兴趣的:(nodejs微信公众号教程)