Call Payment in H5 within Wechat
Update Time:2025.01.07Open a H5 webpage in the WeChat browser and execute JS to call a payment. API input and output data is in JSON format.
|
1. API intro
Applicable object: Common mode Institutional mode
2. API definition
This API has no backend interface interaction, and the data in the list needs to be signed.
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
Official Account ID | appId | string[1,16] | Yes | The merchant can get it after registering an official account with the payment permission. |
Timestamp | timeStamp | string[1,32] | Yes | The current time. For details, see timestamp rules. |
Random string | nonceStr | string[1,32] | Yes | Random string, not longer than 32 digits. It is recommended to use the random number generation algorithm. |
An extension string for order details | package | string[1,128] | Yes | The value of the prepay_id parameter returned by the unified order placement API, in the format of prepay_id=*** |
Signature method | signType | string[1,32] | Yes | Signature type. Default is RSA. This parameter is not used in the signature. |
Signature | paySign | string[1,64] | Yes | Signature. For more information, see the paySign generation rules. |
Description of return result values
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 |
3. paySign generation rules
3.1.Construct a signature string
There are four lines in the signature string, and each line is a parameter. Each line ends with \n (Newline character; the ASCII code value is 0x0A), and even the last line shall ends with \n. If the parameter itself ends with \n, an additional \n is also required
Signature fields and formats:
Example of a string to be signed:
3.2. Calculating signature value:
The signature functions provided by most programming languages support signing signature data. It is strongly recommended that merchants call such functions, use the merchant's private key to sign the signature string with SHA256 with RSA, and perform Base64 encoding on the signature result to obtain the signature value.
Here we use command lines to demonstrate how to generate a signature.
|
The sample code is as follows:
Example