Due to technical reasons of one party, the merchant may fail to receive the final payment notification within the expected time. in this case, the merchant can use this API to query the detailed payment status of the order. I. order query
Due to technical reasons of one party, the merchant may fail to receive the final payment notification within the expected time. in this case, the merchant can use this API to query the detailed payment status of the order.
The order Query api url is:
Https://api.weixin.qq.com/pay/orderquery? Access_token = xxxxxx
The URL parameter only contains the current public platform credential access_token, and the real data queried by the order is placed in PostData, in the following format:
{ "appid" : "wwwwb4f85f3a797777", "package" : "out_trade_no=11122&partner=1900090055&sign=4e8d0df3da0c3d0df38f", "timestamp" : "1369745073", "app_signature" : "53cca9d47b883bd4a5c85a9300df3da0cb48565c", "sign_method" : "sha1"}
The preceding parameters are described in the table.
Parameters |
Description |
Appid |
AppId of the public platform account; |
Package |
Query the key information data of an order, including the third-party unique Order No. out_trade_no, the ID of a Tenpay Merchant (that is, the partner ID described above), and the signature sign, here, sign is to sort the parameter lexicographic order and use & Union, and then add & key = partnerkey (unique allocation) to perform md5 calculation, and then convert it to uppercase, and finally get the sign |
Timestamp |
Linux timestamp; |
App_signature |
Generated based on the signature method described in the payment signature generation method. the signature fields include appid, appkey, package, and timestamp; |
Sign_method |
Signature Method (not included in signature generation ); |
II. implementation details 1. get access token
This is very easy. For more information, see access token on the public platform (26 ).
The code is as follows:
$appid = "wx0000000000000000";$appsecret = "e76050733c695748537fc4d4c21d0e2c";$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";$result = https_request($url);$jsoninfo = json_decode($result, true);$access_token = $jsoninfo["access_token"];
2. Parameter generation
Appid: direct value assignment
Timestamp: directly obtained by the program
$timestamp = time();
Sign_method: here is sha1
Difficulty 1: obtain the package value
First obtain the sign
Sign is the lexicographically ordered sorting of the out_trade_no, partner, and key (partnerkey) information. then, it is converted to uppercase by MD5.
$sign= strtoupper(md5("out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&key=ebf5cf381de2d716d432bfda34fa9e57"));
Package is the key information data for order query, including the third-party unique Order No. out_trade_no, Fu Tong merchant ID (partner), signature sign
$package = "out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&sign=".$sign;
Difficulty 2: obtain app_signature
App_signature is still generated based on the signature method described in the payment signature generation method. the signature fields include appid, appkey, package, and timestamp;
$obj['appid'] = "wx0000000000000000";$obj['appkey'] = "8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6k";$obj['package'] = $package;$obj['timestamp'] = $timestamp;$WxPayHelper->get_biz_sign($obj);
In this way, all parameters are obtained.
3. submit the query
$jsonmenu = '{ "appid" : "wx0000000000000000", "package" : "'.$package.'", "timestamp" : "'.$timestamp.'", "app_signature" : "'.$app_signature.'", "sign_method" : "sha1"}';$url = "https://api.weixin.qq.com/pay/orderquery?access_token=".$access_token;$result = https_request($url, $jsonmenu);var_dump($result);
The complete code is as follows:
Include_once ("WxPayHelper. php"); // 1. obtain access token $ appid = "wx0000000000000000"; $ appsecret = "authorization"; $ url =" https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= $ Appid & secret = $ appsecret "; $ result = https_request ($ url); $ jsoninfo = json_decode ($ result, true); $ access_token = $ jsoninfo [" access_token "]; // 2. prepare the parameter $ timestamp = time (); $ sign = strtoupper (md5 ("out_trade_no = JfuKdiBig4zZnE4n & partner = 1234567890 & key = asdfasdfasdfasdfasdfasdfasdfasdf ")); $ package = "out_trade_no = JfuKdiBig4zZnE4n & partner = 1234567890 & sign = ". $ sign; // 2.1 construct the most troublesome app_signature $ obj ['appid '] = "wx000000000000"; $ obj ['appkey'] = "signature "; $ obj ['package'] = $ package; $ obj ['timestamp'] = $ timestamp; $ WxPayHelper = new WxPayHelper (); // The get_biz_sign function is protected, cancel the operation first. Otherwise, the error $ app_signature = $ WxPayHelper-> get_biz_sign ($ obj); // 3. submit the constructed json file to the server and query $ jsonmenu = '{"appid": "wx0000000000000000", "package ":"'. $ package. '"," timestamp ":"'. $ timestamp. '"," app_signature ":"'. $ app_signature. '"," sign_method ":" sha1 "}'; $ url =" https://api.weixin.qq.com/pay/orderquery?access_token= ". $ Access_token; $ result = https_request ($ url, $ jsonmenu); var_dump ($ result); function https_request ($ url, $ data = null) {$ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url); curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (! Empty ($ data) {curl_setopt ($ curl, CURLOPT_POST, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data);} curl_setopt ($ curl, expires, 1 ); $ output = curl_exec ($ curl); curl_close ($ curl); return $ output ;}
III. Order result
After the above program is executed, the order result is as follows:
{ "errcode": 0, "errmsg": "ok", "order_info": { "ret_code": 0, "ret_msg": "", "input_charset": "GBK", "trade_state": "0", "trade_mode": "1", "partner": "1234567890", "bank_type": "CMB_FP", "bank_billno": "201405273540085997", "total_fee": "1", "fee_type": "1", "transaction_id": "1218614901201405273313473135", "out_trade_no": "JfuKdiBig4zZnE4n", "is_split": "false", "is_refund": "false", "attach": "", "time_end": "20140527194139", "transport_fee": "0", "product_fee": "1", "discount": "0", "rmb_total_fee": "" }}
The meanings of each field are shown in the table.
Parameters |
Description |
Ret_code |
Status Code of the query result. if the value is 0, the query is successful. Otherwise, the query result is incorrect; |
Ret_msg |
Query result error information; |
Input_charset |
Encoding method in the returned information; |
Trade_state |
Order Status. if the value is 0, the order is successful. if the value is other, the order is failed; |
Trade_mode |
Transaction mode. the value 1 indicates that the account is received immediately, and other items are retained; |
Partner |
The merchant ID of Caifu Tong, that is, the partnerid of the previous article; |
Bank_type |
Bank type; |
Bank_billno |
Bank order number; |
Total_fee |
Total amount, in minutes; |
Fee_type |
Currency, 1 is RMB; |
Transaction_id |
Caifutong order number; |
Out_trade_no |
Third-party order number; |
Is_split |
Whether to subscribe to the account; false indicates no subscribe; true indicates revenue share; |
Is_refund |
Refund or not; false indicates no refund; true indicates refund; |
Attach |
Merchant data packet, that is, the attach entered by the merchant when the order package is generated; |
Time_end |
Payment completion time; |
Transport_success |
Logistics fee, unit: minute; |
Product_detail |
Item fee, unit: minute; |
Discount |
Discount price, in the unit of points; |
RMB _total_fee |
The total amount after being converted into RMB. unit: Minute. Generally, you can use total_fee. |
If the program is incorrect, it will be described in errcode and errmsg.
For more information about payment development order query, see PHP Chinese website!