Because of the technical reasons of one side, may cause the merchant to receive the final payment notice within the expected time, at this time the merchant can inquire the detailed payment status of the order by the API.
The URL for the order query API is:
Https://api.weixin.qq.com/pay/orderquery?access_token=xxxxxx
The parameters in the URL contain only the current micro-credit public platform voucher Access_token, and the real data of the order query is placed in the PostData, the format is as follows:
{
"AppID": "wwwwb4f85f3a797777",
"Package": "out_trade_no=11122&partner=1900090055&sign=4e8d0df3da0c3d0df38f",
"Timestamp": "1369745073",
"App_signature": "53cca9d47b883bd4a5c85a9300df3da0cb48565c",
"Sign_method": "SHA1"
}
The above content parameter descriptions are shown in the table.
Parameters |
Description |
AppID |
AppID of public platform accounts; |
Package |
Query the key information data of the order, including the third party unique order number out_trade_no, Tenpay merchant Body 仹 Identification Partner (that is, the Partnerid described above), signature sign, where sign is to sort the parameter dictionary order and use & Union, and finally add &key=partnerkey (unique allocation), perform MD5 operation, then turn to uppercase, and finally get sign |
Timestamp |
Linux time stamp; |
App_signature |
The signature field is generated according to the signature method described in the payment signature (paysign) Generation method: AppID, Appkey, package, timestamp; |
Sign_method |
Signature method (excluding signature generation); |
II. details of implementation
1. Get access token
This is easy, reference micro-trust public Platform Development (NUM) ACCESS TOKEN
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 Assignment
Timestamp: direct access to Programs
Sign_method: Here for SHA1
The acquisition of 1:package value of difficult points
To get sign first.
Sign is a dictionary ordering of the Out_trade_no,partner,key (Partnerkey) Three information, MD5 operations, and then uppercase
$sign = Strtoupper (MD5 ("out_trade_no=jfukdibig4zzne4n&partner=1234567890&key= Ebf5cf381de2d716d432bfda34fa9e57 "));
Package is the key information data of the query order, including the third party unique order number out_trade_no, Tenpay merchant Body 仹 Identification Partner (that is, the Partnerid described above), signature sign
$package = "out_trade_no=jfukdibig4zzne4n&partner=1234567890&sign=". $sign;
Difficulty 2: Getting app_signature
App_signature is still generated according to the signature in the payment signature (paysign) generation method, participating in the signature field: AppID, Appkey, package, timestamp;
$obj [' AppID '] = "wx0000000000000000";
$obj [' appkey '] = " 8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuli yxiyw6k ";
$obj [' package '] = $package;
$obj [' timestamp '] = $timestamp;
$WxPayHelper->get_biz_sign ($obj);
So all the parameters are obtained
3. Submit a 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 looks like this:
Include_once ("wxpayhelper.php"); 1.
Get access token $appid = "wx0000000000000000";
$appsecret = "E76050733CE76050733CE76050733CDD"; $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 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 Construction of the most troublesome app_signature $obj [' appid '] = "wx0000000000000000"; $obj [' appkey '] = " 8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuli
yxiyw6k ";
$obj [' package '] = $package;
$obj [' timestamp '] = $timestamp;
$WxPayHelper = new Wxpayhelper (); Get_biz_sign function is protected, you need to cancel it first, otherwise it will error $app _signature = $WxPayHelper->get_biz_sign ($obj); 3. Submits the constructed JSON to the micro-server, querying $jsonmenu = ' {AppID ': ' wx0000000000000000 ', ' package ': '. $package. ', ' timestamp ': '. $times
Tamp. ' "," 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, Curlopt_returntransfer, 1);
$output = curl_exec ($curl);
Curl_close ($curl);
return $output; }
Third, the order result
After the above procedure is executed, the order result is obtained 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 as shown in the table
Parameters |
Description |
Ret_code |
Query result status code, 0 indicates success, others indicate error; |
Ret_msg |
Query results error message; |
Input_charset |
Returns the encoding method in the information; |
Trade_state |
Order status, 0 for success, others for failure; |
Trade_mode |
Trading mode, 1 for instant to account, other reservations; |
Partner |
Tenpay merchant number, that is, the partnerid of the previous article; |
Bank_type |
Type of bank; |
Bank_billno |
Bank order number; |
Total_fee |
Total amount, the unit is divided; |
Fee_type |
Currency, 1 for RMB; |
transaction_id |
Tenpay order number; |
Out_trade_no |
Third party order number; |
Is_split |
Whether the split, false for no split, true for a split; |
Is_refund |
Whether refunds, false for no refunds, ture for refunds; |
Attach |
Merchant Data package, that is, the attach that the merchant fills in when the order package is generated; |
Time_end |
Payment completion time; |
Transport_fee |
Logistics cost, the unit is divided; |
Product_fee |
The cost of goods, the unit is divided; |
Discount |
Discount price, the unit is divided; |
Rmb_total_fee |
Converted into RMB after the total amount, the unit is divided, generally see total_fee can. |
If the program is wrong, it will be described in Errcode and errmsg.
The above is the micro-credit payment development in the query function of data collation, hoping to help micro-credit development to pay friends.