下載對賬單的接口如下。
https:// api.mch.weixin.qq.com/pay/downloadbill
下載對賬單時,POST數據示例如下。
<xml> <appid>wx2421b1c4370ec43b</appid> <bill_date>20141110</bill_date> <bill_type>ALL</bill_type> <mch_id>10000100</mch_id> <nonce_str>21df7dc9cd8616b56919f20d9f679233</nonce_str> <sign>332F17B766FC787203EBE9D6E40457A1</sign> </xml>
上述數據的參數說明如表17-22所示。
表17-22 下載對賬單接口的參數說明
成功時,數據以文本表格的方式返回,第一行為表頭,後面各行為對應的字段內容,字段內容與查詢訂單或退款結果一致。具體字段說明可查閱相應接口。
下載對賬單接口類的實現如下。
1 /** 2 * 下載對賬單接口 3 */ 4 class DownloadBill_pub extends Wxpay_client_pub 5 { 6 7 function __construct 8 { 9 // 設置接口鏈接 10 $this->url = "https:// api.mch.weixin.qq.com/pay/downloadbill"; 11 // 設置curl超時時間 12 $this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT; 13 } 14 15 /** 16 * 生成接口參數XML 17 */ 18 function createXml 19 { 20 try 21 { 22 if($this->parameters["bill_date"] == null ) 23 { 24 throw new SDKRuntimeException("對賬單接口中,缺少必填參數bill_date!". "<br>"); 25 } 26 $this->parameters["appid"] = WxPayConf_pub::APPID; // 公眾賬號ID 27 $this->parameters["mch_id"] = WxPayConf_pub::MCHID; // 商戶號 28 $this->parameters["nonce_str"] = $this->createNoncestr;// 隨機字符串 29 $this->parameters["sign"] = $this->getSign($this->parameters);// 簽名 30 return $this->arrayToXml($this->parameters); 31 }catch (SDKRuntimeException $e) 32 { 33 die($e->errorMessage); 34 } 35 } 36 37 /** 38 * 作用:獲取結果,默認不使用證書 39 */ 40 function getResult 41 { 42 $this->postXml; 43 $this->result = $this->xmlToArray($this->result_xml); 44 return $this->result; 45 } 46 47 }