efps-version
elf 1 year ago
parent 06a838fbf1
commit 2bf5ac1a1a

@ -7,6 +7,9 @@ namespace App\Command;
use App\Helper\Efps\Api; 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\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest;
use App\Request\RegisterRequest; use App\Request\RegisterRequest;
use App\Service\AppService; use App\Service\AppService;
use App\Service\MerchantService; use App\Service\MerchantService;
@ -42,8 +45,13 @@ class JinlingCommand extends HyperfCommand
public function handle(): void public function handle(): void
{ {
// $this->bindCard();
$ret = Api::certifiedPayment([ // $this->comfirmBindCard();
// $this->prepay();
// $this->confirmPay();
$this->refund();
return;
/*$ret = Api::certifiedPayment([
'outTradeNo' => time() . rand(1000, 9999), 'outTradeNo' => time() . rand(1000, 9999),
'userName' => 'abc', 'userName' => 'abc',
'phoneNum' => '18760419185', 'phoneNum' => '18760419185',
@ -52,7 +60,7 @@ class JinlingCommand extends HyperfCommand
'payAmount' => 100, 'payAmount' => 100,
]); ]);
var_dump($ret); var_dump($ret);
return; return;*/
/*$ret = Api::unifiedPayment(); /*$ret = Api::unifiedPayment();
var_dump($ret); var_dump($ret);
return;*/ return;*/
@ -74,7 +82,7 @@ class JinlingCommand extends HyperfCommand
/*$ret = Api::unifiedPayment(); /*$ret = Api::unifiedPayment();
var_dump($ret); var_dump($ret);
return;*/ return;*/
$ret = Api::register([ /*$ret = Api::register([
'merId' => "T100", // 562238003185933 'merId' => "T100", // 562238003185933
'backUrl' => 'http://www.baidu.com', 'backUrl' => 'http://www.baidu.com',
'certificateName' => '测试', 'certificateName' => '测试',
@ -88,14 +96,16 @@ class JinlingCommand extends HyperfCommand
'canDownType' => '01', 'canDownType' => '01',
]); ]);
var_dump($ret); var_dump($ret);
return; return;*/
$ret = Api::bindCard([ $ret = Api::bindCard([
'mchtOrderNo' => time() . rand(1000, 9999), 'mchtOrderNo' => time() . rand(1000, 9999),
'userName' => '廖金灵', 'memberId' => 'T01',
'phoneNum' => '18760419185', 'userName' => '饶丽秀',
'bankCardNo' => '6214835911385365', 'phoneNum' => '13817896134',
// 'bankCardNo' => '622908113000409396',
'bankCardNo' => '6212261402022689613',
'bankCardType' => 'debit', 'bankCardType' => 'debit',
'certificatesNo' => '350824199001105476', 'certificatesNo' => '350824199001045864',
]); ]);
var_dump($ret); var_dump($ret);
return; return;
@ -159,4 +169,112 @@ class JinlingCommand extends HyperfCommand
$params['sign'] = $sign; $params['sign'] = $sign;
var_dump(json_encode($params)); 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);
}
} }

@ -8,15 +8,12 @@ use App\Exception\BusinessException;
use App\Helper\Efps\Api; use App\Helper\Efps\Api;
use App\Model\Order; use App\Model\Order;
use App\Model\RefundOrder; use App\Model\RefundOrder;
use App\Model\User;
use App\Request\BindCardConfirmRequest; use App\Request\BindCardConfirmRequest;
use App\Request\BindCardRequest; use App\Request\BindCardRequest;
use App\Request\JsapiPayRequest;
use App\Request\ProtocolPayConfirmRequest; use App\Request\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest; use App\Request\ProtocolPayPreRequest;
use App\Request\RefundQueryRequest; use App\Request\RefundQueryRequest;
use App\Request\RefundRequest; use App\Request\RefundRequest;
use App\Request\RegisterRequest;
use App\Request\UnBindCardRequest; use App\Request\UnBindCardRequest;
use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\HttpServer\Contract\RequestInterface;
use App\Service\PaymentService; use App\Service\PaymentService;
@ -30,29 +27,6 @@ class PayController extends AbstractController
$this->paymentService = $paymentService; $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) public function bindCard(RequestInterface $request)
{ {
$req = new BindCardRequest($request->all()); $req = new BindCardRequest($request->all());

@ -138,39 +138,6 @@ class Api extends AbstractApi
return self::request($uri, $params, $sign); 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) public static function unBindCard($params)
{ {
$protocol = $params['protocol'] ?? ''; $protocol = $params['protocol'] ?? '';
@ -197,23 +164,27 @@ class Api extends AbstractApi
$orderInfo = []; $orderInfo = [];
$orderInfo['Id'] = $outTradeNo; $orderInfo['Id'] = $outTradeNo;
$orderInfo['businessType'] = '130001'; $orderInfo['businessType'] = '130001';
$orderInfo['goodsList'] = [['name' => 'pay', 'number' => 'one', 'amount' => $$payAmount]]; $orderInfo['goodsList'] = [['name' => 'pay', 'number' => '1', 'amount' => $payAmount]];
$uri = '/api/txs/protocol/protocolPayPre'; $uri = '/api/txs/protocol/protocolPayPre';
$params = [ $params = [
'version' => '3.0', 'version' => '3.0',
'customerCode' => self::getConfig('customerCode'), 'customerCode' => self::getConfig('customerCode'),
'outTradeNo' => $outTradeNo, 'outTradeNo' => $outTradeNo,
'protocol' => $protocol,
// 'smsNo' => $smsNo,
// 'smsCode' => $smsCode,
'orderInfo' => $orderInfo, 'orderInfo' => $orderInfo,
'payAmount' => $payAmount, 'payAmount' => $payAmount,
'payCurrency' => 'CNY', 'payCurrency' => 'CNY',
'isInstalments' => 0, 'isInstalments' => 0,
'notifyUrl' => 'http://146.70.113.165:9501/notify/payment',
'transactionStartTime' => date('YmdHis'), 'transactionStartTime' => date('YmdHis'),
'nonceStr' => StringHelper::getRandomString(32), 'nonceStr' => StringHelper::getRandomString(32),
]; ];
if ($protocol) {
$params['protocol'] = $protocol;
} else {
$params['smsCode'] = $smsCode;
$params['smsNo'] = $smsNo;
}
$sign = Signer::sign(json_encode($params)); $sign = Signer::sign(json_encode($params));
return self::request($uri, $params, $sign); return self::request($uri, $params, $sign);
} }
@ -240,7 +211,6 @@ class Api extends AbstractApi
{ {
$uri = '/api/txs/pay/Refund/V2'; $uri = '/api/txs/pay/Refund/V2';
$outRefundNo = $params['outRefundNo'] ?? ''; $outRefundNo = $params['outRefundNo'] ?? '';
$notifyUrl = $params['notifyUrl'] ?? '';
$outTradeNo = $params['outTradeNo'] ?? ''; $outTradeNo = $params['outTradeNo'] ?? '';
$refundAmount = $params['refundAmount'] ?? 0; $refundAmount = $params['refundAmount'] ?? 0;
$amount = $params['amount'] ?? 0; $amount = $params['amount'] ?? 0;
@ -254,7 +224,7 @@ class Api extends AbstractApi
'refundAmount' => $refundAmount, 'refundAmount' => $refundAmount,
'amount' => $amount, 'amount' => $amount,
'remark' => $remark, 'remark' => $remark,
'notifyUrl' => $notifyUrl, 'notifyUrl' => 'http://146.70.113.165:9501/notify/refund',
'nonceStr' => StringHelper::getRandomString(32), 'nonceStr' => StringHelper::getRandomString(32),
]; ];
$sign = Signer::sign(json_encode($params)); $sign = Signer::sign(json_encode($params));
@ -275,33 +245,4 @@ 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 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);
}
} }

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Model;
class BankCard extends Model
{
protected $table = 'bank_cards';
}

@ -21,8 +21,8 @@ Router::addGroup('/payment',function () {
Router::post('/refund-query', [PayController::class, 'refundQuery']); Router::post('/refund-query', [PayController::class, 'refundQuery']);
}, ['middleware' => [\App\Middleware\RequestLogMiddleware::class]]); }, ['middleware' => [\App\Middleware\RequestLogMiddleware::class]]);
Router::addGroup('/payment',function () { Router::addGroup('/notify',function () {
Router::addRoute(['GET', 'POST'], '/notify', [NotifyController::class, 'payment']); Router::addRoute(['GET', 'POST'], '/payment', [NotifyController::class, 'payment']);
Router::addRoute(['GET', 'POST'], '/notify', [NotifyController::class, 'refund']); Router::addRoute(['GET', 'POST'], '/refund', [NotifyController::class, 'refund']);
}); });

@ -37,6 +37,31 @@ CREATE TABLE `users` (
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC; ) 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` ( CREATE TABLE `orders` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID', `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`app_id` varchar(16) NOT NULL 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 '通知地址', `notify_url` varchar(1024) NOT NULL DEFAULT '' COMMENT '通知地址',
`pay_url` varchar(1024) NOT NULL DEFAULT '' COMMENT '支付地址', `pay_url` varchar(1024) NOT NULL DEFAULT '' COMMENT '支付地址',
`token` varchar(32) NOT NULL DEFAULT '', `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 '支付时间', `payed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '支付时间',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '订单状态', `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '订单状态',
`error_code` varchar(32) NOT NULL DEFAULT '' COMMENT '错误码', `error_code` varchar(32) NOT NULL DEFAULT '' COMMENT '错误码',

Loading…
Cancel
Save