名著阅读 > 微信公众平台开发:从零基础到ThinkPHP5高性能框架实践 > 17.12 退款查询 >

17.12 退款查询

查询退款的接口如下。


https:// api.mch.weixin.qq.com/pay/refundquery
  

查询退款时,POST数据示例如下。


<xml>
    <appid>wx2421b1c4370ec43b</appid>
    <mch_id>10000100</mch_id>
    <nonce_str>0b9f35f484df17a732e537c37708d1d0</nonce_str>
    <out_refund_no></out_refund_no>
    <out_trade_no>1415757673</out_trade_no>
    <refund_id></refund_id>
    <transaction_id></transaction_id>
    <sign>66FFB727015F450D167EF38CCC549521</sign>
</xml>
  

上述数据的参数说明如表17-20所示。

表17-20 查询退款接口的参数说明

正确创建时,返回的数据示例如下。


<xml>
    <appid><![CDATA[wx2421b1c4370ec43b]]></appid>
    <mch_id><![CDATA[10000100]]></mch_id>
    <nonce_str><![CDATA[TeqClE3i0mvn3DrK]]></nonce_str>
    <out_refund_no_0><![CDATA[1415701182]]></out_refund_no_0>
    <out_trade_no><![CDATA[1415757673]]></out_trade_no>
    <refund_count>1</refund_count>
    <refund_fee_0>1</refund_fee_0>
    <refund_id_0><![CDATA[2008450740201411110000174436]]></refund_id_0>
    <refund_status_0><![CDATA[PROCESSING]]></refund_status_0>
    <result_code><![CDATA[SUCCESS]]></result_code>
    <return_code><![CDATA[SUCCESS]]></return_code>
    <return_msg><![CDATA[OK]]></return_msg>
    <sign><![CDATA[1F2841558E233C33ABA71A961D27561C]]></sign>
    <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>
</xml>
  

上述数据的参数说明如表17-21所示。

表17-21 查询退款接口返回参数说明

退款查询接口类的实现代码如下。


 1 /**
 2  * 退款查询接口
 3  */
 4 class RefundQuery_pub extends Wxpay_client_pub
 5 {
 6 
 7     function __construct {
 8         // 设置接口链接
 9         $this->url = "https:// api.mch.weixin.qq.com/pay/refundquery";
10         // 设置curl超时时间
11         $this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
12     }
13 
14     /**
15      * 生成接口参数XML
16      */
17     function createXml
18     {
19         try
20         {
21             if($this->parameters["out_refund_no"] == null &&
22                 $this->parameters["out_trade_no"] == null &&
23                 $this->parameters["transaction_id"] == null &&
24                 $this->parameters["refund_id "] == null)
25             {
26                 throw new SDKRuntimeException("退款查询接口中,out_refund_no、out_
                   trade_no、transaction_id、refund_id四个参数必填一个!"."<br>");
27             }
28                $this->parameters["appid"] = WxPayConf_pub::APPID;// 公众账号ID
29                $this->parameters["mch_id"] = WxPayConf_pub::MCHID;// 商户号
30             $this->parameters["nonce_str"] = $this->createNoncestr;// 随机字符串
31             $this->parameters["sign"] = $this->getSign($this->parameters);// 签名
32             return  $this->arrayToXml($this->parameters);
33         }catch (SDKRuntimeException $e)
34         {
35             die($e->errorMessage);
36         }
37     }
38 
39     /**
40      *     作用:获取结果,使用证书通信
41      */
42     function getResult
43     {
44         $this->postXmlSSL;
45         $this->result = $this->xmlToArray($this->response);
46         return $this->result;
47     }
48 
49 }