Latest update time:2019.11.20 Release notes
The JSAPI is called when the Payer opens an HTML5 website with a WeChat-supported browser. The input and output API data is in JSON format.
1. WeixinJSBridge built-in objects are invalid in other browsers and parameter names in the list are case-sensitive.
2. "get_brand_wcpay_request:ok" is returned by the JSAPI only when the Payer completes the payment. For front-end logic, "get_brand_wcpay_request:cancel" or "get_brand_wcpay_request:fail" can be handled as payment exceptions.
Applicable object: Common modeInstitutional mode
Name | ID | Type | Required | Description |
---|---|---|---|---|
Official Account ID | appId | string(16) | Yes | This ID is issued after merchants apply for official account supporting WeChat payment. Example:wx8888888888888888 |
Timestamp | timeStamp | string(32) | Yes | Specifies the current time. For more information, see Timestamp in Parameter Specifications. Example:1414561699 |
Random string | nonceStr | string(32) | Yes | 32 characters or fewer. For more information, see Random string Algorithm. Example:5K8264ILTKCH16CQ2502SI8ZNMTM67VS |
Order Extension string | package | string(128) | Yes | Specifies the parameter value (prepay_id) returned by the Unified Order API. ?The submission format is "prepay_id=***". Example:prepay_id=123456789 |
Signature | paySign | string(64) | Yes | Specifies a signature. For more information, see Signature Algorithm. Example:C380BEC2BFD727A4B6845133519F3AD6 |
Sign type | signType | string(32) | Yes | Currently HMAC-SHA256 and MD5 are supported, default is MD5. This parameter must be submitted if HMAC-SHA256 is chosen Example:MD5 |
Field Name | Return Value | Description |
---|---|---|
success | get_brand_wcpay_request:ok | Payment successful |
fail | get_brand_wcpay_request:cancel | Payment canceled |
fail | get_brand_wcpay_request:fail | Payment failed |
fail | Missing parameter for calling payment jsapi: total_fee. | 1. Please check whether the prepayment session id "prepay_id" has expired. 2. Whether the appid currently used is consistent with the appid of the unified order API |
function?onBridgeReady(){
? ?WeixinJSBridge.invoke(
? ? ? ?'getBrandWCPayRequest',?{
? ? ? ? ? ?"appId"?:?"wx2421b1c4370ec43b",?? ??//Official Account name transferred by merchants ? ??
? ? ? ? ? ?"timeStamp":" 1395712654",?? ? ? ??//Timestamp since 1.1.1970 UTC ? ??
? ? ? ? ? ?"nonceStr"?:?"e61463f8efa94090b1f366cccfbbb444",?//Random string ? ??
? ? ? ? ? ?"package"?:?"prepay_id=u802345jgfjsdfgsdg888",?? ??
? ? ? ? ? ?"signType"?:?"MD5",?? ? ? ??//WeChat signature type: ? ??
? ? ? ? ? ?"paySign"?:?"70EA570631E4BB79628FBCA90534C63FF7FADD89"?//WeChat signature?
? ? ? ?},
? ? ? ?function(res){?? ??
? ? ? ? ? ?if(res.err_msg?==?"get_brand_wcpay_request:ok"?)?{}?? ??// Use the above method to determine values returned to the front-end. Please note that "res.err_msg" returns"ok" after a successful payment. However, WeChat doesn't guarantee its reliability.?
? ? ? ?}
? ?);?
}
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證