<commit_before>var crypto = require('crypto');

var utils = {};

utils.sign = function(config){
  return function(req,res,next){
    config = config || {};
    var q = req.query;
    var token = config.wx.token;
    var signature = q.signature;  //微信加密签名
    var nonce = q.nonce;  //随机数
    var timestamp = q.timestamp; //时间戳
    var echostr = q.echostr; //随机字符串
    /* 
      1）将token、timestamp、nonce三个参数进行字典序排序 
      2）将三个参数字符串拼接成一个字符串进行sha1加密 
      3）开发者获得加密后的字符串可与signature对比，标识该请求来源于微信 
    */
    var str = [token,timestamp,nonce].sort().join('');
    var sha = crypto.createHash('sha1');
    sha.update(str);
    console.log(sha)
    if(req.method == 'GET'){
      if(sha == signature){
        res.send(echostr+'');
      }else{
        res.send('err');
      }
    }else if(req.method == 'POST'){
      if(sha != signature){
        return
      }
      next();
    }
  }
}

<commit_msg>wechat token<commit_after>var crypto = require('crypto');

var utils = {};

utils.sign = function(config){
  return function(req,res,next){
    config = config || {};
    var q = req.query;
    var token = config.wx.token;
    var signature = q.signature;  //微信加密签名
    var nonce = q.nonce;  //随机数
    var timestamp = q.timestamp; //时间戳
    var echostr = q.echostr; //随机字符串
    /* 
      1）将token、timestamp、nonce三个参数进行字典序排序 
      2）将三个参数字符串拼接成一个字符串进行sha1加密 
      3）开发者获得加密后的字符串可与signature对比，标识该请求来源于微信 
    */
    var str = [token,timestamp,nonce].sort().join('');
    var sha = crypto.createHash('sha1');
    sha.update(str);
    sha = sha.digest('hex');
    console.log(sha == signature);
    if(req.method == 'GET'){
      if(sha == signature){
        res.send(echostr+'');
      }else{
        res.send('err');
      }
      next();
    }else if(req.method == 'POST'){
      if(sha != signature){
        return
      }
      next();
    }
  }
}


{'fraction_non_alphanumeric': 0.1625269978401728, 'fraction_numerical': 0.005399568034557235, 'mean_word_length': 2.3629764065335754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5491952', 'n_tokens_mistral': 740, 'n_tokens_neox': 783, 'n_words': 121}