Latest update time:2020.04.30 Release notes
Open a H5 webpage in the WeChat browser and execute JS to call a payment. API input and output data is in JSON format.
WeixinJSBridge built-in objects are invalid in other browsers.
Parameter names in the list are case sensitive. Signature verification will fail if the case is incorrect.
Applicable object:Common modeInstitutional mode
API Rules: https://wechatpay-api.gitbook.io/wechatpay-api-v3
List of web API parameters:
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
Official Account ID | appId | String(16) | Yes | The merchant can get it after registering an official account with the payment permission. Example:wx8888888888888888 |
Timestamp | timeStamp | String(32) | Yes | The current time. For details, see timestamp rules. Example:1414561699 |
Random string | nonceStr | String(32) | Yes | Random string, not longer than 32 digits. It is recommended to use the random number generation algorithm. Example:5K8264ILTKCH16CQ2502SI8ZNMTM67VS |
An extension string for order details | package | String(128) | Yes | The value of the prepay_id parameter returned by the unified order placement API, in the format of prepay_id=*** Example:prepay_id=123456789 |
Signature method | signType | String(32) | Yes | Signature type. Default is RSA. This parameter is not used in the signature. Example:RSA |
Signature | paySign | String(64) | Yes | Signature. For more information, see the paySign generation rules. Example:C380BEC2BFD727A4B6845133519F3AD6 |
Official Account ID
Timestamp
Random string
An extension string for order details
wx8888888888888888
1414561699
5K8264ILTKCH16CQ2502SI8ZNMTM67VS
prepay_id=123456789
The signature method is the same as the signature for request data. Use the merchant private key to sign the string using the SHA256-with-RSA signature algorithm, and obtain the signature value through Base64 encoding.
Description of the values returned by the payment API err_msg in the web:
Return value | Description |
---|---|
get_brand_wcpay_request:ok | Payment successful |
get_brand_wcpay_request:cancel | User cancellation during payment |
get_brand_wcpay_request:fail | Payment failure |
Note: JS API's result of get_brand_wcpay_request:ok is returned only when users make payments successfully. Due to the complexity of frontend interaction, both get_brand_wcpay_request:cancel and get_brand_wcpay_request:fail can be processed as errors or user cancellation.
function onBridgeReady(){
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId":"wx2421b1c4370ec43b", //Official Account name, passed by the merchant
"timeStamp":"1395712654",//Timestamp, number of seconds since 1970
"nonceStr":"e61463f8efa94090b1f366cccfbbb444", //Random string
"package":"prepay_id=u802345jgfjsdfgsdg888",
"signType":"RSA",//WeChat signature method:
"paySign":"70EA570631E4BB79628FBCA90534C63FF7FADD89" //WeChat signature
},
function(res){
if(res.err_msg == "get_brand_wcpay_request:ok" ) {} // The above method can be used to judge the value returned from the frontend. WeChat team reminds you that res.err_msg will return OK after users make payment successfully, but this value is not guaranteed to be absolute reliable.
}
);
}
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
}else{
onBridgeReady();
}
Customer Service Tel
Business Development
9:00-18:00
Monday-Friday GMT+8
Technical Support
WeChat Pay Global
ICP证