2023-01-29 10:26:52 +08:00

66 lines
1.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace wxpay;
use think\Loader;
require_once 'lib/WxPayException.php';
Loader::import('wxpay.lib.WxPayApi');
/**
* 下载对账单
*
* 用法:
* 调用 \wxpay\DownloadBill::exec($date, $type) 即可
*
*
*
*/
class DownloadBill
{
/**
* @param string $date 日期, 格式: yyyymmdd, 如20140603(当天的无法查询)
* @param string $type 账单类型,
* ALL返回当日所有订单信息默认值
SUCCESS返回当日成功支付的订单
REFUND返回当日退款订单
RECHARGE_REFUND返回当日充值退款订单相比其他对账单多一栏“返还手续费”
*
* @return array 账单数据
*/
public static function exec($date, $type='ALL')
{
// 1.校检参数
self::checkParams($date, $type);
// 2.组装参数
$input = new \WxPayDownloadBill();
$input->SetBill_date($date);
$input->SetBill_type($type);
$result = \WxPayApi::downloadBill($input);
// 3.处理返回结果
if (empty($result)) {
throw new \WxPayException('未查询到结果');
} else {
return $result;
}
}
/**
* 校检参数
*/
private static function checkParams($date, $type)
{
// 检测时间格式
$d = \DateTime::createFromFormat('Ymd', $date);
if(!($d && $d->format('Ymd') == $date)) {
throw new \WxPayException('$date格式不正确, 正确格式为: yyyymmdd, 如20170917');
}
$typeArr = ['ALL', 'SUCCESS', 'REFUND', 'RECHARGE_REFUND'];
if (!in_array($type, $typeArr)) {
throw new \WxPayException('$type参数错误, $type必须为ALL, SUCCESS, REFUND, RECHARGE_REFUND其中之一');
}
}
}