multi-store/app/common/service/pay/WeChatPay.php

40 lines
1.0 KiB
PHP

<?php
namespace app\common\service\pay;
use support\exception\BusinessException;
/**
* 微信支付
* Class WeChatPay
* @package app\common\service\pay
*/
class WeChatPay extends PayTool
{
public function refund($amount, $order)
{
$totalFee = (int)bcmul($amount, 100);
try {
$wechat = new PayService(1);
$order = [
'out_trade_no' => $order['order_id'],
'out_refund_no' => 'BO' . time(),
'amount' => [
'refund' => $totalFee,
'total' => (int)bcmul($order['pay_price'], 100),
'currency' => 'CNY',
],
];
$res = $wechat->wechat->refund($order);
if ($res['status'] == 'PROCESSING') {
return true;
}
return false;
} catch (\Exception $e) {
\support\Log::info($e->extra['message'] ?? $e->getMessage());
throw new BusinessException($e->extra['message'] ?? $e->getMessage());
}
}
}