efps-version
elf 1 year ago
parent 2bf5ac1a1a
commit 4c9082f698

@ -8,8 +8,10 @@ use App\Helper\Efps\Api;
use App\Helper\Signer; use App\Helper\Signer;
use App\Helper\StringHelper; use App\Helper\StringHelper;
use App\Request\BindCardRequest; use App\Request\BindCardRequest;
use App\Request\PaymentQueryRequest;
use App\Request\ProtocolPayConfirmRequest; use App\Request\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest; use App\Request\ProtocolPayPreRequest;
use App\Request\RefundQueryRequest;
use App\Request\RegisterRequest; use App\Request\RegisterRequest;
use App\Service\AppService; use App\Service\AppService;
use App\Service\MerchantService; use App\Service\MerchantService;
@ -49,7 +51,9 @@ class JinlingCommand extends HyperfCommand
// $this->comfirmBindCard(); // $this->comfirmBindCard();
// $this->prepay(); // $this->prepay();
// $this->confirmPay(); // $this->confirmPay();
$this->refund(); // $this->refund();
// $this->refundQuery();
$this->paymentQuery();
return; return;
/*$ret = Api::certifiedPayment([ /*$ret = Api::certifiedPayment([
'outTradeNo' => time() . rand(1000, 9999), 'outTradeNo' => time() . rand(1000, 9999),
@ -277,4 +281,40 @@ class JinlingCommand extends HyperfCommand
$params = $request->getData(); $params = $request->getData();
var_dump($params); var_dump($params);
} }
public function refundQuery()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outRefundNo' => '16853743952501',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new RefundQueryRequest($params);
$params = $request->getData();
var_dump($params);
}
public function paymentQuery()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outTradeNo' => '16853732799380',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new PaymentQueryRequest($params);
$params = $request->getData();
var_dump($params);
}
} }

@ -4,19 +4,24 @@ declare(strict_types=1);
namespace App\Controller\Payment; namespace App\Controller\Payment;
use App\Helper\Efps\Result;
use App\Helper\Efps\Signer; use App\Helper\Efps\Signer;
use App\Helper\Log; use App\Helper\Log;
use App\Helper\Platform\Notification; use App\Helper\Platform\Notification;
use App\Model\App; use App\Model\App;
use App\Model\Order; use App\Model\Order;
use App\Model\RefundOrder; use App\Model\RefundOrder;
use App\Service\PaymentService;
use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\HttpServer\Contract\RequestInterface;
class NotifyController extends AbstractController class NotifyController extends AbstractController
{ {
public function __construct() private PaymentService $paymentService;
public function __construct(PaymentService $paymentService)
{ {
$this->paymentService = $paymentService;
} }
public function payment(RequestInterface $request) public function payment(RequestInterface $request)
@ -56,20 +61,10 @@ class NotifyController extends AbstractController
]; ];
} }
if ($params['payState'] === '00') { $params['returnCode'] = '0000';
$order->status = Order::STATUS_PAYED; $params['returnMsg'] = '成功';
$order->fee = $params['procedureFee'] ?: 0; $result = new Result($params);
$order->pay_order_no = $params['transactionNo'] ?: ''; $this->paymentService->handlePayResult($result, $order);
$order->channel_order_no = $params['channelOrder'] ?: '';
$order->payed_at = date('Y-m-d H:i:s');
$order->save();
} elseif ($params['payState'] === '01') {
$order->status = Order::STATUS_FAILED;
$order->error_code = '01';
$order->error_msg = '处理失败';
$order->payed_at = date('Y-m-d H:i:s');
$order->save();
}
$result = $this->notify($order->notify_url, $app, [ $result = $this->notify($order->notify_url, $app, [
'outTradeNo' => $params['outTradeNo'] ?: '', 'outTradeNo' => $params['outTradeNo'] ?: '',
@ -121,23 +116,18 @@ class NotifyController extends AbstractController
'returnMsg' => '处理成功' 'returnMsg' => '处理成功'
]; ];
} }
if ($params['payState'] === '00') {
$order->status = RefundOrder::STATUS_REFUND_SUCCESS; $params['returnCode'] = '0000';
$order->fee = $params['procedureFee'] ?: 0; $params['returnMsg'] = '成功';
$order->refunded_at = date('Y-m-d H:i:s'); $refundState = $params['refundState'] ?? null;
$order->save(); $refundState = is_null($refundState) ? ($params['payState'] ?? null) : $refundState;
} elseif ($params['payState'] === '01') { $result = new Result($params);
$order->status = RefundOrder::STATUS_REFUND_FAILED; $this->paymentService->handleRefundResult($result, $order);
$order->error_code = '01';
$order->error_msg = '处理失败';
$order->refunded_at = date('Y-m-d H:i:s');
$order->save();
}
$result = $this->notify($order->notify_url, $app, [ $result = $this->notify($order->notify_url, $app, [
'outRefundNo' => $params['outRefundNo'] ?: '', 'outRefundNo' => $params['outRefundNo'] ?: '',
'transactionNo' => $params['transactionNo'] ?: '', 'transactionNo' => $params['transactionNo'] ?: '',
'payState' => $params['payState'], 'payState' => $refundState,
'amount' => $params['amount'] ?: 0, 'amount' => $params['amount'] ?: 0,
'refundAmount' => $params['refundAmount'] ?: 0, 'refundAmount' => $params['refundAmount'] ?: 0,
]); ]);

@ -10,6 +10,7 @@ use App\Model\Order;
use App\Model\RefundOrder; use App\Model\RefundOrder;
use App\Request\BindCardConfirmRequest; use App\Request\BindCardConfirmRequest;
use App\Request\BindCardRequest; use App\Request\BindCardRequest;
use App\Request\PaymentQueryRequest;
use App\Request\ProtocolPayConfirmRequest; use App\Request\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest; use App\Request\ProtocolPayPreRequest;
use App\Request\RefundQueryRequest; use App\Request\RefundQueryRequest;
@ -141,6 +142,13 @@ class PayController extends AbstractController
throw new BusinessException($result->getMessage()); throw new BusinessException($result->getMessage());
} }
$order = RefundOrder::where('out_refund_order_no', $result->get('outRefundNo'))
->where('status', RefundOrder::STATUS_APPLY_SUCCESS)
->first();
if ($order) {
$this->paymentService->handleRefundResult($result, $order);
}
return $this->success( return $this->success(
$result->getData([ $result->getData([
'outRefundNo', 'outRefundNo',
@ -151,4 +159,30 @@ class PayController extends AbstractController
]) ])
); );
} }
public function paymentQuery(RequestInterface $request) {
$req = new PaymentQueryRequest($request->all());
$data = $req->getData();
$result = Api::paymentQuery($data);
if (!$result->isSuccess()) {
throw new BusinessException($result->getMessage());
}
$order = Order::where('out_order_no', $result->get('outTradeNo'))
->where('status', Order::STATUS_WAIT_PAY)
->first();
if ($order) {
$this->paymentService->handlePayResult($result, $order);
}
return $this->success(
$result->getData([
'outTradeNo',
'transactionNo',
'payState',
'procedureFee',
'amount'
])
);
}
} }

@ -217,7 +217,6 @@ class Api extends AbstractApi
$remark = $params['remark'] ?? ''; $remark = $params['remark'] ?? '';
$params = [ $params = [
// 'version' => '3.0',
'customerCode' => self::getConfig('customerCode'), 'customerCode' => self::getConfig('customerCode'),
'outRefundNo' => $outRefundNo, 'outRefundNo' => $outRefundNo,
'outTradeNo' => $outTradeNo, 'outTradeNo' => $outTradeNo,
@ -237,7 +236,6 @@ class Api extends AbstractApi
$outRefundNo = $params['outRefundNo'] ?? ''; $outRefundNo = $params['outRefundNo'] ?? '';
$params = [ $params = [
// 'version' => '3.0',
'customerCode' => self::getConfig('customerCode'), 'customerCode' => self::getConfig('customerCode'),
'outRefundNo' => $outRefundNo, 'outRefundNo' => $outRefundNo,
'nonceStr' => StringHelper::getRandomString(32), 'nonceStr' => StringHelper::getRandomString(32),
@ -245,4 +243,18 @@ class Api extends AbstractApi
$sign = Signer::sign(json_encode($params)); $sign = Signer::sign(json_encode($params));
return self::request($uri, $params, $sign); return self::request($uri, $params, $sign);
} }
public static function paymentQuery($params)
{
$uri = '/api/txs/pay/PaymentQuery';
$outTradeNo = $params['outTradeNo'] ?? '';
$params = [
'customerCode' => self::getConfig('customerCode'),
'outTradeNo' => $outTradeNo,
'nonceStr' => StringHelper::getRandomString(32),
];
$sign = Signer::sign(json_encode($params));
return self::request($uri, $params, $sign);
}
} }

@ -0,0 +1,13 @@
<?php
namespace App\Request;
class PaymentQueryRequest extends ApiRequest
{
public function rules(): array
{
return [
];
}
}

@ -9,6 +9,7 @@ use App\Helper\Redis;
use App\Helper\RedisKey; use App\Helper\RedisKey;
use App\Model\App; use App\Model\App;
use App\Model\Order; use App\Model\Order;
use App\Model\RefundOrder;
class PaymentService extends AbstractService class PaymentService extends AbstractService
{ {
@ -39,6 +40,21 @@ class PaymentService extends AbstractService
} }
} }
public function handleRefundResult(Result $result, RefundOrder $order) {
if ($result->get('refundState') === '00') {
$order->status = RefundOrder::STATUS_REFUND_SUCCESS;
$order->fee = $result->get('procedureFee', 0);
$order->refunded_at = date('Y-m-d H:i:s');
$order->save();
} elseif ($result->get('refundState') === '01') {
$order->status = RefundOrder::STATUS_REFUND_FAILED;
$order->error_code = '01';
$order->error_msg = '处理失败';
$order->refunded_at = date('Y-m-d H:i:s');
$order->save();
}
}
private function generateOrderNo() { private function generateOrderNo() {
$now = time(); $now = time();
$key = RedisKey::getGenerateOrderNoKey($now); $key = RedisKey::getGenerateOrderNoKey($now);

@ -19,6 +19,7 @@ Router::addGroup('/payment',function () {
Router::post('/protocol-pay-pre-request', [PayController::class, 'protocolPayPreRequest']); Router::post('/protocol-pay-pre-request', [PayController::class, 'protocolPayPreRequest']);
Router::post('/protocol-pay-confirm', [PayController::class, 'protocolPayConfirm']); Router::post('/protocol-pay-confirm', [PayController::class, 'protocolPayConfirm']);
Router::post('/refund-query', [PayController::class, 'refundQuery']); Router::post('/refund-query', [PayController::class, 'refundQuery']);
Router::post('/payment-query', [PayController::class, 'paymentQuery']);
}, ['middleware' => [\App\Middleware\RequestLogMiddleware::class]]); }, ['middleware' => [\App\Middleware\RequestLogMiddleware::class]]);
Router::addGroup('/notify',function () { Router::addGroup('/notify',function () {

@ -105,7 +105,7 @@ CREATE TABLE `refund_orders` (
`error_msg` varchar(255) NOT NULL DEFAULT '' COMMENT '错误信息', `error_msg` varchar(255) NOT NULL DEFAULT '' COMMENT '错误信息',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
KEY `idx_refundorderno` (`refund_order_no`) USING BTREE, KEY `idx_outrefundorderno` (`out_refund_order_no`) USING BTREE,
KEY `idx_createdat` (`created_at`) USING BTREE, KEY `idx_createdat` (`created_at`) USING BTREE,
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC COMMENT='退款订单表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC COMMENT='退款订单表';
Loading…
Cancel
Save