Micro-channel pay signature algorithm JavaScript version, the parameter name ASCII codes from small to large; 0, A, B, a, b;

  // payment md5 encryption obtain Sign 
  paysignjs: function (jsonobj) {
     var signstr = the this .obj2str (jsonobj) 
    signstr = signstr + 'Key & =' + Key; 
    the console.log ( "signstrkey:" , signstr)
     var Sign = md5util. hexMD5 (signstr); // verification call returns proactive notification or micro channel signature, sign parameter transfer does not participate in the signature, and the signature generated sign value for calibration. 
    return sign.toUpperCase () 
  }, 
  // Object turn string, the signature for calculated 
  obj2str: function (args) {
     var Keys = Object.keys (args) 
    Keys = dict keys.sort () //ASCII code parameter name in ascending order (lexicographical); 
    var newArgs = {} 
    keys.forEach ( function (Key) {
       IF !! (Args [Key] = "" && args [Key] = 'undefined') {   / / If the value parameter is null does not participate in the signature; 
        newArgs [Key] = args [Key]   // parameter names are case sensitive; 
      } 
      
    }) 
    var String = ''
     for ( var K in newArgs) { 
      String + = '&' + K + '=' + newArgs [K] 
    } 
    String = String.substr (. 1 )
     return String 
  }, 
  // random function generating:
  createNonceStr: function () {
     return . Math.random () toString (36) .substr (2, 15)    // random decimal, hexadecimal converter 36, 0. removed, retain the remaining part 
  },
   // function of time stamp generator , expression of the certificate to a current time, accurate to the second string 
  createTimeStamp: function () {
     return the parseInt ( new new . a Date () the getTime () / 1000) + '' 
  }

 

Guess you like

Origin www.cnblogs.com/jopny/p/11454952.html