mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2026-07-05 21:01:08 +08:00
Compare commits
3 Commits
af7ea76eae
...
8f7758975c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f7758975c | ||
|
|
8e532f25c7 | ||
|
|
eca01d957b |
@ -16,13 +16,10 @@
|
||||
|
||||
namespace WePayV3;
|
||||
|
||||
use WeChat\Contracts\Tools;
|
||||
use WeChat\Exceptions\InvalidDecryptException;
|
||||
use WeChat\Exceptions\InvalidResponseException;
|
||||
use WePayV3\Contracts\BasicWePay;
|
||||
|
||||
/**
|
||||
* 电商接口 | 订单退款接口
|
||||
* 订单退款接口
|
||||
* 注意:直连商户退款接口集成在 Order 中
|
||||
* @deprecated
|
||||
* @class Refund
|
||||
@ -38,7 +35,8 @@ class Refund extends BasicWePay
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
return $this->doRequest('POST', '/v3/ecommerce/refunds/apply', json_encode($data, JSON_UNESCAPED_UNICODE), true);
|
||||
return Order::instance($this->config)->createRefund($data);
|
||||
// return $this->doRequest('POST', '/v3/ecommerce/refunds/apply', json_encode($data, JSON_UNESCAPED_UNICODE), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,8 +47,9 @@ class Refund extends BasicWePay
|
||||
*/
|
||||
public function query($refundNo)
|
||||
{
|
||||
$pathinfo = "/v3/ecommerce/refunds/out-refund-no/{$refundNo}";
|
||||
return $this->doRequest('GET', "{$pathinfo}?sub_mchid={$this->config['mch_id']}", '', true);
|
||||
return Order::instance($this->config)->queryRefund($refundNo);
|
||||
// $pathinfo = "/v3/ecommerce/refunds/out-refund-no/{$refundNo}";
|
||||
// return $this->doRequest('GET', "{$pathinfo}?sub_mchid={$this->config['mch_id']}", '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,18 +62,19 @@ class Refund extends BasicWePay
|
||||
*/
|
||||
public function notify($xml = '')
|
||||
{
|
||||
$data = Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
|
||||
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS') {
|
||||
throw new InvalidResponseException('获取退款通知XML失败!');
|
||||
}
|
||||
try {
|
||||
$key = md5($this->config['mch_v3_key']);
|
||||
$decrypt = base64_decode($data['req_info']);
|
||||
$response = openssl_decrypt($decrypt, 'aes-256-ecb', $key, OPENSSL_RAW_DATA);
|
||||
$data['result'] = Tools::xml2arr($response);
|
||||
return $data;
|
||||
} catch (\Exception $exception) {
|
||||
throw new InvalidDecryptException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
return Order::instance($this->config)->notifyRefund($xml);
|
||||
// $data = Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
|
||||
// if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS') {
|
||||
// throw new InvalidResponseException('获取退款通知XML失败!');
|
||||
// }
|
||||
// try {
|
||||
// $key = md5($this->config['mch_v3_key']);
|
||||
// $decrypt = base64_decode($data['req_info']);
|
||||
// $response = openssl_decrypt($decrypt, 'aes-256-ecb', $key, OPENSSL_RAW_DATA);
|
||||
// $data['result'] = Tools::xml2arr($response);
|
||||
// return $data;
|
||||
// } catch (\Exception $exception) {
|
||||
// throw new InvalidDecryptException($exception->getMessage(), $exception->getCode());
|
||||
// }
|
||||
}
|
||||
}
|
||||
@ -30,7 +30,7 @@ try {
|
||||
// 4. 组装参数,可以参考官方商户文档
|
||||
$options = [
|
||||
'transaction_id' => '1008450740201411110005820873',
|
||||
'out_refund_no' => '商户退款单号',
|
||||
'out_refund_no' => '3241251235123',
|
||||
'total_fee' => '1',
|
||||
'refund_fee' => '1',
|
||||
];
|
||||
|
||||
@ -25,11 +25,12 @@ try {
|
||||
$payment = \WePayV3\Order::instance($config);
|
||||
|
||||
// 4. 组装支付参数
|
||||
$order = (string)time();
|
||||
$result = $payment->create('app', [
|
||||
'appid' => $config['appid'],
|
||||
'mchid' => $config['mch_id'],
|
||||
'description' => '商品描述',
|
||||
'out_trade_no' => (string)time(),
|
||||
'out_trade_no' => $order,
|
||||
'notify_url' => 'https://thinkadmin.top',
|
||||
'amount' => ['total' => 2, 'currency' => 'CNY'],
|
||||
]);
|
||||
@ -38,6 +39,25 @@ try {
|
||||
echo "\n--- 创建支付参数 ---\n";
|
||||
var_export($result);
|
||||
|
||||
// 创建退款
|
||||
$out_refund_no = strval(time());
|
||||
$result = $payment->createRefund([
|
||||
'out_trade_no' => $order,
|
||||
'out_refund_no' => $out_refund_no,
|
||||
'amount' => [
|
||||
'refund' => 2,
|
||||
'total' => 2,
|
||||
'currency' => 'CNY'
|
||||
]
|
||||
]);
|
||||
echo "\n--- 创建退款订单 ---\n";
|
||||
var_export($result);
|
||||
|
||||
$result = $payment->queryRefund($out_refund_no);
|
||||
|
||||
echo "\n--- 查询退款订单 ---\n";
|
||||
var_export($result);
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
// 出错啦,处理下吧
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
|
||||
@ -64,6 +64,25 @@ try {
|
||||
// 'trade_state_desc' => '订单未支付',
|
||||
// );
|
||||
|
||||
// 创建退款
|
||||
$out_refund_no = strval(time());
|
||||
$result = $payment->createRefund([
|
||||
'out_trade_no' => $order,
|
||||
'out_refund_no' => $out_refund_no,
|
||||
'amount' => [
|
||||
'refund' => 2,
|
||||
'total' => 2,
|
||||
'currency' => 'CNY'
|
||||
]
|
||||
]);
|
||||
echo "\n--- 创建退款订单2 ---\n";
|
||||
var_export($result);
|
||||
|
||||
$result = $payment->queryRefund($out_refund_no);
|
||||
|
||||
echo "\n--- 查询退款订单2 ---\n";
|
||||
var_export($result);
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
// 出错啦,处理下吧
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
|
||||
@ -57,6 +57,25 @@ try {
|
||||
// 'trade_state_desc' => '订单未支付',
|
||||
// );
|
||||
|
||||
// 创建退款
|
||||
$out_refund_no = strval(time());
|
||||
$result = $payment->createRefund([
|
||||
'out_trade_no' => $order,
|
||||
'out_refund_no' => $out_refund_no,
|
||||
'amount' => [
|
||||
'refund' => 2,
|
||||
'total' => 2,
|
||||
'currency' => 'CNY'
|
||||
]
|
||||
]);
|
||||
echo "\n--- 创建退款订单2 ---\n";
|
||||
var_export($result);
|
||||
|
||||
$result = $payment->queryRefund($out_refund_no);
|
||||
|
||||
echo "\n--- 查询退款订单2 ---\n";
|
||||
var_export($result);
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
// 出错啦,处理下吧
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user