From 2bf5ac1a1a534dbbbf2b6c6b8469a0e77584155d Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Mon, 29 May 2023 23:31:31 +0800 Subject: [PATCH] yh --- app/Command/JinlingCommand.php | 136 +++++++++++++++++++++-- app/Controller/Payment/PayController.php | 26 ----- app/Helper/Efps/Api.php | 77 ++----------- app/Model/BankCard.php | 10 ++ config/routes.php | 6 +- payment.sql | 27 ++++- 6 files changed, 175 insertions(+), 107 deletions(-) create mode 100644 app/Model/BankCard.php diff --git a/app/Command/JinlingCommand.php b/app/Command/JinlingCommand.php index d845424..776c561 100644 --- a/app/Command/JinlingCommand.php +++ b/app/Command/JinlingCommand.php @@ -7,6 +7,9 @@ namespace App\Command; use App\Helper\Efps\Api; use App\Helper\Signer; use App\Helper\StringHelper; +use App\Request\BindCardRequest; +use App\Request\ProtocolPayConfirmRequest; +use App\Request\ProtocolPayPreRequest; use App\Request\RegisterRequest; use App\Service\AppService; use App\Service\MerchantService; @@ -42,8 +45,13 @@ class JinlingCommand extends HyperfCommand public function handle(): void { - - $ret = Api::certifiedPayment([ + // $this->bindCard(); + // $this->comfirmBindCard(); + // $this->prepay(); + // $this->confirmPay(); + $this->refund(); + return; + /*$ret = Api::certifiedPayment([ 'outTradeNo' => time() . rand(1000, 9999), 'userName' => 'abc', 'phoneNum' => '18760419185', @@ -52,7 +60,7 @@ class JinlingCommand extends HyperfCommand 'payAmount' => 100, ]); var_dump($ret); - return; + return;*/ /*$ret = Api::unifiedPayment(); var_dump($ret); return;*/ @@ -74,7 +82,7 @@ class JinlingCommand extends HyperfCommand /*$ret = Api::unifiedPayment(); var_dump($ret); return;*/ - $ret = Api::register([ + /*$ret = Api::register([ 'merId' => "T100", // 562238003185933 'backUrl' => 'http://www.baidu.com', 'certificateName' => '测试', @@ -88,14 +96,16 @@ class JinlingCommand extends HyperfCommand 'canDownType' => '01', ]); var_dump($ret); - return; + return;*/ $ret = Api::bindCard([ 'mchtOrderNo' => time() . rand(1000, 9999), - 'userName' => '廖金灵', - 'phoneNum' => '18760419185', - 'bankCardNo' => '6214835911385365', + 'memberId' => 'T01', + 'userName' => '饶丽秀', + 'phoneNum' => '13817896134', + // 'bankCardNo' => '622908113000409396', + 'bankCardNo' => '6212261402022689613', 'bankCardType' => 'debit', - 'certificatesNo' => '350824199001105476', + 'certificatesNo' => '350824199001045864', ]); var_dump($ret); return; @@ -159,4 +169,112 @@ class JinlingCommand extends HyperfCommand $params['sign'] = $sign; var_dump(json_encode($params)); } + + public function bindCard() + { + $params = [ + 'app_id' => '202304270000004', + 'timestamp' => time(), + 'nonce_str' => StringHelper::getRandomString(32), + 'data' => json_encode([ + 'mchtOrderNo' => time() . rand(1000, 9999), + 'memberId' => 'T01', + 'userName' => '饶丽秀', + 'phoneNum' => '13817896134', + // 'bankCardNo' => '622908113000409396', + 'bankCardNo' => '6212261402022689613', + 'bankCardType' => 'debit', + 'certificatesNo' => '350824199001045864', + ]), + ]; + $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); + $params['sign'] = $sign; + var_dump($params); + $request = new BindCardRequest($params); + $params = $request->getData(); + var_dump($params); + } + + public function comfirmBindCard() + { + $params = [ + 'app_id' => '202304270000004', + 'timestamp' => time(), + 'nonce_str' => StringHelper::getRandomString(32), + 'data' => json_encode([ + 'memberId' => 'T01', + 'smsNo' => 'QY202305292233394504122', + 'smsCode' => '485608', + ]), + ]; + $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); + $params['sign'] = $sign; + var_dump($params); + $request = new BindCardRequest($params); + $params = $request->getData(); + var_dump($params); + } + + public function prepay() + { + $params = [ + 'app_id' => '202304270000004', + 'timestamp' => time(), + 'nonce_str' => StringHelper::getRandomString(32), + 'data' => json_encode([ + 'memberId' => 'T01', + 'outTradeNo' => time() . rand(1000, 9999), + 'protocol' => 'p202305296288304915744', + 'payAmount' => 1, + ]), + ]; + $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); + $params['sign'] = $sign; + var_dump($params); + $request = new ProtocolPayPreRequest($params); + $params = $request->getData(); + var_dump($params); + } + + public function confirmPay() + { + $params = [ + 'app_id' => '202304270000004', + 'timestamp' => time(), + 'nonce_str' => StringHelper::getRandomString(32), + 'data' => json_encode([ + 'token' => '83f93a2b0a134d358dde920d9b7abca0', + 'protocol' => 'p202305296288304915744', + 'smsCode' => '466592', + ]), + ]; + $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); + $params['sign'] = $sign; + var_dump($params); + $request = new ProtocolPayConfirmRequest($params); + $params = $request->getData(); + var_dump($params); + } + + public function refund() + { + $params = [ + 'app_id' => '202304270000004', + 'timestamp' => time(), + 'nonce_str' => StringHelper::getRandomString(32), + 'data' => json_encode([ + 'outRefundNo' => time() . rand(1000, 9999), + 'remark' => '退款', + 'amount' => 1, + 'refundAmount' => 1, + 'outTradeNo' => '16853732799380', + ]), + ]; + $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); + $params['sign'] = $sign; + var_dump($params); + $request = new ProtocolPayConfirmRequest($params); + $params = $request->getData(); + var_dump($params); + } } diff --git a/app/Controller/Payment/PayController.php b/app/Controller/Payment/PayController.php index 8528e0c..c91c533 100644 --- a/app/Controller/Payment/PayController.php +++ b/app/Controller/Payment/PayController.php @@ -8,15 +8,12 @@ use App\Exception\BusinessException; use App\Helper\Efps\Api; use App\Model\Order; use App\Model\RefundOrder; -use App\Model\User; use App\Request\BindCardConfirmRequest; use App\Request\BindCardRequest; -use App\Request\JsapiPayRequest; use App\Request\ProtocolPayConfirmRequest; use App\Request\ProtocolPayPreRequest; use App\Request\RefundQueryRequest; use App\Request\RefundRequest; -use App\Request\RegisterRequest; use App\Request\UnBindCardRequest; use Hyperf\HttpServer\Contract\RequestInterface; use App\Service\PaymentService; @@ -30,29 +27,6 @@ class PayController extends AbstractController $this->paymentService = $paymentService; } - public function register(RequestInterface $request) - { - $req = new RegisterRequest($request->all()); - $app = $req->getApp(); - $data = $req->getData(); - $result = Api::register($data); - if (!$result->isSuccess()) { - throw new BusinessException($result->getMessage()); - } - if ($result->get('auditState') == 1) { - $user = new User(); - $user->app_id = $app->app_id; - $user->member_id = $result->get('memberId'); - $user->merId = $data['merId'] ?: ''; - $user->card_no = $data['lawyerCertNo'] ?: ''; - $user->card_valid_to = $data['certificateTo'] ?: ''; - $user->mobile = $data['contactPhone'] ?: ''; - $user->save(); - } - - return $this->success($result->getData()); - } - public function bindCard(RequestInterface $request) { $req = new BindCardRequest($request->all()); diff --git a/app/Helper/Efps/Api.php b/app/Helper/Efps/Api.php index edb288c..c91f337 100644 --- a/app/Helper/Efps/Api.php +++ b/app/Helper/Efps/Api.php @@ -138,39 +138,6 @@ class Api extends AbstractApi return self::request($uri, $params, $sign); } - public static function certifiedPayment($params) - { - $outTradeNo = $params['outTradeNo'] ?? StringHelper::generateOrderNo(); - $userName = $params['userName'] ?? ''; - $phoneNum = $params['phoneNum'] ?? ''; - $bankCardNo = $params['bankCardNo'] ?? ''; - $certificatesNo = $params['certificatesNo'] ?? ''; - $payAmount = $params['payAmount'] ?? 0; - $payCurrency = 'CNY'; - $orderInfo = []; - $orderInfo['Id'] = $outTradeNo; - $orderInfo['businessType'] = '130001'; - $orderInfo['goodsList'] = [['name' => 'pay', 'number' => 'one', 'amount' => $payAmount]]; - - $uri = '/api/txs/pay/CertifiedPayment'; - $params = [ - 'version' => '2.0', - 'customerCode' => self::getConfig('customerCode'), - 'outTradeNo' => $outTradeNo, - 'userName' => Signer::publicEncrypt($userName), - 'certificatesType' => '01', - 'certificatesNo' => Signer::publicEncrypt($certificatesNo), - 'phoneNum' => Signer::publicEncrypt($phoneNum), - 'bankCardNo' => Signer::publicEncrypt($bankCardNo), - 'payAmount' => $payAmount, - 'payCurrency' => $payCurrency, - 'orderInfo' => $orderInfo, - 'transactionStartTime' => date('YmdHis'), - 'nonceStr' => StringHelper::getRandomString(32), - ]; - $sign = Signer::sign(json_encode($params)); - return self::request($uri, $params, $sign); - } public static function unBindCard($params) { $protocol = $params['protocol'] ?? ''; @@ -197,23 +164,27 @@ class Api extends AbstractApi $orderInfo = []; $orderInfo['Id'] = $outTradeNo; $orderInfo['businessType'] = '130001'; - $orderInfo['goodsList'] = [['name' => 'pay', 'number' => 'one', 'amount' => $$payAmount]]; + $orderInfo['goodsList'] = [['name' => 'pay', 'number' => '1', 'amount' => $payAmount]]; $uri = '/api/txs/protocol/protocolPayPre'; $params = [ 'version' => '3.0', 'customerCode' => self::getConfig('customerCode'), 'outTradeNo' => $outTradeNo, - 'protocol' => $protocol, - // 'smsNo' => $smsNo, - // 'smsCode' => $smsCode, 'orderInfo' => $orderInfo, 'payAmount' => $payAmount, 'payCurrency' => 'CNY', 'isInstalments' => 0, + 'notifyUrl' => 'http://146.70.113.165:9501/notify/payment', 'transactionStartTime' => date('YmdHis'), 'nonceStr' => StringHelper::getRandomString(32), ]; + if ($protocol) { + $params['protocol'] = $protocol; + } else { + $params['smsCode'] = $smsCode; + $params['smsNo'] = $smsNo; + } $sign = Signer::sign(json_encode($params)); return self::request($uri, $params, $sign); } @@ -240,7 +211,6 @@ class Api extends AbstractApi { $uri = '/api/txs/pay/Refund/V2'; $outRefundNo = $params['outRefundNo'] ?? ''; - $notifyUrl = $params['notifyUrl'] ?? ''; $outTradeNo = $params['outTradeNo'] ?? ''; $refundAmount = $params['refundAmount'] ?? 0; $amount = $params['amount'] ?? 0; @@ -254,7 +224,7 @@ class Api extends AbstractApi 'refundAmount' => $refundAmount, 'amount' => $amount, 'remark' => $remark, - 'notifyUrl' => $notifyUrl, + 'notifyUrl' => 'http://146.70.113.165:9501/notify/refund', 'nonceStr' => StringHelper::getRandomString(32), ]; $sign = Signer::sign(json_encode($params)); @@ -275,33 +245,4 @@ class Api extends AbstractApi $sign = Signer::sign(json_encode($params)); return self::request($uri, $params, $sign); } - - public static function unifiedPayment() - { - $uri = '/api/txs/pay/UnifiedPayment'; - $orderNo = "123456".date('YmdHis'); - $client_ip = "127.0.0.1"; - - $orderInfo = []; - $orderInfo['Id'] = $orderNo; - $orderInfo['businessType'] = '130001'; - $orderInfo['goodsList'] = [['name'=>'pay', 'number'=>'one', 'amount'=>1]]; - - $params = [ - 'outTradeNo' => $orderNo, - 'customerCode' => self::getConfig('customerCode'), - 'clientIp' => $client_ip, - 'orderInfo' => $orderInfo, - 'payCurrency' => 'CNY', - 'payAmount' => 10, - 'payCurrency' => 'CNY', - 'notifyUrl' => 'http://www.baidu.com', - 'redirectUrl' => 'http://www.baidu.com', - 'transactionStartTime' =>date('YmdHis'), - 'nonceStr' => 'pay'.rand(100,999), - 'version' => '3.0' - ]; - $sign = Signer::sign(json_encode($params)); - return self::request($uri, $params, $sign); - } } \ No newline at end of file diff --git a/app/Model/BankCard.php b/app/Model/BankCard.php new file mode 100644 index 0000000..36dc129 --- /dev/null +++ b/app/Model/BankCard.php @@ -0,0 +1,10 @@ + [\App\Middleware\RequestLogMiddleware::class]]); -Router::addGroup('/payment',function () { - Router::addRoute(['GET', 'POST'], '/notify', [NotifyController::class, 'payment']); - Router::addRoute(['GET', 'POST'], '/notify', [NotifyController::class, 'refund']); +Router::addGroup('/notify',function () { + Router::addRoute(['GET', 'POST'], '/payment', [NotifyController::class, 'payment']); + Router::addRoute(['GET', 'POST'], '/refund', [NotifyController::class, 'refund']); }); diff --git a/payment.sql b/payment.sql index 3091bd4..929b33a 100644 --- a/payment.sql +++ b/payment.sql @@ -37,6 +37,31 @@ CREATE TABLE `users` ( PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC; +CREATE TABLE `bank_cards` ( + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', + `app_id` varchar(16) NOT NULL COMMENT '应用ID', + `member_id` varchar(32) NOT NULL COMMENT '用户编号', + `card_no` varchar(32) not null default '', + `real_name` varchar(20) not null default '', + `mobile` varchar(15) not null default '', + `bank_card_no` varchar(20) not null default '', + `bank_card_type` varchar(10) not null default '', + `sms_no` varchar(32) NOT NULL DEFAULT '', + `protocol` varchar(32) NOT NULL DEFAULT '', + `bind_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '支付时间', + `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态', + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + KEY `idx_mobile` (`mobile`) USING BTREE, + KEY `idx_bankcardno` (`bank_card_no`) USING BTREE, + KEY `idx_realname` (`real_name`) USING BTREE, + KEY `idx_cardno` (`card_no`) USING BTREE, + KEY `idx_smsno` (`sms_no`) USING BTREE, + KEY `idx_protocol` (`protocol`) USING BTREE, + KEY `idx_createdat` (`created_at`) USING BTREE, + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC COMMENT='银行卡'; + CREATE TABLE `orders` ( `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID', `app_id` varchar(16) NOT NULL COMMENT '应用ID', @@ -50,7 +75,7 @@ CREATE TABLE `orders` ( `notify_url` varchar(1024) NOT NULL DEFAULT '' COMMENT '通知地址', `pay_url` varchar(1024) NOT NULL DEFAULT '' COMMENT '支付地址', `token` varchar(32) NOT NULL DEFAULT '', - `protocol` varchar(16) NOT NULL DEFAULT '', + `protocol` varchar(32) NOT NULL DEFAULT '', `payed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '支付时间', `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '订单状态', `error_code` varchar(32) NOT NULL DEFAULT '' COMMENT '错误码',