/** * 下载对账单,DownloadBill中bill_date为必填参数 * appid、mchid、spbill_create_ip、nonce_str不需要填入 * @param DownloadBill $inputObj * @param int $timeOut * @throws Exception * @return 成功时返回,其他抛异常 */ public static function downloadBill($inputObj, $timeOut = 6) { $url = "https://api.mch.weixin.qq.com/pay/downloadbill"; //检测必填参数 if (!$inputObj->IsBill_dateSet()) { throw new Exception("对账单接口中,缺少必填参数bill_date!"); } $inputObj->SetAppid(Config::APPID); //公众账号ID $inputObj->SetMch_id(Config::MCHID); //商户号 $inputObj->SetNonce_str(self::getNonceStr()); //随机字符串 $inputObj->SetSign(); //签名 $xml = $inputObj->ToXml(); $response = self::postXmlCurl($xml, $url, false, $timeOut); if (substr($response, 0, 5) == "<xml>") { return ""; } return $response; }
<?php /** * 对账单接口demo * ==================================================== * 商户可以通过该接口下载历史交易清单。 */ include_once "./WxPayHelper/WxPayHelper.php"; //对账单日期 if (!isset($_POST["bill_date"])) { $bill_date = date("Ymd"); } else { $bill_date = $_POST["bill_date"]; //使用对账单接口 $downloadBill = new DownloadBill(); //设置对账单接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //sign已填,商户无需重复填写 $downloadBill->setParameter("bill_date", "{$bill_date}"); //对账单日期 $downloadBill->setParameter("bill_type", "ALL"); //账单类型 //非必填参数,商户可根据实际情况选填 //$downloadBill->setParameter("device_info","XXXX");//设备号 //对账单接口结果 $downloadBillResult = $downloadBill->getResult(); echo $downloadBillResult['return_code']; if ($downloadBillResult['return_code'] == "FAIL") { echo "通信出错:" . $downloadBillResult['return_msg'];