elf 1 year ago
parent 4022901c65
commit 63cd600172

@ -45,7 +45,7 @@ class MineCommand extends HyperfCommand
public function handle(): void public function handle(): void
{ {
$this->getBalance(); $this->unionPay();
return; return;
// $this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_register', $this->getApp(), ['userId' => '30684']); // $this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_register', $this->getApp(), ['userId' => '30684']);
$this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_bind_card', $this->getApp(), ['userId' => '23121', 'bindCardFlag' => true]); $this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_bind_card', $this->getApp(), ['userId' => '23121', 'bindCardFlag' => true]);
@ -89,7 +89,7 @@ class MineCommand extends HyperfCommand
return $requestService->createRequestLog('/', $params); return $requestService->createRequestLog('/', $params);
} }
protected function getApp($appId = '202308070000001') { protected function getApp($appId = '202308040000002') {
return App::where('app_id', $appId)->first(); return App::where('app_id', $appId)->first();
} }
@ -329,4 +329,34 @@ class MineCommand extends HyperfCommand
$result = $paymentService->transferPay($data, $this->getApp(), $this->getToken()); $result = $paymentService->transferPay($data, $this->getApp(), $this->getToken());
var_dump($result); var_dump($result);
} }
protected function unionPay()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
'userId' => 'ELF1990',
'goodsName' => '测试商品',
'agreementNo' => '312023081200002052866',
'notifyUrl' => 'http://www.baidu.com',
'returnUrl' => 'http://www.baidu.com',
'amount' => 100,
'outOrderNo' => time() . rand(1000, 9999),
'validDate' => '2023-08-15',
'payMethod' => 'unionPay',
'payType' => 'ALIPAY_NATIVE',
'splitInfoList' => [
[
'splitUserId' => 'RLX1990',
'sellerFlag' => 1,
'splitAmount' => 100,
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
];
$result = $paymentService->payment($data, $this->getApp(), $this->getToken());
var_dump($result);
}
} }

@ -131,6 +131,47 @@ class NotifyController extends AbstractController
$baofu->notifySuccess(); $baofu->notifySuccess();
} }
public function confirmAssurePortfolioPay(RequestInterface $request)
{
[$token, $params] = $this->getTokenAndParams($request);
$baofu = new Baofu();
if (!$baofu->notifyVerify($params, 'confirm-assure-portfolio-pay')) {
Log::info('confirmAssurePortfolioPayNotifyVerifyFail: ' . $params);
return $baofu->notifySuccess();
}
$requestLog = $this->requestService->getRequestLogByToken($token);
$info = [
'member_id' => $params['loginId'],
'order_no' => $params['tradeId'],
'third_order_no' => $params['orderId'],
'status' => $params['orderStatus'],
'amount' => $params['orderMoney'],
'finished_at' => $params['finishTime'],
];
$order = $this->paymentService->updateOrder($info, 'PROCESS');
if (empty($order)) {
return $baofu->notifySuccess();
}
$result = $this->notify(
$requestLog->getDataValue('notifyUrl'),
$requestLog->app,
[
'amount' => $order->amount,
'status' => $order->status,
'userId' => $order->user_id,
'orderNo' => $order->order_no,
'outOrderNo' => $order->out_order_no,
'finishTime' => $order->finished_at,
]
);
$baofu->notifySuccess();
}
public function refund(RequestInterface $request) public function refund(RequestInterface $request)
{ {
[$token, $params] = $this->getTokenAndParams($request); [$token, $params] = $this->getTokenAndParams($request);

@ -181,7 +181,7 @@ class Baofu
return $this->api('cloud-b2c-assure-recharge', $data); return $this->api('cloud-b2c-assure-recharge', $data);
} }
public function payment($params, $type, $token) public function payment($params, $token)
{ {
$dataContent = [ $dataContent = [
'goodsName' => $params['goodsName'], 'goodsName' => $params['goodsName'],
@ -255,7 +255,7 @@ class Baofu
return $this->api('confirm-assure-pay', $data); return $this->api('confirm-assure-pay', $data);
} }
public function confirmAssurePortfolioPay($params) public function confirmAssurePortfolioPay($params, $token)
{ {
$dataContent = [ $dataContent = [
'amount' => $params['amount'], 'amount' => $params['amount'],
@ -267,7 +267,7 @@ class Baofu
$data = []; $data = [];
$data['loginNo'] = $params['loginNo']; $data['loginNo'] = $params['loginNo'];
$data['dataContent'] = json_encode($dataContent); $data['dataContent'] = json_encode($dataContent);
$data['notifyUrl'] = $params['notifyUrl']; $data['notifyUrl'] = NotifyList::getNotifyUrl('confirm-assure-portfolio-pay', $token);
return $this->api('confirm-assure-portfoli-pay', $data); return $this->api('confirm-assure-portfoli-pay', $data);
} }

@ -48,6 +48,10 @@ class NotifyList
'description' => '自助交易确认分账', 'description' => '自助交易确认分账',
'signParams' => 'orgNo|merchantNo|terminalNo|tradeId|subOutOrderNo|orderStatus|loginId|finishTime|confirmType', 'signParams' => 'orgNo|merchantNo|terminalNo|tradeId|subOutOrderNo|orderStatus|loginId|finishTime|confirmType',
], ],
'confirm-assure-portfolio-pay' => [
'description' => '确认分账',
'signParams' => 'orgNo|merchantNo|loginNo|terminalNo|requestDate|dataContent',
],
'refund' => [ 'refund' => [
'description' => '退款', 'description' => '退款',
'signParams' => 'orgNo|merchantNo|terminalNo|refundOrderId|refundTradeId|refundMoney|refundStatus|refundSuccTime|refundType|errorMsg', 'signParams' => 'orgNo|merchantNo|terminalNo|refundOrderId|refundTradeId|refundMoney|refundStatus|refundSuccTime|refundType|errorMsg',

@ -37,11 +37,18 @@ class PaymentService extends AbstractService
} }
$data['payType'] = $data['payType'] ?? 'CARD'; $data['payType'] = $data['payType'] ?? 'CARD';
[$order, $orderSplitInfos] = $this->createOrder($app, $data, $user, 'paymentSplit'); $payMethod = $data['payMethod'] ?? 'paymentSplit';
[$order, $orderSplitInfos] = $this->createOrder($app, $data, $user, $payMethod);
$splitInfoList = $this->buildSplitInfoList($orderSplitInfos); $splitInfoList = $this->buildSplitInfoList($orderSplitInfos);
return $this->paymentSplit($order, $user, $splitInfoList, $token); if ($payMethod == 'paymentSplit') {
return $this->paymentSplit($order, $user, $splitInfoList, $token);
} elseif($payMethod == 'unionPay') {
return $this->unionPay($order, $user, $splitInfoList, $token);
} else {
throw new BusinessException('payMethod不支持');
}
} }
public function transferPay(array $data, App $app, string $token) public function transferPay(array $data, App $app, string $token)
@ -254,17 +261,17 @@ class PaymentService extends AbstractService
return [$order, $orderSplitInfos]; return [$order, $orderSplitInfos];
} }
public function updateOrder($params) { public function updateOrder($params, $status = 'APPLY_SUCCESS') {
$order = Order::where('order_no', $params['order_no'])->where('status', 'APPLY_SUCCESS')->first(); $order = Order::where('order_no', $params['order_no'])->where('status', $status)->first();
if (empty($order)) { if (empty($order)) {
return null; return null;
} }
$order->third_order_no = $params['third_order_no']; $order->third_order_no = $params['third_order_no'];
$order->status = $params['status']; $order->status = $params['status'];
$order->finished_at = date('Y-m-d H:i:s', strtotime($params['finished_at'])); $order->finished_at = date('Y-m-d H:i:s', strtotime($params['finished_at']));
$order->error_message = $params['error_message']; $order->error_message = $params['error_message'] ?? '';
$order->transaction_id = $params['transaction_id']; $order->transaction_id = $params['transaction_id'] ?? '';
$order->out_transaction_id = $params['out_transaction_id']; $order->out_transaction_id = $params['out_transaction_id'] ?? '';
$order->save(); $order->save();
return $order; return $order;
} }
@ -452,7 +459,6 @@ class PaymentService extends AbstractService
'assureConfirmSplitInfoList' => $confirmSplitInfoList, 'assureConfirmSplitInfoList' => $confirmSplitInfoList,
'outOrderNo' => StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_CONFIRM_PAY), 'outOrderNo' => StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_CONFIRM_PAY),
'amount' => $data['amount'], 'amount' => $data['amount'],
'notifyUrl' => $data['notifyUrl'],
], $token); ], $token);
$order->status = 'CONFIRM_SUCCESS'; $order->status = 'CONFIRM_SUCCESS';
$order->save(); $order->save();

@ -33,6 +33,7 @@ Router::addGroup('/notify',function () {
Router::addRoute(['GET', 'POST'], '/payment/{token}', [NotifyController::class, 'payment']); Router::addRoute(['GET', 'POST'], '/payment/{token}', [NotifyController::class, 'payment']);
Router::addRoute(['GET', 'POST'], '/refund/{token}', [NotifyController::class, 'refund']); Router::addRoute(['GET', 'POST'], '/refund/{token}', [NotifyController::class, 'refund']);
Router::addRoute(['POST'], '/test-notify', [NotifyController::class, 'testNotify']); Router::addRoute(['POST'], '/test-notify', [NotifyController::class, 'testNotify']);
Router::addRoute(['GET', 'POST'], '/confirm-assure-portfolio-pay', [NotifyController::class, 'confirmAssurePortfolioPay']);
}); });
Router::addRoute(['GET', 'POST'], '/return/{token}', [ReturnController::class, 'go']); Router::addRoute(['GET', 'POST'], '/return/{token}', [ReturnController::class, 'go']);

Loading…
Cancel
Save