Mini Program Calls Payment
Merchants call wx.requestPayment(OBJECT) in the Mini Program to start WeChat Pay.
Merchants call wx.requestPayment(OBJECT) in the Mini Program to start WeChat Pay.
Applicable object: Common mode Institutional mode
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. Example: wx8888888888888888 |
Timestamp | timeStamp | string[1,32] | Yes | The current time. For details, see timestamp rules. Example: 1414561699 |
Random string | nonceStr | string[1,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[1,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 |
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
Mini Program 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.
Here we use command lines to demonstrate how to generate a signature.
$ echo -n -e \
"wx8888888888888888\n1414561699\n5K8264ILTKCH16CQ2502SI8ZNMTM67VS\nprepay_id=wx201410272009395522657a690389285100\n" \
| openssl dgst -sha256 -sign apiclient_key.pem \
| openssl base64 -A
uOVRnA4qG/MNnYzdQxJanN+zU+lTgIcnU9BxGw5dKjK+VdEUz2FeIoC+D5sB/LN+nGzX3hfZg6r5wT1pl2ZobmIc6p0ldN7J6yDgUzbX8Uk3sD4a4eZVPTBvqNDoUqcYMlZ9uuDdCvNv4TM3c1WzsXUrExwVkI1XO5jCNbgDJ25nkT/c1gIFvqoogl7MdSFGc4W4xZsqCItnqbypR3RuGIlR9h9vlRsy7zJR9PBI83X8alLDIfR1ukt1P7tMnmogZ0cuDY8cZsd8ZlCgLadmvej58SLsIkVxFJ8XyUgx9FmutKSYTmYtWBZ0+tNvfGmbXU7cob8H/4nLBiCwIUFluw==
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. Example: 1414561699 |
Random string | nonceStr | string[1,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[1,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[1,32] | Yes | Signature type. Default is RSA. This parameter is not used in the signature. Example: RSA |
Signature | paySign | string[1,64] | Yes | Signature. For more information, see the paySign generation rules. Example: C380BEC2BFD727A4B6845133519F3AD6 |
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. |
wx.requestPayment
(
{
"timeStamp": "1414561699",
"nonceStr": "5K8264ILTKCH16CQ2502SI8ZNMTM67VS",
"package": "prepay_id=wx201410272009395522657a690389285100",
"signType": "RSA",
"paySign": "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==",
"success":function(res){},
"fail":function(res){},
"complete":function(res){}
}
)
Customer Service Tel
Business Development
9:00-18:00
Monday-Friday GMT+8
Technical Support
WeChat Pay Global
ICP证