Mini Program Calls Payment
Update Time:2025.01.07Merchants call wx.requestPayment(OBJECT) in the Mini Program to start WeChat Pay.
1. API intro
Applicable object: Common mode Institutional mode
2. API definition
List of fields involved to generate paySign during the process of Mini Program calling the payment API:
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
Mini Program id | appId | string[1,32] | Yes | The merchant can get it after registering a Mini Program successfully. |
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=*** |
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 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.
Here we use command lines to demonstrate how to generate a signature.
|
4. Merchants call wx.requestPayment(OBJECT) in the Mini Program to start WeChat Pay.
Interface: wx.requestPayment,see Mini Program
Object parameter description:
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
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. |
Callback results:
Callback Type | errMsg | DescriptionCallback results: |
---|---|---|
success | requestPayment:ok | Calling payment successful |
fail | requestPayment:fail cancel | User cancels payment |
fail | requestPayment:fail (detail message) | Failed to call payment. The detail message is the specific failure reason returned by the backend. |
The sample code is as follows:
Example