微信支付开发(5) 订单查询

本文介绍微信支付中订单查询功能的实现。

作者:方倍工作室

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

 

一、订单查询

因为某一方技术的原因,可能导致商户在预期时间内都收不到最终支付通知,此时商户可以通过该API来查询订单的详细支付状态。

订单查询API的URL为:

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

URL中的参数只包含目前微信公众平台凭证access_token,而订单查询的真正数据是放在PostData中的,格式如下:

{"appid" : "wwwwb4f85f3a797777","package" : "out_trade_no=11122&partner=1900090055&sign=4e8d0df3da0c3d0df38f","timestamp" : "1369745073","app_signature" : "53cca9d47b883bd4a5c85a9300df3da0cb48565c","sign_method" : "sha1"
}

上述内容参数说明如表所示。

参数

说明

appid

公众平台账户的AppId;

package

查询订单的关键信息数据,包含第三方唯一订单号out_trade_no、财付通商户身仹标识partner(即前文所述的partnerid)、签名sign,其中sign是对参数字典序排序并使用&联合起来,最后加上&key=partnerkey(唯一分配),进行md5运算,再转成全大写,最终得到sign

timestamp

linux时间戳;

app_signature

根据支付签名(paySign)生成方法中所讲的签名方式生成的,参加签名字段为:appid、appkey、package、timestamp;

sign_method

签名方法(不计入签名生成);

 

二、实现细节

1. 获得access token

这个很容易,参考微信公众平台开发(26) ACCESS TOKEN

代码如下:

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($result, true);
6 $access_token = $jsoninfo["access_token"];

2. 参数生成

appid: 直接赋值

timestamp:程序直接获取

$timestamp = time();

sign_method:这里为sha1

难点1:package 值的获得

先要获得sign

sign是out_trade_no,partner,key(partnerkey)三项信息的字典序排序,再MD5运算,再转为大写

$sign= strtoupper(md5("out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&key=ebf5cf381de2d716d432bfda34fa9e57"));

package 是查询订单的关键信息数据,包含第三方唯一订单号 out_trade_no、财付通商户身仹标识 partner(即前文所述的 partnerid) 、签名 sign

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

难点2:获得app_signature

app_signature 依然是根据支付签名(paySign)生成方法中所讲的签名方式生成的,参加签名字段为:appid、appkey、package、timestamp;

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

这样各项参数都获得了

3.提交查询

$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);

 

 

完整代码如下所示:

 1 include_once("WxPayHelper.php");
 2 
 3 //1. 获取access token
 4 $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"];
10 
11 
12 //2.准备参数
13 $timestamp = time();
14 $sign= strtoupper(md5("out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&key=asdfasdfasdfasdfasdfasdfasdfasdf"));
15 $package = "out_trade_no=JfuKdiBig4zZnE4n&partner=1234567890&sign=".$sign;
16 
17 //2.1构造最麻烦的app_signature
18 $obj['appid']          = "wx0000000000000000";
19 $obj['appkey']         = "8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6k";
20 $obj['package']        = $package;
21 $obj['timestamp']      = $timestamp;
22 $WxPayHelper = new WxPayHelper();
23 //get_biz_sign函数受保护,需要先取消一下,否则会报错
24 $app_signature  = $WxPayHelper->get_biz_sign($obj);
25 
26 //3. 将构造的json提交给微信服务器,查询
27 $jsonmenu = '
28 {
29  "appid" : "wx0000000000000000",
30  "package" : "'.$package.'",
31  "timestamp" : "'.$timestamp.'",
32  "app_signature" : "'.$app_signature.'",
33  "sign_method" : "sha1"
34 }
35 ';
36 
37 $url = "https://api.weixin.qq.com/pay/orderquery?access_token=".$access_token;
38 $result = https_request($url, $jsonmenu);
39 var_dump($result);
40 
41 function https_request($url, $data = null){
42  $curl = curl_init();
43  curl_setopt($curl, CURLOPT_URL, $url);
44  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
45  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
46  if (!empty($data)){
47      curl_setopt($curl, CURLOPT_POST, 1);
48      curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
49  }
50  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
51  $output = curl_exec($curl);
52  curl_close($curl);
53  return $output;
54 }

 

三、订单结果

上述程序执行后,获得订单结果如下

{"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": "" } }

各个字段的含义如表所示。

参数

说明

ret_code

查询结果状态码,0表明成功,其他表明错误;

ret_msg

查询结果出错信息;

input_charset

返回信息中的编码方式;

trade_state

订单状态,0为成功,其他为失败;

trade_mode

交易模式,1为即时到帐,其他保留;

partner

财付通商户号,即前文的partnerid;

bank_type

银行类型;

bank_billno

银行订单号;

total_fee

总金额,单位为分;

fee_type

币种,1为人民币;

transaction_id

财付通订单号;

out_trade_no

第三方订单号;

is_split

是否分账,false为无分账,true为有分账;

is_refund

是否退款,false为无退款,ture为退款;

attach

商户数据包,即生成订单package时商户填入的attach;

time_end

支付完成时间;

transport_fee

物流费用,单位为分;

product_fee

物品费用,单位为分;

discount

折扣价格,单位为分;

rmb_total_fee

换算成人民币之后的总金额,单位为分,一般看total_fee即可。

如果程序有误,会在errcode和errmsg描述出来。

 

 

====================================================================

方倍工作室微信公众平台账号关注方法:
1. 微信通讯录-添加朋友-查找公众号-搜索“方倍工作室”
2. 微信通讯录-添加朋友-搜号码-输入“pondbaystudio”
3. 使用微信扫描下面的二维码

转载于:https://www.cnblogs.com/lanzhi/p/6467415.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543725.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ruby 执行函数_Ruby at()函数

ruby 执行函数Ruby中的at()函数 (at() function in Ruby) If you are working with arrays in Ruby, sometimes you may need to find the element at a particular index. For meeting the purpose, we have got at() function in Ruby which is already defined in Rubys lib…

python饼形图_Python | 饼形图

python饼形图A pie plot or a pie chart is a circular statistical graphic technique, in which a circle is divided into slices with respect to numerical proportion. In a pie chart, the arc length, central angle, and area of each slice, is proportional to the …

Linux巡检

# uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # hostname # 查看计算机名 # lspci -tv # 列出所有PCI设备 # lsusb -tv # 列出所有USB设备 # lsmod # 列出加载的内核模块 # env # 查看环境变量 # fre…

appweb ejs_EJS部分

appweb ejsHi! Welcome. Today, we are going to look at EJS partials. EJS Partials help us avoid repetition of the same code on several web pages. 嗨! 欢迎。 今天,我们将看EJS局​​部函数 。 EJS Partials帮助我们避免在多个网页上重复相同的…

Struts2配置

1. 设定server a) window– preferences – myeclipse – servers – tomcat – 6.x b) 选择tomcat homedirectory c) 选择enable d) finish 2. 设定jdk环境 a) window– preferences – java – installed jres b) 如果没有对应的JDK…

ruby继承_Ruby继承

ruby继承Ruby中的继承 (Inheritance in Ruby) Inheritance is a feature of Object Oriented languages in which new classes are derived from existing classes and resulting in the formation of a hierarchy of classes. The derived class is often called as child cla…

Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题

近期在知乎看到一句话,保持学习的有一种是你看到了很多其它的牛人,不甘心,真的不甘心。Spring和hibernate整合的时候,jsp页面做展现,发现展现属性出现: org.apache.jasper.JasperException: could not init…

sql判断数据库类型数据_SQL数据类型

sql判断数据库类型数据SQL | 资料类型 (SQL | Data Types) Just like other programming languages, facilities of defining data of various types are available in SQL also. SQL supports the following data types for the specification of various data-items or field…

同事反馈环:如何实现持续改进的文化

“魔镜魔镜告诉我,谁才是最美丽的人?”,邪恶的皇后如此问道。似乎在精益和敏捷企业中也会有很多与《白雪公主》中类似的问题,如果我们没有一面可以看到我们正在做什么的镜子,我们就很难搞清楚我们有多么美丽&#xff0…

Scala懒惰瓦尔

Scala | 懒惰的瓦尔 (Scala | lazy val) Scala programming language allows the user to initialize a variable as a lazy val. A lazy variable is used when we need to save memory overheads while object creation. Using the lazy keyword, you can halt the initializ…

经典功率谱估计及Matlab仿真

原文出自:http://www.cnblogs.com/jacklu/p/5140913.html 功率谱估计在分析平稳各态遍历随机信号频率成分领域被广泛使用,并且已被成功应用到雷达信号处理、故障诊断等实际工程中。本文给出了经典功率谱估计的几类方法,并通过Matlab的实验仿真…

ruby 三目运算符_Ruby运算符

ruby 三目运算符Ruby运算符 (Ruby operators) Operators are the symbols which assist compiler or interpreter to carry out certain mathematical, logical and relational tasks and produce the results. Operators are method calls with parameters. 运算符是帮助编译器…

极验验证码流程-3.图片加密处理 图片移位

终于把图片加密给搞定了,原理是他把图分成了52个部分,然后通过移动来形成新的图片 主要的位置关系看代码 顺便吐槽下ruby,小众语言就是这么不方便,很多库都没有,百度了半天 最后换成了java来写 图片保存到本地的就不详细说了 主要…

什么是Brouter?

代理:网络设备 (Brouter: A network device) Brouter is a network device, which operates as a combination of both bridge and router. In this single device, a user will get a function of both bridge and router, as it can send out data to create a co…

11gR2 RAC时间同异常导致节点down掉问题处理

实验环境下11204的RAC环境,出现了一个节点DOWN掉的问题。检查日志信息后,在otcssd日志信息发现如下信息:2016-01-17 23:15:20.564: [ CTSS][1175029504]ctsscomm_recv_cb2: Receive incoming message event. Msgtype [3].2016-01-17 23:15…

html-iframe_HTML iframe

html-iframeiframe (Iframes) In HTML, iframes are used to display a webpage inside another webpage. 在HTML中&#xff0c; iframe用于在另一个网页内显示一个网页。 Syntax: 句法&#xff1a; <iframe src"URL"></iframe>The <iframe> tag…

ruby循环_Ruby循环

ruby循环Ruby循环 (Ruby Loops) Loops are comprised of sequentially group instructions which are executed repeatedly until a certain condition is met. Loops provide great help in making the programmers task easier. 循环由顺序执行的组指令组成&#xff0c;这些指…

后缀数组 TYVJ P1860 后缀数组

/*P1860 后缀数组时间: 1000ms / 空间: 131072KiB / Java类名: Main描述 我们定义一个字符串的后缀suffix(i)表示从s[i]到s[length(s)]这段子串。后缀数组&#xff08;Suffix array&#xff09;SA[i]中存放着一个排列&#xff0c;满足suffix(sa[i])<suffix(sa[i1]) 按照字典…

Binary XML file line #2: You must supply a layout_height attribute inflate

Android开发中遇到的奇葩问题之一&#xff1a;java.lang.NullPointerException&#xff0c;java.lang.RuntimeException:Binary XML file line #2: You must supply a layout_height attribute inflate&#xff0c;遇到这个问题说明你在非主流上测试&#xff0c;或者说是在部分…

量词逻辑量词里面的v表示?_知识表示能力问答中的人工智能量词(MCQ)

量词逻辑量词里面的v表示&#xff1f;1) How many types of quantifiers are there that are used to represent knowledge? 3 types2 typesUser can define as many quantifiers he wantsNone of the above Answer & Explanation Correct answer: 22 types There are two…