Unified order

Application scenario

In addition to the payment code payment scenario, the merchant system first calls the interface to generate the prepaid trading sheet in the background of WeChat payment service, returns the correct prepaid transaction session identifier, and then generates the transaction string according to different scenarios such as Native, JSAPI, APP, and so on.

State machine

The payment status changes are as follows:

Interface link

URL address: https://api.mch.weixin.qq.com/pay/unifiedorder

URL address: https://api2.mch.weixin.qq.com/pay/unifiedorder (standby domain name) See inter city disaster plan

Do you need certificates?

no

Request parameters

Field name Variable name Must fill type Example value describe
Public account ID Appid yes String (32) Wxd678efh567hg6787 WeChat pays public account ID (enterprise number Corpid is appId).
Merchant number Mch_id yes String (32) One billion two hundred and thirty million one hundred and nine WeChat payment distribution merchant number
Device number Device_info no String (32) 013467007045764 Custom parameters can be used for the terminal device number (store number or cash register equipment ID), PC web page or public number to pay the "WEB".
Random string Nonce_str yes String (32) 5K8264ILTKCH16CQ2502SI8ZNMTM67VS The random string length is less than 32 bits. Recommend Random number generation algorithm
autograph Sign yes String (32) C380BEC2BFD727A4B6845133519F3AD6 The signature value calculated by the signature algorithm is shown in detail. Signature generation algorithm
Signature type Sign_type no String (32) MD5 The signature type is MD5 by default, supporting HMAC-SHA256 and MD5.
Commodity Description Body yes String (128) Tencent recharge center -QQ member recharge

The commodity is simply described. Please follow the specification according to the specification. Parameter requirement

Commodity details Detail no String (6000)   Detailed description of goods, for the use of single discount merchants, the field must be uploaded according to the specifications, see "Single product preferences parameters"
Additional data Attach no String (127) Shenzhen branch Additional data is returned in the query API and payment notification, which can be used as a custom parameter.
Merchant order number Out_trade_no yes String (32) Twenty trillion and one hundred and fifty billion eight hundred and six million one hundred and twenty-five thousand three hundred and forty-six The order number in the merchant system requires only 32 characters, only numeric, uppercase and lowercase letters * - * and the only one under the same merchant number. See for details Merchant order number
Price currency Fee_type no String (16) CNY The three bit alphabetic code conforms to the ISO 4217 standard. The default is RMB: CNY. See the detailed list. Currency type
Marked price Total_fee yes Int Eighty-eight The total amount of the order is divided into units. Payment amount
Terminal IP Spbill_create_ip yes String (64) 123.12.12.123 Supports IP addresses in two formats of IPV4 and IPV6. User's client IP
Transaction start time Time_start no String (14) Twenty trillion and ninety-one billion two hundred and twenty-five million ninety-one thousand and ten The order generation time is yyyyMMddHHmmss, which is 20091225091010 at 9:10 on December 25, 2009. 10. Other details Time rule
End of transaction Time_expire no String (14) Twenty trillion and ninety-one billion two hundred and twenty-seven million ninety-one thousand and ten

The order failure time is yyyyMMddHHmmss, which is 20091227091010 at 9:10 on December 27, 2009. 10. The order failure time is for the order number. Because there is a required parameter prepay_id when the request is paid, there is only a two hour expiration date, so when the reentrant time exceeds 2 hours, you need to re request the next interface to get the new prepay_id. Other details Time rule

Time_expire can only transmit the single pass value for the first time, does not allow the two modification, and the two modification system will report wrong. If the user fails to pay, it needs to pay again. It is necessary to replace the original order number and place the order again.

Recommendation: the shortest failure time interval is greater than 1 minutes.

Order discount sign Goods_tag no String (32) WXG Order discount mark, using the voucher or setting up the discount function parameters, specify the details. Voucher or discount
Notification address Notify_url yes String (256) Http://www.weixin.qq.com/wxpay/pay.php Receives the callback address of WeChat payment result notification asynchronously, notifications that URL must be URL accessible by external network, and can not carry parameters.
Transaction type Trade_type yes String (16) JSAPI

JSAPI -JSAPI payment

NATIVE -Native payment

APP -APP payment

Detailed description Parameter requirement

Commodity ID Product_id no String (32) 12235413214070356458058 When trade_type=NATIVE, this parameter must be transmitted. This parameter is defined as the commodity ID contained in the two-dimensional code, which is defined by the merchant himself.
Designated payment method Limit_pay no String (32) No_credit Uploading this parameter no_credit-- can restrict users from using credit card payment.
User ID Openid no String (128) OUpF8uMuAJO_M2pxb1Q9zNjWeS6o When trade_type=JSAPI (i.e. JSAPI payment), this parameter will be passed. This parameter is the unique identifier for WeChat users under the appid corresponding to the merchant. How can openid be obtained? Get openid ] Please use the enterprise number. Enterprise number OAuth2.0 interface Get the member userid in the enterprise number and call it again. Enterprise number userid to openid interface Conversion
Electronic invoice entry logo Receipt no String (8) Y Y, when Y is introduced, there will be a ticket entry for payment success information and payment details page. It is necessary to open the electronic invoice function on WeChat payment platform or WeChat public platform.
+ Scene information Scene_info no String (256)

{"store_info": {
"Id": "SZTX001".
"Name": "Tengda restaurant".
"Area_code": "440305".
"Address": "Tencent Building in the Science Park"

This field is often used to report the scene information under offline activities, and support the actual store information. Merchants can also report relevant information on demand. The field is JSON object data. The object format is {"store_info": {"Id": "store ID", "name": "name", "area_code": "encoding", "address": "address" "{" {"{" "{" {{{{{{"> > >, please click on" + ".

Examples are as follows:

<xml>
<appid>wx2421b1c4370ec43b</appid>
<attach> payment test </attach>
<body>JSAPI payment test </body>
<mch_id>10000100</mch_id>
"Iphone6s_16G", "wxpay_goods_id": "1001", "goods_name": "iPhone6s 16G", "quantity": "1", "528800", "528800", "123456", "apple", "apple", "apple". <detail><! [CDATA[{ "goods_detail": "goods_id":
<nonce_str>1add1a30ac87aa2db72f57a2375d8fec</nonce_str>
<notify_url>http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php</notify_url>
<openid>oUpF8uMuAJO_M2pxb1Q9zNjWeS6o</openid>
<out_trade_no>1415659990</out_trade_no>
<spbill_create_ip>14.23.150.211</spbill_create_ip>
<total_fee>1</total_fee>
<trade_type>JSAPI</trade_type>
<sign>0CB01533B8C1EF103065174F50BCA001</sign>
</xml>

Note: the parameter value is transferred by XML, and the CDATA tag is used to explain that the data is not parsed by the XML parser.

Return result

Field name Variable name Must fill type Example value describe
Return status code Return_code yes String (16) SUCCESS

SUCCESS/FAIL

This field is a communication identifier, a non transaction identifier, and whether the transaction is successful needs to be judged by result_code.

Return information Return_msg yes String (128) OK

When return_code is FAIL, the return information is the cause of the error, for example

Signature failed

Error checking of parameter format

The following fields return when return_code is SUCCESS.

Field name Variable name Must fill type Example value describe
Public account ID Appid yes String (32) Wx8888888888888888 Calling the interface to submit the public account ID
Merchant number Mch_id yes String (32) One billion nine hundred million one hundred and nine Merchant number submitted by calling interface
Device number Device_info no String (32) 013467007045764 Custom parameters can be used to request the payment of terminal devices, etc.
Random string Nonce_str yes String (32) 5K8264ILTKCH16CQ2502SI8ZNMTM67VS The random string returned by WeChat
autograph Sign yes String (32) C380BEC2BFD727A4B6845133519F3AD6 The signature value returned by WeChat is detailed. signature algorithm
Business results Result_code yes String (16) SUCCESS SUCCESS/FAIL
error code Err_code no String (32)   When result_code is FAIL, error code is returned. See the error list below.
Error code description Err_code_des no String (128)   When result_code is FAIL, the error description is returned. See the error list below.

The following fields return when both return_code and result_code are SUCCESS.

Field name Variable name Must fill type Example value describe
Transaction type Trade_type yes String (16) JSAPI

JSAPI -JSAPI payment

NATIVE -Native payment

APP -APP payment

Detailed description Parameter requirement

Prepaid transaction session identifier Prepay_id yes String (64) Wx201410272009395522657a690389285100 The prepaid session identifier generated by WeChat is used in subsequent interface calls, which is valid for 2 hours.
Two dimensional code link Code_url no String (64) Weixin://wxpay/bizpayurl/up? Pr=NwY5Mz9&groupid=00

When trade_type=NATIVE returns, the URL is used to generate the payment of two-dimensional code, and then provide the user with sweep code payment.

Note: the value of code_url is not fixed. When used, it can be converted into two-dimensional code according to URL format.

Examples are as follows:

<xml>
<return_code><! [CDATA[SUCCESS]]></return_code>
<return_msg><! [CDATA[OK]]></return_msg>
<appid><! [CDATA[wx2421b1c4370ec43b]]></appid>
<mch_id><! [CDATA[10000100]]></mch_id>
<nonce_str><! [CDATA[IITRi8Iabbblz1Jc]]></nonce_str>
<openid><! [CDATA[oUpF8uMuAJO_M2pxb1Q9zNjWeS6o]]></openid>
<sign><! [CDATA[7921E432F65EB8ED0CE9755F0E86D72F]]></sign>
<result_code><! [CDATA[SUCCESS]]></result_code>
<prepay_id><! [CDATA[wx201411101639507cbf6ffd8b0779950874]]></prepay_id>
<trade_type><! [CDATA[JSAPI]]></trade_type>
</xml>

Error code

Name describe Reason Solution
INVALID_REQUEST Parameter error The parameter format is incorrect or not uploaded according to the rules. When the order is reentered, the parameter value is consistent with the original request. Please confirm the parameter problem.
NOAUTH Merchants do not have this interface authority. Merchants do not have permission to open this interface. Merchants are requested to apply for this interface authority.
NOTENOUGH Sorry, your credit is running low Insufficient user account balance The user account balance is insufficient. Please recharge the user or replace the payment card.
ORDERPAID Merchant orders have been paid. Merchant orders have been paid without duplication. Merchant orders have been paid without more operation.
ORDERCLOSED Order closed Current order is closed, unable to pay. The order is closed now, please re order.
SYSTEMERROR System error System timeout System exception, please call again with the same parameter.
APPID_NOT_EXIST APPID does not exist. There is no APPID in the parameter. Please check if APPID is correct.
MCHID_NOT_EXIST MCHID does not exist. There is no MCHID in the parameter. Please check if MCHID is correct.
APPID_MCHID_NOT_MATCH Appid and mch_id do not match. Appid and mch_id do not match. Please confirm whether appid matches mch_id.
LACK_PARAMS Missing parameters Lack of necessary request parameters Please check whether the parameters are complete.
OUT_TRADE_NO_USED Repeat order number The same transaction can not be submitted many times. Please verify whether the merchant's order number is submitted repeatedly.
SIGNERROR Signature error Incorrect result of parameter signature Please check that the signature parameters and methods meet the requirements of the signature algorithm.
XML_FORMAT_ERROR XML format error XML format error Please check whether the XML parameter format is correct.
REQUIRE_POST_METHOD Please use the post method. No post transfer parameters were used. Please check whether the request parameter is submitted by post method.
POST_DATA_EMPTY Post data is empty. Post data can not be empty. Please check whether the post data is empty.
NOT_UTF8 Coding format error No specified encoding format was used. Please use the UTF-8 encoding format.