the merchant server first calls the [Order Placement API] to generate a prepayment order, and signs the obtained parameter prepay_id again before transferring it to the app to initiate payment.
1. API intro
Applicable object: Common mode Institutional mode
2. Request Parameters
This API signature has no background interface interaction, and the data in the list shall be signed
the client request field (Note: The following field names are case sensitive):
|
APPID | appId | string[1,16] | Yes | APPID corresponding to the mobile app applied by the merchant on the WeChat Open Platform Example: wx8888888888888888 |
Merchant ID | partnerid | string[1,32] | Yes | Merchant ID assigned by WeChat Pay. Example: 1900000109 |
Prepayment transaction session | prepayid | string[1,64] | Yes | Prepayment session ID generated by WeChat, which is used in subsequent API calls. The value is valid for 2 hours. Example: WX1217752501201407033233368018 |
An extension string for order details | package | string[1,128] | Yes | Specify as the static value “Sign=WXPay” Example: Sign=WXPay |
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 |
Timestamp | timestamp | string[1,10] | Yes | The current time. For details, see timestamp rules. Example: 1412000000 |
Signature | paySign | string[1,64] | Yes | Signature. For more information, see the paySign generation rules. Example: C380BEC2BFD727A4B6845133519F3AD6 |
3. paySign Generating 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

1 Account ID
2 Timestamp
3 Random string
4 Prepayment transaction session
Example of a string to be signed:

1 wx8888888888888888
2 1414561699
3 5K8264ILTKch16CQ2502SI8ZNMTM67VS
4 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.

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==
The sample code is as follows:
IOS

1PayReq *request = [[[PayReq alloc] init] autorelease];
2request.partnerId = @"10000100";
3request.prepayId= @"1101000000140415649af9fc314aa427";
4request.package = @"Sign=WXPay";
5request.nonceStr= @"a462b76e7436e98e0ed6e13c64b4fd1c";
6request.timeStamp= @"1397527777";
7request.sign= @"oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==";
8[WXApi sendReq:request];
Android

1IWXAPI api;
2PayReq request = new PayReq();
3request.appId = "wxd930ea5d5a258f4f";
4request.partnerId = "1900000109";
5request.prepayId= "1101000000140415649af9fc314aa427",;
6request.packageValue = "Sign=WXPay";
7request.nonceStr= "1101000000140429eb40476f8896f4c9";
8request.timeStamp= "1398746574";
9request.sign= "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYDSs2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==";
10api.sendReq(request);
HarmonyOS Next

1IWXAPI api;
2let req = new wxopensdk.PayReq
3req.appId = 'wxd930ea5d5a258f4f'
4req.partnerId = '1900000109'
5req.prepayId = '1101000000140415649af9fc314aa427'
6req.packageValue = 'Sign=WXPay'
7req.nonceStr = '1101000000140429eb40476f8896f4c9'
8req.timeStamp = '1398746574'
9req.sign = 'oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg=='