完善更多直连商户接口

This commit is contained in:
邹景立 2023-04-28 19:45:43 +08:00
parent 200f14dba9
commit 53f3dce3dd
3 changed files with 95 additions and 10 deletions

View File

@ -135,24 +135,28 @@ abstract class BasicWePay
* @param string $method 请求访问
* @param string $pathinfo 请求路由
* @param string $jsondata 请求数据
* @param bool $verify 是否验证
* @return array
* @param boolean $verify 是否验证
* @param boolean $isjson 返回JSON
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function doRequest($method, $pathinfo, $jsondata = '', $verify = false)
public function doRequest($method, $pathinfo, $jsondata = '', $verify = false, $isjson = true)
{
list($time, $nonce) = [time(), uniqid() . rand(1000, 9999)];
$signstr = join("\n", [$method, $pathinfo, $time, $nonce, $jsondata, '']);
// 生成数据签名TOKEN
$token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$this->config['mch_id'], $nonce, $time, $this->config['cert_serial'], $this->signBuild($signstr)
);
list($header, $content) = $this->_doRequestCurl($method, $this->base . $pathinfo, [
'data' => $jsondata, 'header' => [
"Accept: application/json", "Content-Type: application/json",
'User-Agent: https://thinkadmin.top', "Authorization: WECHATPAY2-SHA256-RSA2048 {$token}",
],
]);
if ($verify) {
$headers = [];
foreach (explode("\n", $header) as $line) {
@ -171,7 +175,8 @@ abstract class BasicWePay
throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
}
}
return json_decode($content, true);
return $isjson ? json_decode($content, true) : $content;
}
/**

View File

@ -22,7 +22,7 @@ use WePayV3\Contracts\BasicWePay;
use WePayV3\Contracts\DecryptAes;
/**
* 订单支付接口
* 直连商户 | 订单支付接口
* Class Order
* @package WePayV3
*/
@ -39,6 +39,7 @@ class Order extends BasicWePay
* @param array $data 支付参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
*/
public function create($type, $data)
{
@ -73,18 +74,32 @@ class Order extends BasicWePay
/**
* 支付订单查询
* @param string $orderNo 订单单号
* @param string $tradeNo 订单单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml
*/
public function query($orderNo)
public function query($tradeNo)
{
$pathinfo = "/v3/pay/transactions/out-trade-no/{$orderNo}";
$pathinfo = "/v3/pay/transactions/out-trade-no/{$tradeNo}";
return $this->doRequest('GET', "{$pathinfo}?mchid={$this->config['mch_id']}", '', true);
}
/**
* 支付通知
* 关闭支付订单
* @param string $tradeNo 订单单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function close($tradeNo)
{
$data = ['mchid' => $this->config['mch_id']];
$path = "/v3/pay/transactions/out-trade-no/{$tradeNo}/close";
return $this->doRequest('POST', $path, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 支付通知解析
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
*/
@ -107,4 +122,69 @@ class Order extends BasicWePay
}
return $data;
}
/**
* 创建退款订单
* @param array $data 退款参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
*/
public function createRefund($data)
{
$path = '/v3/refund/domestic/refunds';
return $this->doRequest('POST', $path, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 退款订单查询
* @param string $refundNo 退款单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml
*/
public function queryRefund($refundNo)
{
$path = "/v3/refund/domestic/refunds/{$refundNo}";
return $this->doRequest('GET', $path, '', true);
}
/**
* 申请交易账单
* @param array|string $params
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_6.shtml
*/
public function tradeBill($params)
{
$path = '/v3/bill/tradebill?' . is_array($params) ? http_build_query($params) : $params;
return $this->doRequest('GET', $path, '', true);
}
/**
* 申请资金账单
* @param array|string $params
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_7.shtml
*/
public function fundflowBill($params)
{
$path = '/v3/bill/fundflowbill?' . is_array($params) ? http_build_query($params) : $params;
return $this->doRequest('GET', $path, '', true);
}
/**
* 下载账单文件
* @param string $fileurl
* @return string 二进制 Excel 内容
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_1.shtml
*/
public function downloadBill($fileurl)
{
$path = strstr($fileurl, '/v3/');
return $this->doRequest('GET', $path, '', false, false);
}
}

View File

@ -22,7 +22,7 @@ use WeChat\Exceptions\InvalidResponseException;
use WePayV3\Contracts\BasicWePay;
/**
* 订单退款接口
* 电商接口 | 订单退款接口
* Class Refund
* @package WePayV3
*/