Login expired. Please log in again.

Feedback

0/300

Feedback

Submitted successfully

ok

Feedback

Network exception, please try again later

ok

Mini Program Calls Payment

Latest update time:2023.10.20 Release notes

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:

   Mini Program id 
   Timestamp 
   Random string
   An extension string for order details

Example of a string to be signed:

   wx8888888888888888
   1414561699
   5K8264ILTKch16CQ2502SI8ZNMTM67VS
   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.

$ 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==
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:


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){}
	}
)
 
{
	"code": "INVALID_REQUEST",
	"message": "Parameter format verification error",
	"detail": {
		"field": "#/properties/payer",
		"value": "1346177081915535577",
		"issue": "与ALLOF schema不符",
		"location": "body"
	}
}


    Page Navigation

About  WeChat  Pay

Powered By Tencent & Tenpay Copyright©

2005-2024 Tenpay All Rights Reserved.

Contact Us
Wechat Pay Global

WeChat Pay Global

置顶