1. Simulation test system
In order to lower the test threshold for merchants, the WeChat payment team developed an independent simulation test system. The system returns different response messages based on the amount of the acceptance use case to meet the merchant's needs for normal function testing, security/abnormality testing, and performance testing.
Figure 1 WeChat payment simulation test system
Figure 1 is a simplified schematic diagram of the WeChat payment simulation test system (hereinafter referred to as the simulation system). The API protocol of the simulation system is exactly the same as the official API. Merchant developers only need to add a sandboxnew path to the official API call URL to connect to the simulation system.
For example, the credit card payment URL: api.mch.weixin.qq.com/pay/micropay
is changed to: api.mch.weixin.qq.com/sandboxnew/pay/micropay.
The simulation system is completely independent from the production environment, including the storage layer. All transactions made by merchants in the simulation system (such as orders, payments, and query) are fake data without fund flow, that is, users do not need to actually deduct money, and merchants will not have funds credited to their account. The same applies to vouchers. In the sandbox environment, merchants do not need to actually create and issue vouchers, and there will be no real deductions. The API verification key for the acceptance simulation test system needs to be obtained from the API:
Get the verification key API:
Request Url | api.mch.weixin.qq.com/sandboxnew/pay/getsignkey |
---|---|
Do you need a certificate | No |
Request method | POST |
Field | Required | Example value | Type | Description | |
---|---|---|---|---|---|
mch_id | is | 1305638280 | String(32) | WeChat merchant number assigned by WeChat payment | |
characters String | nonce_stris | 5K8264ILTKCH16CQ2502SI8ZNMTM67VS | String(32) | Random string, no longer than 32 bits | |
sign | is | 5K8264ILTKCH16CQ2502SI8ZNMTM67VS | String(32) | signature value |
Field name | Field | Required | Example value | Type | Description |
---|---|---|---|---|---|
Status code | return_codeis | SUCCESS | String(16) | SUCCESS/FAIL This field is a communication identifier, not a transaction identifier | |
return_msg | No | Signature failed | String(128) | Return information, if not empty, it is an error Reason, signature failed, parameter format verification error |
Field name | Field | Required | Example value | Type | Description |
---|---|---|---|---|---|
The merchant number | mch_id | is | 1305638280 | String(32) | WeChat merchant number assigned by WeChat payment |
Sandbox key | sandbox_signkey | No | 013467007045764 | String(32) | Returned sandbox key |
Example of interaction process for merchants to access the simulation system:
1. The merchant initiates a card payment request and uses POST method to call api.mch.weixin.qq.com/sandboxnew/pay/micropay
2. https requests with sandboxnew will be routed by nginx to the simulation system. The simulation system returns the expected message to the merchant based on the payment amount (total_fee field). At the same time, the request data is landed;
3. The merchant initiates an order query, calls api.mch.weixin.qq.com/sandboxnew/pay/orderquery, and brings the WeChat order number (transaction_id) or Merchant’s internal order number (out_trade_no);
4. After receiving the order inquiry request, the simulation system returns the expected order inquiry result to the merchant based on the order number and amount;
5. The merchant downloads the statement and calls api.mch .weixin.qq.com/sandboxnew/pay/downloadbill, the simulation system returns a fixed bill format to the merchant. Note: The content of the bill is not necessarily exactly the same as the transaction generated by the merchant in the simulation system.
Use Fangbei Studio WeChat Payment AlmightyInterface class to achieve it with a few lines of code
//1.5 沙箱密钥$obj = array();$obj['mch_id'] = MCHID;$url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey';$wxHongBaoHelper = new WxPay();$data = $wxHongBaoHelper->wxpay($url, $obj, false);$res = $wxHongBaoHelper->xmlToArray($data);
Return results As follows
array(3) { ["return_code"]=> string(7) "SUCCESS" ["return_msg"]=> string(2) "ok" ["sandbox_signkey"]=> string(32) "4d827419cb511d8f6ccc35d574ff1f7b"}
In order to lower the merchant test threshold, the WeChat payment team developed an independent simulation test system. The system returns different response messages based on the amount of the acceptance use case to meet the merchant's needs for normal function testing, security/abnormality testing, and performance testing.
[Related recommendations]
1.WeChat public account platform source code download
The above is the detailed content of Detailed explanation of sandbox key steps for WeChat payment development. For more information, please follow other related articles on the PHP Chinese website!