Skip to content

Instantly share code, notes, and snippets.

@fenying
Created May 26, 2021 11:31
Show Gist options
  • Save fenying/c5e22822f98cd702d029a16145dc77d0 to your computer and use it in GitHub Desktop.
Save fenying/c5e22822f98cd702d029a16145dc77d0 to your computer and use it in GitHub Desktop.
Request wechat pay sandbox api sign key.
import * as $crypto from 'crypto';
const WEPAY_MCH_ID = 12345678;
const WEPAY_API_KEY = '';
const NONCE_STR = $crypto.randomBytes(16).toString('hex');
const REQ_SIGN = $crypto.createHash('md5')
.update(`mch_id=${WEPAY_MCH_ID}&nonce_str=${NONCE_STR}&sign_type=MD5&key=${WEPAY_API_KEY}`)
.digest('hex')
.toUpperCase();
console.log(`<xml>
<mch_id>${WEPAY_MCH_ID}</mch_id>
<nonce_str>${NONCE_STR}</nonce_str>
<sign_type>MD5</sign_type>
<sign>${REQ_SIGN}</sign>
</xml>`);
// curl -X POST curl -X POST 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey' -H 'Content-Type: application/xml' -d '...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment