JSAPI can only be used in a built-in browser, but cannot be called by other browsers. The getBrandWCPayRequest interface is provided for the front-end webpage of the merchant to call. the merchant's payment permission will be verified before the call. if the merchant has the permission to initiate the payment, the payment process will begin. This section describes the interface calling rules before payment. for details about the message notification mechanism of payment status, refer to the following section. Note: all input parameters are of the string type! 1. js api Payment Interface (getBrandWCPayRequest)
JS APIs can only be used in built-in browsers, but cannot be called by other browsers. The getBrandWCPayRequest interface is provided for the front-end webpage of the merchant to call. the merchant's payment permission will be verified before the call. if the merchant has the permission to initiate the payment, the payment process will begin. This section describes the interface calling rules before payment. for details about the message notification mechanism of payment status, refer to the following section. Note: all input parameters are of the string type!
The getBrandWCPayRequest parameter is shown in Table 6-5.
Parameters |
Name |
Required |
Format |
Description |
AppId |
Public id |
Yes |
String type |
After a merchant registers a public account with the payment permission, the account can be obtained; |
TimeStamp |
Timestamp |
Yes |
String type, less than 32 bytes |
The number of seconds generated by the merchant from 00:00:00 to the present on January 1, January 1, 1970, that is, the current time, and must be converted to the string form; |
NonceStr |
Random string |
Yes |
String type, less than 32 bytes |
Random string generated by the merchant; |
Package |
Order details extension string |
Yes |
String type, less than 4096 bytes |
The merchant makes up the order information into this string. for details about the composition scheme, refer to the package group package in the interface instructions. the merchant concatenates the information according to the specifications and then transmits the information; |
SignType |
Signature method |
Yes |
String type. the parameter value is "SHA1" |
Enter as shown in the document. Currently, only SHA1 is supported; |
PaySign |
Signature |
Yes |
String type |
The merchant signs the parameters in the interface list according to the specified method, and uses the signature method marked in signType in the signature method. for details about the signature scheme, refer to the signature in the interface instructions to help the poor; after being signed by the merchant according to the specifications, it is passed in; |
Table 6-5 getBrandWCPayRequest parameters
The returned value of getBrandWCPayRequest is shown in Table 6-6.
Return value |
Description |
Err_msg |
Get_brand_wcpay_request: OK, payment successful Get_brand_wcpay_request: The user cancels the cancel payment process. Get_brand_wcpay_request: fail payment failed |
Table 6-6 getBrandWCPayRequest return values
Js api return result get_brand_wcpay_request: OK is returned only when the user successfully completes the payment. Due to the complexity of front-end interaction, get_brand_wcpay_request: cancel or get_brand_wcpay_request: fail can be handled in a unified manner for users to encounter errors or voluntarily give up without further division.
II. js api payment implementation
The following code is the official js api payment demo.
SetParameter ("bank_type", "WX"); $ wxPayHelper-> setParameter ("body", "test"); $ wxPayHelper-> setParameter ("partner ", "1900000109"); $ wxPayHelper-> setParameter ("out_trade_no", $ commonUtil-> create_noncestr (); $ wxPayHelper-> setParameter ("total_timeout", "1 "); $ wxPayHelper-> setParameter ("fee_type", "1"); $ wxPayHelper-> setParameter ("policy_url", "htttp: // www.baidu.com "); $ wxPayHelper-> setParameter ("spbill_create_ip "," 127.0.0.1 "); $ wxPayHelper-> setParameter (" input_charset "," GBK ");?>