Ejemplo n.º 1
0
<?php

require_once "lib/WxPay.Api.php";
//require_once "../lib/WxPay.MicroPay.php";
if (isset($_REQUEST["bill_date"]) && $_REQUEST["bill_date"] != "") {
    $bill_date = $_REQUEST["bill_date"];
    $bill_type = $_REQUEST["bill_type"];
    $input = new WxPayDownloadBill();
    $input->SetBill_date($bill_date);
    $input->SetBill_type($bill_type);
    $file = WxPayApi::downloadBill($input);
    $file_name = '/tmp/' . date($bill_date . '-' . date('YmdHis')) . '.csv';
    if (!empty($file)) {
        @($tempfile = fopen($file_name, 'x+'));
        fwrite($tempfile, $file);
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=" . $file_name);
        readfile($file_name);
        fclose($tempfile);
        unlink($file_name);
    } else {
        die($bill_date . '日期内暂无账单数据');
    }
    exit(0);
}
?>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1" /> 
    <title>微信支付-对账单下载</title>
Ejemplo n.º 2
0
 /**
  * 下载对账单,WxPayDownloadBill中bill_date为必填参数
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayDownloadBill $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public static function downloadBill($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/pay/downloadbill";
     //检测必填参数
     if (!$inputObj->IsBill_dateSet()) {
         throw new WxPayException("对账单接口中,缺少必填参数bill_date!");
     }
     $inputObj->SetAppid(WxPayConfig::APPID);
     //公众账号ID
     $inputObj->SetMch_id(WxPayConfig::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;
 }
Ejemplo n.º 3
0
 /**
  * 下载对账单,WxPayDownloadBill中bill_date为必填参数
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayDownloadBill $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public function downloadBill($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/pay/downloadbill";
     //检测必填参数
     if (!$inputObj->isBillDateSet()) {
         throw new WxPayException("对账单接口中,缺少必填参数bill_date!");
     }
     $inputObj->setAppid($this->apiConfig->appid);
     //公众账号ID
     $inputObj->setMchId($this->apiConfig->mchid);
     //商户号
     $inputObj->setMchKey($this->apiConfig->mchkey);
     //商户密钥
     $inputObj->setNonceStr($this->getNonceStr());
     //随机字符串
     $inputObj->setSign();
     //签名
     $xml = $inputObj->toXml();
     $response = $this->postXmlCurl($xml, $url, false, $timeOut);
     if (substr($response, 0, 5) == "<xml>") {
         return "";
     }
     return $response;
 }