Skip to content

Instantly share code, notes, and snippets.

@Soul-Clinic
Last active December 15, 2015 11:07
Show Gist options
  • Save Soul-Clinic/b2813a53c8331719b547 to your computer and use it in GitHub Desktop.
Save Soul-Clinic/b2813a53c8331719b547 to your computer and use it in GitHub Desktop.
var crypto = require('crypto');
var key = 'rmyrm80lo2me1bv5o5fkpeq5yv0b61dl';
function md5 (str) {
var md5sum = crypto.createHash('md5');
md5sum.update(str);
str = md5sum.digest('hex');
return str;
};
var string = 'discount=0.00&payment_type=1&subject=Charge&trade_no=2015121500001000540067160951&buyer_email=celwk%40163.com&gmt_create=2015-12-15+18%3A28%3A43&notify_type=trade_status_sync&quantity=1&out_trade_no=AP70180020151215182814411&seller_id=2088121087841020&notify_time=2015-12-15+18%3A28%3A44&body=7018-test-3+CNY&trade_status=WAIT_BUYER_PAY&is_total_fee_adjust=Y&total_fee=0.03&seller_email=weplant%40wohuizhong.com&price=0.03&buyer_id=2088002485666544&notify_id=18c20c7f2c60dc43b6f1d90f9bd103a450&use_coupon=N&sign_type=MD5&sign=219ac1cee50707a488eb8d8bf592cb41';
var spec = decodeURIComponent(string);
//'discount=0.00&payment_type=1&subject=Charge&trade_no=2015121500001000540067160951&buyer_email=celwk%40163.com&gmt_create=2015-12-15+18%3A28%3A43&notify_type=trade_status_sync&quantity=1&out_trade_no=AP70180020151215182814411&seller_id=2088121087841020&notify_time=2015-12-15+18%3A28%3A45&body=7018-test-3+CNY&trade_status=TRADE_SUCCESS&is_total_fee_adjust=N&total_fee=0.03&gmt_payment=2015-12-15+18%3A28%3A44&seller_email=weplant%40wohuizhong.com&price=0.03&buyer_id=2088002485666544&notify_id=0e01b8cd8f02eed44b814b804d68eaba50&use_coupon=N&sign_type=MD5&sign=b850315d1030297b1edb814aafc68960');
var components = spec.split('&');
components.sort();
var components = components.filter(function (c) {
if (c.indexOf('sign') == 0) {
console.log(c);
return false;
}
return true;
});
var signString = components.join('&') + key;
console.log(signString);
var text = md5(signString);
console.log('\ntext=%s', text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment