WechatPay
WechatPay
The payment interface adopts server-side integration, namely Server To Server mode. The specific process is as follows:
- The user places an order on the applet/official account/APP/browser website
- The online store submits the order information to this interface
- FireAnt submit the order to the WeChat server, and then return the result of creating the order to the online store for the next payment step
- The online store will activate WeChat Pay based on different transaction types (different payment methods will be activated in different scenarios)
- After the user completes the payment, FireAnt will notify the online store of the result through notifyUrl
Among them, steps 2-3 involve the server submitting data and do not involve the browser. There may be some differences in the specific programming language used, Payment Submission Example。
Form parameter format description
| Name | Type | Max Length | Required | Description |
|---|---|---|---|---|
| Order information | ||||
| merNo | String | 5 | Yes | Merchant ID number Explanation: PSP assigns a unique identifier to merchants |
| gatewayNo | String | 8 | Yes | Merchant gateway number Explanation: PSP assigns a unique identifier to sub merchants |
| orderNo | String | 50 | Yes | Merchant Order Number Rule: Merchant order number. Unique identifier, do not duplicate order numbers in the same online store system |
| orderCurrency | String | 3 | Yes | Order currency Explanation: 3-digit ISO 4217 code, currency code can be found in the appendix. |
| orderAmount | String | 10 | Yes | Order amount Rule: No more than two decimal places |
| shipFee | String | 100 | No | Shipping fee Rule: No more than two decimal places |
| discount | String | 100 | No | discount Discounts default to negative values It can only be a number and is limited to 2 decimal places |
| goodsInfo | String | 5000 | No | Detailed information of goods Including the name, ID, unit price, and quantity of the goods Please refer to Appendix:Goods Information |
| Local payment information | ||||
| appid | String | 50 | No | Merchants apply for the corresponding appid for APP(or Mini program/Official account) on WeChat open platform. JSAPI/API payment is required |
| openid | String | 50 | No | Unique identifier of the user under the merchant appid JSAPI支付时必需 |
| paymentMethod | String | 50 | Yes | Payment method, fixed WeChatPay |
| tradeType | String | 50 | Yes | Transaction type JSAPI: Mini program/official account payment NATIVE: PC website payment APP: App payment MWEB: H5 payment(Mobile website payment) |
| limitPay | String | 50 | No | Payment limitation no_credit:specify that credit card payment cannot be used |
| ip | String | 50 | No | User IP Required for MWEB payment |
| Shipping information | ||||
| shipFirstName | String | 100 | No | Consignee's first name |
| shipLastName | String | 100 | No | Consignee's last name |
| shipEmail | String | 100 | No | Consignee's email |
| shipPhone | String | 100 | No | Consignee's phone |
| shipCountry | String | 100 | No | Consignee's country ISO 3166-1 country code, such as US. |
| shipState | String | 100 | No | Consignee's state |
| shipCity | String | 100 | No | Consignee's city |
| shipAddress | String | 100 | No | Consignee's address |
| shipZip | String | 100 | No | Consignee's zip |
| Other information | ||||
| notifyUrl | String | 200 | Yes | Asynchronous notification url. After the payment is completed, the platform will notify this address of the payment result through server-side POST. The asynchronous address will return OK upon receiving the request, otherwise it will return up to 3 times within a period of time |
| signInfo | String | 32 | Yes | Encrypt signature information Combine the payment submission parameters and then perform sha256 encryption. The specific parameter combination order is as follows, and the order cannot be changed:merNo + gatewayNo +orderNo + orderCurrency +orderAmount + notifyUrl + merKey(secret key, can be queried in the merchant's backend),the order of these parameters cannot be modified, and there should be no spaces or + in between Please refer to Appendix: SHA256 Encryption |
| remark | String | 500 | No | Order remark information. |
Payment Submission Example
java
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "merNo=30000&gatewayNo=30000001&orderNo=12345678&orderCurrency=USD&orderAmount=100.00&goodsInfo=image形象店-深圳腾大-QQ公仔#,#123#,#50.00#,#2&appid=wx8888888888888888&openid=oUpF8uMuAJO_M2pxb1Q9zNjWeS6o&paymentMethod=WechatPay&tradeType=JSAPI&limitPay=no_credit&ip=127.0.0.1¬ifyUrl=https://xxx.com/notifyurl&signInfo=61be55a8e2f6b4e172338b...");
Request request = new Request.Builder()
.url("https://sandbox.fireantspay.com/WxInterface")
.method("POST", body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://sandbox.fireantspay.com/WxInterface',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'merNo=30000&gatewayNo=30000001&orderNo=12345678&orderCurrency=USD&orderAmount=100.00&goodsInfo=image%E5%BD%A2%E8%B1%A1%E5%BA%97-%E6%B7%B1%E5%9C%B3%E8%85%BE%E5%A4%A7-QQ%E5%85%AC%E4%BB%94%23%2C%23123%23%2C%2350.00%23%2C%232&appid=wx8888888888888888&openid=oUpF8uMuAJO_M2pxb1Q9zNjWeS6o&paymentMethod=WechatPay&tradeType=JSAPI&limitPay=no_credit&ip=127.0.0.1¬ifyUrl=https%3A%2F%2Fxxx.com%2Fnotifyurl&signInfo=61be55a8e2f6b4e172338b...',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;js
var request = require('request')
var options = {
method: 'POST',
url: 'https://sandbox.fireantspay.com/WxInterface',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
merNo: '30000',
gatewayNo: '30000001',
orderNo: '12345678',
orderCurrency: 'USD',
orderAmount: '100.00',
goodsInfo: 'image形象店-深圳腾大-QQ公仔#,#123#,#50.00#,#2',
appid: 'wx8888888888888888',
openid: 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o',
paymentMethod: 'WechatPay',
tradeType: 'JSAPI',
limitPay: 'no_credit',
ip: '127.0.0.1',
notifyUrl: 'https://xxx.com/notifyurl',
signInfo: '61be55a8e2f6b4e172338b...'
}
}
request(options, function (error, response) {
if (error) throw new Error(error)
console.log(response.body)
})js
var settings = {
url: 'https://sandbox.fireantspay.com/WxInterface',
method: 'POST',
timeout: 0,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
merNo: '30000',
gatewayNo: '30000001',
orderNo: '12345678',
orderCurrency: 'USD',
orderAmount: '100.00',
goodsInfo: 'image形象店-深圳腾大-QQ公仔#,#123#,#50.00#,#2',
appid: 'wx8888888888888888',
openid: 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o',
paymentMethod: 'WechatPay',
tradeType: 'JSAPI',
limitPay: 'no_credit',
ip: '127.0.0.1',
notifyUrl: 'https://xxx.com/notifyurl',
signInfo: '61be55a8e2f6b4e172338b...'
}
}
$.ajax(settings).done(function (response) {
console.log(response)
})perl
curl --location 'https://sandbox.fireantspay.com/WxInterface' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'merNo=30000' \
--data-urlencode 'gatewayNo=30000001' \
--data-urlencode 'orderNo=12345678' \
--data-urlencode 'orderCurrency=USD' \
--data-urlencode 'orderAmount=100.00' \
--data-urlencode 'goodsInfo=image形象店-深圳腾大-QQ公仔#,#123#,#50.00#,#2' \
--data-urlencode 'appid=wx8888888888888888' \
--data-urlencode 'openid=oUpF8uMuAJO_M2pxb1Q9zNjWeS6o' \
--data-urlencode 'paymentMethod=WechatPay' \
--data-urlencode 'tradeType=JSAPI' \
--data-urlencode 'limitPay=no_credit' \
--data-urlencode 'ip=127.0.0.1' \
--data-urlencode 'notifyUrl=https://xxx.com/notifyurl' \
--data-urlencode 'signInfo=61be55a8e2f6b4e172338b...'WechatPay Interface Response
Response data description
The payment return data is in XML format, which needs to be parsed first before determining the payment result of the order. The specific XML parameters are as follows: Payment Response Example.
Parameter format description
| Name | Type | Max Length | Description |
|---|---|---|---|
| merNo | String | 5 | Merchant ID number Explanation: PSP assigns a unique identifier to merchants |
| gatewayNo | String | 8 | Merchant gateway number Explanation: PSP assigns a unique identifier to sub merchants |
| tradeNo | String | 50 | Merchant Order Number |
| orderNo | String | 50 | Transaction order number. Unique identifier of the order generated by PSP |
| orderCurrency | String | 3 | Order currency |
| orderAmount | String | 10 | Order amount |
| orderStatus | String | 1 | Transaction status: -1: Pending 0: Failed 1: Success |
| orderInfo | String | 100 | Payment result description |
| billAddress | String | 100 | Billing descriptor Return the billing descriptor of the transaction when the payment is successful |
| returnType | String | 1 | Return type 1: Browser real-time return 2: Server real-time return 3: Server asynchronous return The data format returned by the server in real-time is XML, while the data format returned by the server asynchronously and by the browser is NVP. |
| orderErrorCode | String | 50 | Error Code Error codes corresponding to various reasons for failure. When successful, it is usually 00. |
| paymentMethod | String | 50 | Payment method, fixed WeChatPay |
| signInfo | String | 32 | Encrypt signature information Combine the payment submission parameters and then perform sha256 encryption. The specific parameter combination order is as follows, and the order cannot be changed. sha256(merNo + gatewayNo + tradeNo+orderNo + orderCurrency + orderAmount + orderStatus + orderInfo + merKey) |
| remark | String | 500 | Remark |
| redirectUrl | String | 500 | Redirect url. Only exists when the transaction is returned for processing The content included in different transaction types of WeChat Pay varies: NATIVE: return QR code link JSAPI:Return the parameters required for Mini program/Official account to initiate payment APP: return the parameters required for App to initiate payment MWEB: return payment redirect url Please refer to the appendix: Description of redirectUrl |
Payment Response Example
Transaction Pending (JSAPI), merchants need to proceed with the next steps:
xml
<?xm1 version="1.0" encoding="UTE-8"?>
<respon>
<merNo>10000</merNo>
<gatewayNo>10000001</gatewayNo>
<tradeNo>HY024111317280195515514</tradeNo>
<orderNo>12345</orderNo>
<orderAmount>10.00</orderAmount>
<orderCurrency>USD</orderCurrency>
<orderStatus>-1</orderStatus>
<orderErrorCode>PENGDING</orderErrorCode>
<orderInfo></orderInfo>
<paymentMethod>WechatPay</paymentMethod>
<returnType>2</returnType>
<billAddress></billAddress>
<redirectUrl>timeStamp=1731546030&nonceStr=...</redirectUrl>
<signInfo>C6EB2353B92CFEA3698CE2F5332CB882...</signInfo>
<remark></remark>
</respon>Transaction failed (parameter validation failed):
xml
<?xm1 version="1.0" encoding="UTE-8"?>
<respon>
<merNo>10000</merNo>
<gatewayNo>10000001</gatewayNo>
<tradeNo>HY024111317280195515514</tradeNo>
<orderNo>12345</orderNo>
<orderAmount>10.00</orderAmount>
<orderCurrency>USD</orderCurrency>
<orderStatus>0</orderStatus>
<orderErrorCode>I0134</orderErrorCode>
<orderInfo>Appid不能为空</orderInfo>
<paymentMethod>WechatPay</paymentMethod>
<returnType>2</returnType>
<billAddress></billAddress>
<redirectUrl></redirectUrl>
<signInfo>C6EB2353B92CFEA3698CE2F5332CB882...</signInfo>
<remark></remark>
</respon>Transaction failed (WeChat server error):
xml
<?xm1 version="1.0" encoding="UTE-8"?>
<respon>
<merNo>10000</merNo>
<gatewayNo>10000001</gatewayNo>
<tradeNo>HY024111317280195515514</tradeNo>
<orderNo>12345</orderNo>
<orderAmount>10.00</orderAmount>
<orderCurrency>USD</orderCurrency>
<orderStatus>0</orderStatus>
<orderErrorCode>APPID_NOT_EXIST</orderErrorCode>
<orderInfo>APPID不存在</orderInfo>
<paymentMethod>WechatPay</paymentMethod>
<returnType>2</returnType>
<billAddress></billAddress>
<redirectUrl></redirectUrl>
<signInfo>C6EB2353B92CFEA3698CE2F5332CB882...</signInfo>
<remark></remark>
</respon>Asynchronous notification (Success):
txt
orderErrorCode=00&signInfo=4EF256E175307636299F6559C3F89CD94585D3E42DA33985BE400DCBE5FFF779&orderNo=12345&gatewayNo=10000001&tradeNo=HY024111317280195515514&orderCurrency=USD&orderStatus=1&remark=备注&orderAmount=10.00&merNo=10000&billAddress=LARTIN&orderInfo=Approved&paymentMethod=WechatPay&returnType=3