Skip to content

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

NameTypeMax LengthRequiredDescription
Order information
merNoString5YesMerchant ID number
Explanation: PSP assigns a unique identifier to merchants
gatewayNoString8YesMerchant gateway number
Explanation: PSP assigns a unique identifier to sub merchants
orderNoString50YesMerchant Order Number
Rule: Merchant order number. Unique identifier, do not duplicate order numbers in the same online store system
orderCurrencyString3YesOrder currency
Explanation: 3-digit ISO 4217 code, currency code can be found in the appendix.
orderAmountString10YesOrder amount
Rule: No more than two decimal places
shipFeeString100NoShipping fee
Rule: No more than two decimal places
discountString100Nodiscount
Discounts default to negative values
It can only be a number and is limited to 2 decimal places
goodsInfoString5000NoDetailed information of goods
Including the name, ID, unit price, and quantity of the goods
Please refer to Appendix:Goods Information
Local payment information
appidString50NoMerchants apply for the corresponding appid for APP(or Mini program/Official account) on WeChat open platform.
JSAPI/API payment is required
openidString50NoUnique identifier of the user under the merchant appid
JSAPI支付时必需
paymentMethodString50YesPayment method, fixed WeChatPay
tradeTypeString50YesTransaction type
JSAPI: Mini program/official account payment
NATIVE: PC website payment
APP: App payment
MWEB: H5 payment(Mobile website payment)
limitPayString50NoPayment limitation
no_credit:specify that credit card payment cannot be used
ipString50NoUser IP
Required for MWEB payment
Shipping information
shipFirstNameString100NoConsignee's first name
shipLastNameString100NoConsignee's last name
shipEmailString100NoConsignee's email
shipPhoneString100NoConsignee's phone
shipCountryString100NoConsignee's country
ISO 3166-1 country code, such as US.
shipStateString100NoConsignee's state
shipCityString100NoConsignee's city
shipAddressString100NoConsignee's address
shipZipString100NoConsignee's zip
Other information
notifyUrlString200YesAsynchronous 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
signInfoString32YesEncrypt 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
remarkString500NoOrder 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&notifyUrl=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&notifyUrl=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

NameTypeMax LengthDescription
merNoString5Merchant ID number
Explanation: PSP assigns a unique identifier to merchants
gatewayNoString8Merchant gateway number
Explanation: PSP assigns a unique identifier to sub merchants
tradeNoString50Merchant Order Number
orderNoString50Transaction order number.
Unique identifier of the order generated by PSP
orderCurrencyString3Order currency
orderAmountString10Order amount
orderStatusString1Transaction status:
-1: Pending
0: Failed
1: Success
orderInfoString100Payment result description
billAddressString100Billing descriptor
Return the billing descriptor of the transaction when the payment is successful
returnTypeString1Return 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.
orderErrorCodeString50Error Code
Error codes corresponding to various reasons for failure. When successful, it is usually 00.
paymentMethodString50Payment method, fixed WeChatPay
signInfoString32Encrypt 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)
remarkString500Remark
redirectUrlString500Redirect 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