是不是微信支付官方文档看得头大?是不是java、php、go各种官方demo看得头大?我不仅头大,我还窝火,用这个就ok。仅限linux用户,windows用户请出门右转
#!/bin/bash MONEY=金额,单位是分 OPENID='谁要付款就用他的openid' ORDER_ID='订单号,你自定即可' MCHID='你的商户号' CERT_SN='你的api接口证书序列号' APPID='你的appid' GOODS_DESC='商品描述信息' NOTIFY_URL='你自己做一个用来接收微信支付平台通知你的url' PRIV_KEY='你的api接口证书私钥名字叫apiclient_key.pem' METHOD='POST' URL_PATH='/v3/pay/transactions/jsapi' TIMESTAMP=`date +%s` NONCE_STR=`hexdump -n 16 -e '4/4 "%08X" 1 "\n"' /dev/random` POST_DATA="{\"mchid\":\"$MCHID\",\"out_trade_no\":\"$ORDER_ID\",\"appid\":\"$APPID\",\"description\":\"$GOODS_DESC\",\"notify_url\":\"$NOTIFY_URL\",\"amount\":{\"total\":$MONEY,\"currency\":\"CNY\"},\"payer\":{\"openid\":\"$OPENID\"}}" oneline="$METHOD\n$URL_PATH\n$TIMESTAMP\n$NONCE_STR\n$POST_DATA\n" #echo $oneline signstr=`echo -n -e "$oneline" | openssl dgst -sha256 -sign "$PRIV_KEY" | openssl base64 -A` #echo $signstr prepay_id=`curl -s 'https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi' \ -H 'Content-Type: application/json' \ -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"$MCHID\",serial_no=\"$CERT_SN\",nonce_str=\"$NONCE_STR\",timestamp=\"$TIMESTAMP\",signature=\"$signstr\"" \ --data-raw "$POST_DATA" |jq .prepay_id |tr -d '"'` #echo $prepay_id oneline2="$APPID\n$TIMESTAMP\n$NONCE_STR\nprepay_id=$prepay_id\n" paySign=`echo -n -e "$oneline2" | openssl dgst -sha256 -sign "$PRIV_KEY" | openssl base64 -A` #echo $paySign echo "{\"timeStamp\":\"$TIMESTAMP\",\"nonceStr\":\"$NONCE_STR\",\"package\":\"prepay_id=$prepay_id\",\"paySign\":\"$paySign\"}"
小程序拿到结果json中的四个字段发起支付请求就可以了
标签:NONCE,prepay,shell,商户,微信,echo,STR,TIMESTAMP,id From: https://www.cnblogs.com/fairychild/p/17110741.html