WeChat Payment Development (5) Order Inquiry _php Tutorial

Source: Internet
Author: User
This paper introduces the implementation of the Order inquiry function in payment.

Author: Fang Times studio

Address: http://www.cnblogs.com/txw1958/p/wxpay-order-query.html

First, order inquiry

Due to the technical reasons of one party, the merchant may not receive the final payment notice within the expected time, at which point the merchant can query the detailed payment status of the order through 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 public platform voucher Access_token, and the real data for the order query 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 above content parameter description is 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 Backup identification Partner (that is, Partnerid described above), signed sign, which is the parameter dictionary ordering and use & Union together, and finally add &key=partnerkey (unique Assignment), perform the MD5 operation, and then turn it into uppercase, eventually get sign

Timestamp

Linux time stamp;

App_signature

Based on the signature method described in the payment signature (Paysign) generation methods, participate in the signature field: AppID, Appkey, package, timestamp;

Sign_method

Signature method (not counted as signature generation);

II. details of implementation

1. Get access token

This is easy, refer to public platform development (+) ACCESS TOKEN

The code is as follows:

1 $appid = "wx0000000000000000"; 2 $appsecret = "e76050733c695748537fc4d4c21d0e2c"; 3 $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid &secret=$appsecret"; 4 $result = https_request ($url); 5 $jsoninfo = Json_decode ($resulttrue); 6 $access _token $jsoninfo ["Access_token"];

2. Parameter generation

AppID: Direct Assignment

Timestamp: Direct access to the program

$timestamp  Time ();

Sign_method: This is SHA1

The acquisition of the difficulty 1:package value

To get sign first

Sign is a dictionary ordering of Out_trade_no,partner,key (Partnerkey) three information, then MD5 operation, then capitalization

$sign Strtoupper (MD5("Out_trade_no=jfukdibig4zzne4n&partner=1234567890&key=ebf5cf381de2d716d432bfda34fa9e57") );

The package is the key information data for the enquiry order, including the third party unique order number out_trade_no, Tenpay merchant Body Backup identification Partner (the Partnerid described above), signed sign

$package = "out_trade_no=jfukdibig4zzne4n&partner=1234567890&sign=". $sign;

Difficulty 2: Get App_signature

App_signature is still generated according to the signature method described in the payment signature (paysign) generation, participating in the signature field: AppID, Appkey, package, timestamp;

$obj [' AppID ']          = "wx0000000000000000"; $obj [' Appkey ']         = "8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ovuliyxiyw6kxcrvdjenpwpw8mrutnogex8ov uliyxiyw6k "; $obj [' Package ']        $package ; $obj [' Timestamp ']      $timestamp ; $WxPayHelper New Wxpayhelper (); // get_biz_sign function is protected, need to cancel first, otherwise it will error $app _signature  $WxPayHelper->get_biz_sign ($obj);

All of these 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:

1 include_once("wxpayhelper.php");2 3 //1. Get access token4 $appid= "wx0000000000000000";5 $appsecret= "E76050733CE76050733CE76050733CDD";6 $url= "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";7 $result= Https_request ($url);8 $jsoninfo= Json_decode ($result,true);9 $access _token=$jsoninfo["Access_token"];Ten  One  A //2. Preparation Parameters - $timestamp= Time(); - $sign=Strtoupper(MD5("Out_trade_no=jfukdibig4zzne4n&partner=1234567890&key=asdfasdfasdfasdfasdfasdfasdfasdf")); the $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; A $WxPayHelper=NewWxpayhelper (); at //get_biz_sign function is protected, need to cancel first, otherwise it will error - $app _signature=$WxPayHelper->get_biz_sign ($obj); -  - //3. Submit the constructed JSON to the server, querying - $jsonmenu= ' - { in " AppID": "wx0000000000000000", -"Package": "'.$package.'", to"Timestamp": "'.$timestamp.'", +"App_signature": "'.$app _signature.'", - " Sign_method": "SHA1 " the } *'; $ Panax Notoginseng $url= "https://api.weixin.qq.com/pay/orderquery?access_token=".$access _token; - $result= Https_request ($url,$jsonmenu); the Var_dump($result); +  A functionHttps_request ($url,$data=NULL){ the     $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); the     } -curl_setopt ($curl, Curlopt_returntransfer, 1);Wuyi     $output= Curl_exec ($curl); theCurl_close ($curl); -     return $output; Wu}

Third, the order results

Once the above procedure is executed, the result of obtaining the order 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 as shown in the table.

Parameters

Description

Ret_code

Query result status code, 0 indicates success, others indicate error;

Ret_msg

Query result error message;

Input_charset

The encoding method in the return 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, which is the partnerid of the preceding article;

Bank_type

Bank type;

Bank_billno

Bank order number;

Total_fee

The total amount, in units of points;

Fee_type

Currency, 1 is RMB;

transaction_id

Tenpay order number;

Out_trade_no

Third-party order number;

Is_split

Whether to split, false for no split, true to have a split;

Is_refund

Refunds, false for no refunds, ture for refunds;

Attach

Merchant packet, the attach that the merchant fills in when the order package is generated;

Time_end

Payment completion time;

Transport_fee

Logistics costs, units for points;

Product_fee

The cost of goods, units for the points;

Discount

Discount price, in units of points;

Rmb_total_fee

Converted into renminbi after the total amount, units for points, generally see Total_fee can.

If the program is wrong, it will be described in errcode and errmsg .

http://www.bkjia.com/PHPjc/777156.html www.bkjia.com true http://www.bkjia.com/PHPjc/777156.html techarticle This paper introduces the implementation of the Order inquiry function in payment. Author: Fang Times studio Address: http://www.cnblogs.com/txw1958/p/wxpay-order-query.html One, order inquiry because one party ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.