Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize order query developed by WeChat Pay

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to achieve order query developed by WeChat Pay, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article. Let's go and learn about it!

First, order inquiry

Due to the technology of one party, merchants may not receive the final payment notice within the expected time. At this time, merchants can query the detailed payment status of the order through the API.

The URL of order query API is:

Https://api.weixin.qq.com/pay/orderquery?access_token=xxxxxx

The parameters in URL only contain the Wechat public platform voucher access_token, while the real data for 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 parameters are described as shown in the table.

Parameters.

Description

Appid

AppId of the public platform account

Package

Query the key information data of the order, including the third party unique order number out_trade_no, the financial payment merchant identity partner (that is, the partnerid mentioned above), and the signature sign, where sign sorts the parameters in dictionary order and uses & union, and finally adds & key=partnerkey (unique allocation), performs md5 operation, and then converts it to full capitalization, and finally gets the sign.

Timestamp

Linux timestamp

App_signature

Generated according to the signature method described in the payment signature (paySign) generation method. The participating signature fields are: appid, appkey, package, timestamp.

Sign_method

Signature method (excluding signature generation)

Second, implementation details 1. Get access token

This is easy, refer to Wechat Public platform Development (26) 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 "]

two。 Parameter generation

Appid: direct assignment

Timestamp: directly obtained by the program

$timestamp = time ()

Sign_method: this is sha1

The acquisition of difficult 1:package value

You need to get the sign first.

Sign is the dictionary order of out_trade_no,partner,key (partnerkey) three items of information, followed by MD5 operation, and then converted to uppercase.

Sign= strtoupper (md5 ("out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&key=ebf5cf381de2d716d432bfda34fa9e57"))

Package is the key information data for querying orders, including third-party unique order number out_trade_no, financial payment merchant identity partner (partnerid mentioned above), and signature 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 method. The participating signature fields are: appid, appkey, package, timestamp

$obj ['appid'] = "wx0000000000000000"; $obj [' appkey'] = "8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6k"; $obj ['package'] = $package;$obj [' timestamp'] = $timest$WxPayHelper- > get_biz_sign ($obj)

So that all the parameters are obtained.

3. Submit 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. 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. Preparation parameters $timestamp = time (); $sign= strtoupper (md5 ("out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&key=asdfasdfasdfasdfasdfasdfasdfasdf")); $package = "out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&sign=". $sign;//2.1 constructs the most troublesome app_signature$obj ['appid'] = "wx0000000000000000"; $obj [' appkey'] = "8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6k"; $obj ['package'] = $package;$obj [' timestamp'] = $timest$WxPayHelper = new WxPayHelper () / / the get_biz_sign function is protected and needs to be cancelled first, otherwise it will make an error of $app_signature = $WxPayHelper- > get_biz_sign ($obj); / / 3. Submit the constructed json to the Wechat 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, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec ($curl); curl_close ($curl); return $output;} III. Order result

After the implementation of the above procedures, the order results are 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": "1218614901201405273333473135", "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 meaning of each field is shown in the table.

Parameters.

Description

Ret_code

Query result status code. 0 indicates success, others indicates error.

Ret_msg

Error message of query result

Input_charset

The encoding method in the returned information

Trade_state

Order status. 0: success, others: failure.

Trade_mode

Transaction mode, 1 for immediate arrival, other reservations

Partner

Financial payment account number, that is, the partnerid mentioned above.

Bank_type

Bank type

Bank_billno

Bank order number

Total_fee

Total amount in cents

Fee_type

Currency, 1 is RMB

Transaction_id

Caifutong order number

Out_trade_no

Third-party order number

Is_split

Whether to split the account or not. False is not divided, and true is divided.

Is_refund

Whether to refund or not. False is non-refundable and ture is 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_fee

Logistics expenses, divided by units

Product_fee

The cost of goods shall be divided in units.

Discount

Discount price in cents

Rmb_total_fee

The total amount converted into RMB, the unit is points, generally look at the total_fee.

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

The above is all the contents of the article "how to realize order query developed by WeChat Pay". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report