Mini Program Calls Payment

Update Time:2025.01.07

Merchants 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.
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

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:

1   Mini Program id 
2   Timestamp 
3   Random string
4   An extension string for order details

Example of a string to be signed:

1   wx8888888888888888
2   1414561699
3   5K8264ILTKch16CQ2502SI8ZNMTM67VS
4   prepay_id=123456789

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.

1$ echo -n -e \
2"wx8888888888888888\n1414561699\n5K8264ILTKCH16CQ2502SI8ZNMTM67VS\nprepay_id=wx201410272009395522657a690389285100\n" \
3  | openssl dgst -sha256 -sign apiclient_key.pem \
4  | openssl base64 -A
5  uOVRnA4qG/MNnYzdQxJanN+zU+lTgIcnU9BxGw5dKjK+VdEUz2FeIoC+D5sB/LN+nGzX3hfZg6r5wT1pl2ZobmIc6p0ldN7J6yDgUzbX8Uk3sD4a4eZVPTBvqNDoUqcYMlZ9uuDdCvNv4TM3c1WzsXUrExwVkI1XO5jCNbgDJ25nkT/c1gIFvqoogl7MdSFGc4W4xZsqCItnqbypR3RuGIlR9h9vlRsy7zJR9PBI83X8alLDIfR1ukt1P7tMnmogZ0cuDY8cZsd8ZlCgLadmvej58SLsIkVxFJ8XyUgx9FmutKSYTmYtWBZ0+tNvfGmbXU7cob8H/4nLBiCwIUFluw==

Notice

The signType parameter does not participate in signing, but needs to be passed, and its default value is "RSA". The generated signature needs to be passed through the paySign field.

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.
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 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

1wx.requestPayment
2(
3	{
4		"timeStamp": "1414561699",
5		"nonceStr": "5K8264ILTKCH16CQ2502SI8ZNMTM67VS",
6		"package": "prepay_id=wx201410272009395522657a690389285100",
7		"signType": "RSA",
8		"paySign": "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==",
9		"success":function(res){},
10		"fail":function(res){},
11		"complete":function(res){}
12	}
13)

 

 

About  WeChat  Pay

Powered By Tencent & Tenpay Copyright©

2005-2025 Tenpay All Rights Reserved.

Contact Us
Wechat Pay Global

WeChat Pay Global

Contact Us

Customer Service Tel

+86 571 95017

9:00-18:00 Monday-Friday GMT+8

Business Development

wxpayglobal@tencent.com

Developer Support

wepayTS@tencent.com

Wechat Pay Global

About Tenpay
Powered By Tencent & Tenpay Copyright© 2005-2025 Tenpay All Rights Reserved.