master
elf 2 years ago
parent 2089e7a60b
commit c8e823aa62

@ -4,15 +4,13 @@ declare(strict_types=1);
namespace App\Command;
use App\Helper\Efps\Api;
use App\Helper\Efps\Signer;
use App\Helper\Platform\Signer;
use App\Helper\StringHelper;
use App\Request\BindCardRequest;
use App\Request\PaymentQueryRequest;
use App\Request\ProtocolPayConfirmRequest;
use App\Request\RefundQueryRequest;
use App\Request\UnBindCardRequest;
use App\Model\App;
use App\Service\AppService;
use App\Service\MerchantService;
use App\Service\PaymentService;
use App\Service\UserService;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ContainerInterface;
@ -44,247 +42,156 @@ class MineCommand extends HyperfCommand
public function handle(): void
{
$this->pwdModify();
}
protected function generateToken() {
return md5('1-' . microtime());
}
protected function createMerchant() {
/**
* @var PaymentService $paymentService
* @var MerchantService $merchantService
*/
$paymentService = $this->container->make(PaymentService::class);
$merchantService = $this->container->make(MerchantService::class);
return $merchantService->createMerchant([
'username' => 'main',
'password' => StringHelper::getRandomString('10'),
'email' => '360197197@qq.com',
'mobile' => '18760419185',
'ip' => '127.0.0.1'
]);
}
$params = $this->pay();
$data = $paymentService->payment($params);
var_dump($data);
return;
return;
// $ret = Api::withdrawalToCard([]);
// var_dump($ret);
// return;
protected function createApp($merchant, $appName) {
/**
* @var PaymentService $paymentService
* @var AppService $appService
*/
$paymentService = $this->container->make(PaymentService::class);
$appService = $this->container->make(AppService::class);
return $appService->createApp($merchant, $appName);
}
$memberId = 'T01';
$protocol = 'p202305296288304915744';
// $result = $paymentService->protocolPayPreRequest($this->prepay($memberId, $protocol, 1));
// var_dump($result);
protected function createRequestLog($uri, $params) {
/**
* @var RequestService $requestService
*/
$requestService = $this->container->make(RequestService::class);
return $requestService->createRequestLog('/', $params);
}
$token = 'de83e93fc3594dab8d5c8707fcbc8f5c';
$smsCode = '454925';
$result = $paymentService->protocolPayConfirm($this->confirmPay($token, $protocol, $smsCode));
var_dump($result);
return;
// $this->bindCard();
// $this->comfirmBindCard();
// $this->prepay();
// $this->confirmPay();
// $this->refund();
// $this->refundQuery();
// $this->paymentQuery();
$this->unbindCard();
return;
protected function getApp($appId = '202308040000002') {
return App::where('app_id', $appId)->first();
}
public function bindCard()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'mchtOrderNo' => time() . rand(1000, 9999),
'memberId' => 'ABC',
'userName' => '测试者',
'phoneNum' => '18888888888',
'bankCardNo' => '62122610000000000',
'bankCardType' => 'debit',
'certificatesNo' => '350000000000000000',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new BindCardRequest($params);
$params = $request->getData();
var_dump($params);
protected function getToken() {
return md5(microtime() . '-' . rand(1000, 9999) );
}
public function comfirmBindCard()
{
protected function getRequestData() {
$app = $this->getApp();
$data = json_encode([
'userId' => 'ELF1991'
]);
$params = [
'app_id' => '202304270000004',
'app_id' => $app->app_id,
'nonce_str' => StringHelper::getRandomString(16),
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'memberId' => 'ABC',
'smsNo' => 'QY888888888888888',
'smsCode' => '123456',
]),
'data' => $data,
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new BindCardRequest($params);
$params = $request->getData();
var_dump($params);
$params['sign'] = Signer::sign($params, $app->app_key);
echo json_encode($params);
}
public function prepay($memberId, $protocol, $amount)
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'memberId' => $memberId,
'outTradeNo' => time() . rand(1000, 9999),
'protocol' => $protocol,
'payAmount' => $amount,
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
return $params;
protected function register($userId = 'ELF1990') {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->register(['userId' => $userId], $this->getApp(), $this->getToken());
echo $url;
}
public function confirmPay($token, $protocol, $smsCode)
protected function companyRegister($userId = 'COMPANY1990')
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'token' => $token,
'protocol' => $protocol,
'smsCode' => $smsCode,
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
return $params;
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->companyRegister(['userId' => $userId, 'email' => '360197197@qq.com'], $this->getApp(), $this->getToken());
echo $url;
}
public function refund()
protected function rsyncUser()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outRefundNo' => time() . rand(1000, 9999),
'remark' => 'xxx',
'amount' => 88,
'refundAmount' => 88,
'outTradeNo' => '123423423532',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new ProtocolPayConfirmRequest($params);
$params = $request->getData();
var_dump($params);
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$userService->rsyncUser('4673f922e30cfd2efeeb992ff6a32ece', '202308040000002', 'ELF1990');
}
public function refundQuery()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outRefundNo' => '237427342388',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new RefundQueryRequest($params);
$params = $request->getData();
var_dump($params);
protected function rsyncBankCards() {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$userService->rsyncBankCards('4673f922e30cfd2efeeb992ff6a32ece');
}
public function paymentQuery()
protected function bindCard()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outTradeNo' => '3423423432',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new PaymentQueryRequest($params);
$params = $request->getData();
var_dump($params);
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->bindCard(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
echo $url;
}
public function unbindCard()
protected function payment()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'protocol' => 'p88888888888888888',
'memberId' => 'ABC',
]),
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
'userId' => '24',
'agreementNo' => '322022110300000005068',
'notifyUrl' => 'http://www.baidu.com',
'returnUrl' => 'http://www.baidu.com',
'amount' => 10,
'outOrderNo' => time() . rand(1000, 9999),
'expiresIn' => 15*60,
'splitInfoList' => [
[
'userId' => 'ELF1990',
'sellerFlag' => 1,
'amount' => 10,
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new UnBindCardRequest($params);
$params = $request->getData();
var_dump($params);
$result = $paymentService->payment($data, $this->getApp(), $this->getToken());
var_dump($result);
}
public function pay()
public function pwdForget()
{
$params = [
'app_id' => '202305270000001',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outOrderNo' => time().rand(1000, 9999),
'outMemberId' => '1687241209',
'amount' => 100000,
'notifyUrl' => 'https://www.baidu.com',
]),
];
// $params = [http://146.70.113.165:9501/payment.html?token=9276b759977319f399a553f2745e21d9
// 'app_id' => '202306140000001',
// 'timestamp' => '1686843656',
// 'nonce_str' => '1686843656627',
// 'data' => json_encode([
// 'outMemberId' => '202306140000001',
// 'amount' => 10000,
// 'notifyUrl' => 'http://154.23.187.206:9216/api/pay/notify/aboypay/P202306152340565850000',
// 'outOrderNo' => 'P202306152340565850000'
// ])
// ];lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O nM2bUJT89njQGzoeDyK8cLmEYJloUsJX nM2bs8kGzoeDyK8cLmEYJloUksk
$sign = \App\Helper\Platform\Signer::sign($params, 'lsHKbuFngCXhN8Ue1s8QHAgzPvOL3u9O');
$params['sign'] = $sign;
// echo json_encode($params);
return $params;
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->pwdForget(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
var_dump($result);
}
public function payNew()
public function pwdModify()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outOrderNo' => time().rand(1000, 9999),
'outMemberId' => 'T00004',
'amount' => 100,
'notifyUrl' => 'https://www.baidu.com',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
// echo json_encode($params);
return $params;
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->pwdModify(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
var_dump($result);
}
}
}

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace App\Controller\Payment;
use App\Request\BindCardRequest;
use App\Request\RegisterRequest;
use App\Request\UnbindCardRequest;
use Hyperf\HttpServer\Contract\RequestInterface;
use App\Service\PaymentService;
use App\Service\UserService;
@ -20,61 +23,64 @@ class PayController extends AbstractController
$this->paymentService = $paymentService;
}
public function register(RequestInterface $request)
private function parseReqest($request, $requestClass)
{
$app = Context::get('app');
$requestLog = Context::get('requestLog');
$url = $this->userService->register($request->all(), $requestLog->request_token);
return $this->success(['url' => $url]);
$req = new $requestClass($request->all());
return [$app, $req->getData(), $requestLog->request_token];
}
public function bindCard(RequestInterface $request)
public function companyRegister(RequestInterface $request)
{
$requestLog = Context::get('requestLog');
$url = $this->userService->bindCard($request->all(), $requestLog->request_token);
return $this->success(['url' => $url]);
[$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class);
$result = $this->userService->companyRegister($data, $app, $token);
return $this->success(['result' => $result]);
}
public function unbindCard(RequestInterface $request)
public function register(RequestInterface $request)
{
$data = $this->userService->unbindCard($request->all());
return $this->success($data);
[$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class);
$url = $this->userService->register($data, $app, $token);
return $this->success(['url' => $url]);
}
public function bindCardPay(RequestInterface $request)
public function bindCard(RequestInterface $request)
{
$requestLog = Context::get('requestLog');
$data = $this->paymentService->bindCardPay($request->all(), $requestLog->request_token);
return $this->success($data);
[$app, $data, $token] = $this->parseReqest($request, BindCardRequest::class);
$url = $this->userService->bindCard($data, $app, $token);
return $this->success(['url' => $url]);
}
public function protocolPayConfirm(RequestInterface $request)
public function unbindCard(RequestInterface $request)
{
$data = $this->paymentService->protocolPayConfirm($request->all());
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->userService->unbindCard($data, $app);
return $this->success($data);
}
public function refund(RequestInterface $request) {
$data = $this->paymentService->refund($request->all());
return $this->success($data);
}
public function refundQuery(RequestInterface $request) {
$data = $this->paymentService->refundQuery($request->all());
return $this->success($data);
public function pwdForget(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$url = $this->userService->unbindCard($data, $app, $token);
return $this->success(['url' => $url]);
}
public function paymentQuery(RequestInterface $request) {
$data = $this->paymentService->paymentQuery($request->all());
return $this->success($data);
public function pwdModify(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$url = $this->userService->unbindCard($data, $app, $token);
return $this->success(['url' => $url]);
}
public function query(RequestInterface $request) {
$data = $this->paymentService->query($request->all());
public function payment(RequestInterface $request) {
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->payment($data, $app, $token);
return $this->success($data);
}
public function payment(RequestInterface $request) {
$data = $this->paymentService->payment($request->all());
public function refund(RequestInterface $request) {
$data = $this->paymentService->refund($request->all());
return $this->success($data);
}
}

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Exception;
use App\Constants\ResultCode;
use Throwable;
class ApiException extends BasicException
{
protected $code = ResultCode::DEFAULT_ERROR;
protected $errorCode;
public function __construct(string $message = null, string $errorCode = null, Throwable $previous = null)
{
if (is_null($message)) {
$message = ResultCode::getMessage($this->code);
}
$this->errorCode = $errorCode;
parent::__construct($message, $previous);
}
public function getErrorCode() {
return $this->errorCode;
}
}

@ -5,42 +5,42 @@ namespace App\Helper\Baofu;
class ApiList
{
private static $list = [
'openAccount' => [
'open-account' => [
'description' => '个人实名开户',
'url' => '/api/cust/v3.0.0/openAccount',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|customerName|certificateNo'
],
'bindCard' => [
'bind-card' => [
'description' => '个人银行卡签约-获取短信验证码',
'url' => '/api/cust/v3.0.0/bindCard',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|cardNo|bankMobile',
],
'bindCardCheck' => [
'bind-card-check' => [
'description' => '个人银行卡签约-确认绑卡',
'url' => '/api/cust/v3.0.0/bindCardCheck',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|requestNo|verifyCode',
],
'unbindCard' => [
'unbind-card' => [
'description' => '个人银行卡解约',
'url' => '/api/cust/v3.0.0/unbindCard',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|requestNo|agreementNo',
],
'queryCustomerInfo' => [
'query-customer-info' => [
'description' => '客户信息查询',
'url' => '/api/cust/v2.0.0/queryCustomerInfo',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestNo',
],
'findBindBankCards' => [
'find-bind-bank-cards' => [
'description' => '获取已绑定卡信息',
'url' => '/api/cust/v2.0.0/findBindBankCards',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|contractNo',
],
'assurePaymentSplit' => [
'assure-payment-split' => [
'description' => '个人担保支付-余额和卡',
'url' => '/api/order/v3.0.0/assurePaymentSplit',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|paidType|splitInfoList',
],
'paymentSplit' => [
'payment-split' => [
'description' => '个人支付-余额和卡',
'url' => '/api/order/v3.0.0/paymentSplitApi',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|paidType|splitInfoList',
@ -55,12 +55,12 @@ class ApiList
'url' => '/api/order/v3.0.0/withdraw',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|agreementNo',
],
'enterpriseWithdraw' => [
'enterprise-withdraw' => [
'description' => '企业提现',
'url' => '/api/order/v3.0.0/merchantWithdraw',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|agreementNo',
],
'getBalanceNew' => [
'get-balance-new' => [
'description' => '账户余额查询',
'url' => '/api/wallet/v3.0.0/getBalanceNew',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|accountType',
@ -70,77 +70,72 @@ class ApiList
'url' => '/api/order/v3.0.0/recharge',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|agreementNo',
],
'merchantTransferRecharge' => [
'merchant-transfer-recharge' => [
'description' => '企业充值',
'url' => '/api/order/v3.0.0/merchantTransferRecharge',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|agreementNo|notifyUrl',
],
'unifyPay' => [
'unify-pay' => [
'description' => '匿名支付-聚合支付',
'url' => '/api/order/v3.0.0/unifyPay',
'signParams' => 'orgNo|merchantNo|terminalNo|requestDate|loginNo|orderType|dataContent',
],
'cloudB2cAssureRecharge' => [
'cloud-b2c-assure-recharge' => [
'description' => '担保支付-网银支付',
'url' => '/api/order/v3.0.0/cloudB2cAssureRecharge',
'signParams' => 'orgNo|merchantNo|loginNo|terminalNo|requestDate|dataContent',
],
'confirmAssurePay' => [
'confirm-assure-pay' => [
'description' => '担保支付-确认分账',
'url' => '/api/wallet/v3.0.0/confirmAssurePay',
'signParams' => 'orgNo|merchantNo|loginNo|terminalNo|requestDate|dataContent',
],
'refundRequest' => [
'refund-request' => [
'description' => '担保支付-分账前退款',
'url' => '/api/trade/v3.0.0/refundRequest',
'signParams' => 'orgNo|merchantNo|terminalNo|requestDate|refundTradeId|orgTradeId|refundMoney|refundReason|notifyUrl',
],
'profitShareRefundApply' => [
'profit-share-refund-apply' => [
'description' => '担保支付-分账后退款-退款申请',
'url' => '/api/trade/v3.0.0/profitShareRefundApply',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|refundTradeId|orgTradeId|refundAmount|refundSplitInfoList',
],
'profitShareRefundConfirm' => [
'profit-share-refund-confirm' => [
'description' => '担保支付-分账后退款-退款确认',
'url' => '/api/trade/v3.0.0/profitShareRefundConfirm',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|refundTradeId|refundAmount',
],
'profitShareRefundCancel' => [
'profit-share-refund-cancel' => [
'description' => '担保支付-分账后退款-退款撤销',
'url' => '/api/trade/v3.0.0/profitShareRefundCancel',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|refundTradeId',
],
'modifyLoginNo' => [
'modify-login-no' => [
'description' => '信息维护-客户登录号变更',
'url' => '/api/cust/v3.0.0/modifyLoginNo',
'signParams' => 'orgNo|merchantNo|terminalNo|requestDate|loginNo|origLoginNo',
],
'mEnterpriseUnbindCard' => [
'enterprise-unbind-card' => [
'description' => '企业对公卡解绑',
'url' => '/api/cust/v3.0.0/applyUnbindCard',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|agreementNo'
],
'EnterpriseUnbindCard' => [
'description' => '企业对公卡解绑',
'url' => '/api/cust/v3.0.0/applyUnbindCard',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|agreementNo'
],
'sendBindCardEmail' => [
'send-bind-card-email' => [
'description' => '企业认证重发邮件',
'url' => '/api/merchant/v1/sendBindCardEmail',
'signParams' => 'orgNo|terminalNo|requestDate|loginNo'
],
'applyBindCard' => [
'apply-bind-card' => [
'description' => '企业对公卡绑定',
'url' => '/api/merchant/v1/applyBindCard',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|cardName|bankName|provinceName|cityName|branchName'
],
'merchantReportCreate' => [
'merchant-report-create' => [
'description' => '企业注册-聚合交易商户报备-v3.1版本-商户录入',
'url' => '/api/aggregationReport/v3.1.0/merchantReportCreate',
'signParams' => 'orgNo|merchantNo|terminalNo|requestDate|uniqueId|loginNo|bizContent'
],
'authBind' => [
'auth-bind' => [
'description' => '企业注册-聚合交易商户报备-v3.1版本-授权目录报备',
'url' => '/api/aggregationReport/v3.1.0/authBind',
'signParams' => 'orgNo|merchantNo|terminalNo|simId|authType|authContent'

@ -2,11 +2,7 @@
namespace App\Helper\Baofu;
use app\base\helper\Str;
use App\Helper\Redis;
use App\Helper\RedisKey;
use App\Helper\StringHelper;
use think\Env;
class Baofu
{
@ -22,12 +18,12 @@ class Baofu
'ALIPAY_NATIVE' => 1 //'支付宝主扫'
];
public function apply($loginNo, $email, $returnUrl = 'apply'){
public function apply($loginNo, $email, $token) {
$data = [];
$data['loginNo'] = $loginNo;
$data['email'] = $email;
$data['notifyUrl'] = NotifyList::getNotifyUrl('apply');
return $this->pc($returnUrl, $data);
$data['notifyUrl'] = NotifyList::getNotifyUrl('apply', $token);
return $this->pc('apply', $data);
}
public function register($loginNo, $token)
@ -42,8 +38,8 @@ class Baofu
{
$data = [];
$data['loginNo'] = $loginNo;
$data['dataContent'] = NotifyList::getNotifyUrl('cardBind', $token);
return $this->h5('cardBind', $data, $token);
$data['dataContent'] = NotifyList::getNotifyUrl('card-bind', $token);
return $this->h5('card-bind', $data, $token);
}
public function cardUnbind($loginNo, $agreementNo, $requestNo = '')
@ -55,7 +51,7 @@ class Baofu
$data['loginNo'] = $loginNo;
$data['requestNo'] = $requestNo;
$data['agreementNo'] = $agreementNo;
return $this->api('unbindCard', $data);
return $this->api('unbind-card', $data);
}
public function getBalance($loginNo)
@ -63,18 +59,18 @@ class Baofu
$data = [];
$data['loginNo'] = $loginNo;
$data['accountType'] = 'BALANCE';
return $this->api('getBalanceNew', $data);
return $this->api('get-balance-new', $data);
}
public function withdraw($params, $returnUrl = 'withdraw')
public function withdraw($params, $token)
{
$data = [];
$data['amount'] = $params['amount'];
$data['loginNo'] = $params['loginNo'];
$data['agreementNo'] = Rsa::encryptByCERFile($params['agreementNo'], $this->getCerFilePath());
$data['outOrderNo'] = $params['outOrderNo'];
$data['notifyUrl'] = NotifyList::getNotifyUrl($params['notifyUrl']);
return $this->withReturnUrl($this->api($params['notifyUrl'], $data), $returnUrl);
$data['notifyUrl'] = NotifyList::getNotifyUrl($params['notifyUrl'], $token);
return $this->withReturnUrl($this->api('withdraw', $data, $token), $token);
}
public function assurePaymentSplit($params, $token)
@ -89,7 +85,7 @@ class Baofu
$data['expireDate'] = date('YmdHis', time() + 15*60);
$data['validDate'] = date('Ymd');
$data['notifyUrl'] = $params['notifyUrl'];
return $this->withReturnUrl($this->api('assurePaymentSplit', $data), $token);
return $this->withReturnUrl($this->api('assure-payment-split', $data), $token);
}
public function paymentSplit($params, $token)
@ -101,9 +97,9 @@ class Baofu
$data['paidType'] = $params['paidType'] ?: 'CARD';
$data['agreementNo'] = Rsa::encryptByCERFile($params['agreementNo'], $this->getCerFilePath());
$data['splitInfoList'] = json_encode($params['splitInfoList']);
$data['pwdPayExpTime'] = time() + 15*60;
$data['notifyUrl'] = $params['notifyUrl'];
return $this->withReturnUrl($this->api('paymentSplitApi', $data), $token);
$data['pwdPayExpTime'] = $params['pwdPayExpTime'];
$data['notifyUrl'] = NotifyList::getNotifyUrl('payment', $token);
return $this->withReturnUrl($this->api('payment-split', $data), $token);
}
public function unifyPay($params){
@ -156,7 +152,7 @@ class Baofu
$data['loginNo'] = $params['loginNo'];
$data['payId'] = $params['payId'];
$data['dataContent'] = json_encode($dataContent);
return $this->api('cloudB2cAssureRecharge', $data);
return $this->api('cloud-b2c-assure-recharge', $data);
}
public function payment($params, $type = 'ASSURE_PAYMENT')
@ -195,26 +191,26 @@ class Baofu
}
}
public function recharge($params, $returnUrl = 'recharge')
public function recharge($params, $token)
{
$data = [];
$data['loginNo'] = $params['loginNo'];
$data['amount'] = $params['amount'];
$data['outOrderNo'] = $params['outOrderNo'];
$data['agreementNo'] = Rsa::encryptByCERFile($params['agreementNo'], $this->getCerFilePath());
$data['notifyUrl'] = NotifyList::getNotifyUrl('recharge');
return $this->withReturnUrl($this->api('recharge', $data), $returnUrl);
$data['notifyUrl'] = NotifyList::getNotifyUrl('recharge', $token);
return $this->withReturnUrl($this->api('recharge', $data), $token);
}
public function merchantTransferRecharge($params, $returnUrl = 'recharge')
public function merchantTransferRecharge($params, $token)
{
$data = [];
$data['loginNo'] = $params['loginNo'];
$data['amount'] = $params['amount'];
$data['outOrderNo'] = $params['outOrderNo'];
$data['agreementNo'] = Rsa::encryptByCERFile($params['agreementNo'], $this->getCerFilePath());
$data['notifyUrl'] = NotifyList::getNotifyUrl('recharge');
return $this->api('merchantTransferRecharge', $data);
$data['notifyUrl'] = NotifyList::getNotifyUrl('recharge', $token);
return $this->api('merchant-transfer-recharge', $data);
}
public function confirmAssurePay($params)
@ -230,7 +226,7 @@ class Baofu
$data['loginNo'] = $params['loginNo'];
$data['dataContent'] = json_encode($dataContent);
$data['notifyUrl'] = $params['notifyUrl'];
return $this->api('confirmAssurePay', $data);
return $this->api('confirm-assure-pay', $data);
}
public function findBindBankCards($params)
@ -239,7 +235,7 @@ class Baofu
$data['loginNo'] = $params['loginNo'];
$data['contractNo'] = $params['contractNo'];
$data['tradeType'] = 'BASE_LIST';
return $this->api('findBindBankCards', $data);
return $this->api('find-bind-bank-cards', $data);
}
public function queryCustomerInfo($loginNo, $customerType = 'PERSON')
@ -249,39 +245,39 @@ class Baofu
$data['loginNo'] = $loginNo;
$data['customerType'] = $customerType;
$data['requestNo'] = $requestNo;
$result = $this->api('queryCustomerInfo', $data);
$result = $this->api('query-customer-info', $data);
return json_decode($result, true);
}
public function pwdModify($loginNo, $returnUrl = 'pwdModify')
public function pwdModify($loginNo, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
return $this->h5($returnUrl, $data);
return $this->h5('pwd-modify', $data, $token);
}
public function mEnterprisePwdModify($loginNo, $returnUrl = 'mEnterprisePwdModify')
public function enterprisePwdModify($loginNo, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
return $this->h5($returnUrl, $data);
return $this->h5('enterprise-pwd-modify', $data, $token);
}
public function pwdForget($loginNo, $returnUrl = 'pwdForget')
public function pwdForget($loginNo, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
return $this->h5($returnUrl, $data);
return $this->h5('pwd-forget', $data, $token);
}
public function mPwReset($loginNo, $returnUrl = 'mPwReset')
public function pwReset($loginNo, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
return $this->h5($returnUrl, $data);
return $this->h5('pw-reset', $data, $token);
}
public function refund($params, $returnUrl = 'refund')
public function refund($params, $token)
{
$data = [];
$data['loginNo'] = $params['loginNo'];
@ -291,8 +287,8 @@ class Baofu
$data['refundReason'] = $params['refundReason'];
$data['oldSubOutOrderNo'] = $params['oldSubOutOrderNo'];
// $data['refundSplitInfoList'] = json_encode($params['refundSplitInfoList']);
$data['notifyUrl'] = NotifyList::getNotifyUrl($returnUrl);
return $this->api('refundRequest', $data);
$data['notifyUrl'] = NotifyList::getNotifyUrl('refund', $token);
return $this->api('refund-request', $data);
}
public function modifyLoginNo($origLoginNo, $loginNo)
@ -300,189 +296,99 @@ class Baofu
$data = [];
$data['loginNo'] = $loginNo;
$data['origLoginNo'] = $origLoginNo;
return $this->api('modifyLoginNo', $data);
return $this->api('modify-login-no', $data);
}
public function mEnterpriseUnbindCard($loginNo, $agreementNo, $returnUrl = 'mEnterpriseUnbindCard')
public function enterpriseUnbindCard($loginNo, $agreementNo, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
$data['agreementNo'] = $agreementNo;
$data['notifyUrl'] = NotifyList::getNotifyUrl($returnUrl);
return $this->api($returnUrl,$data);
$data['notifyUrl'] = NotifyList::getNotifyUrl('enterprise-unbind-card', $token);
return $this->api('enterprise-unbind-card', $data);
}
public function sendBindCardEmail($loginNo, $returnUrl = 'sendBindCardEmail')
public function sendBindCardEmail($loginNo)
{
$data = [];
$data['loginNo'] = $loginNo;
return $this->api($returnUrl,$data);
return $this->api('send-bind-card-email',$data);
}
public function applyBindCard($loginNo, $info, $returnUrl = 'applyBindCard')
public function applyBindCard($loginNo, $info, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
$data['cardNo'] = BFRSA::encryptByCERFile($info['cardNo'], EXTEND_PATH . Env::get('BAOFOO_CER_FILE_PATH'));
$data['cardNo'] = BFRSA::encryptByCERFile($info['cardNo'], config('baofu.cerFilePath'));
$data['cardName'] = $info['cardName'];
$data['bankName'] = $info['bankName'];
$data['branchName'] = $info['branchName'];
$data['provinceName'] = $info['provinceName'];
$data['cityName'] = $info['cityName'];
$data['notifyUrl'] = NotifyList::getNotifyUrl($returnUrl);
return $this->api($returnUrl,$data);
$data['notifyUrl'] = NotifyList::getNotifyUrl('apply-bind-card', $token);
return $this->api('apply-bind-card' ,$data);
}
public function openAccount($loginNo, $info, $returnUrl = 'openAccount')
public function openAccount($loginNo, $info)
{
$data = [];
$data['loginNo'] = $loginNo;
$data['customerName'] = BFRSA::encryptByCERFile($info['customerName'], EXTEND_PATH . Env::get('BAOFOO_CER_FILE_PATH'));
$data['certificateNo'] = BFRSA::encryptByCERFile($info['certificateNo'], EXTEND_PATH . Env::get('BAOFOO_CER_FILE_PATH'));
$data['customerName'] = BFRSA::encryptByCERFile($info['customerName'], config('baofu.cerFilePath'));
$data['certificateNo'] = BFRSA::encryptByCERFile($info['certificateNo'], config('baofu.cerFilePath'));
$data['base64imageFront'] = $info['imageFront'];
$data['base64imageBack'] = $info['imageBack'];
return $this->api($returnUrl,$data);
return $this->api('open-account', $data);
}
public function shortMessage($loginNo, $info, $returnUrl = 'bindCard')
public function bindCard($loginNo, $info, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
$data['cardNo'] = BFRSA::encryptByCERFile($info['cardNo'], EXTEND_PATH . Env::get('BAOFOO_CER_FILE_PATH'));
$data['bankMobile'] = BFRSA::encryptByCERFile($info['bankMobile'], EXTEND_PATH . Env::get('BAOFOO_CER_FILE_PATH'));
$data['notifyUrl'] = NotifyList::getNotifyUrl('cardBind');
return $this->api($returnUrl,$data);
$data['cardNo'] = BFRSA::encryptByCERFile($info['cardNo'], config('baofu.cerFilePath'));
$data['bankMobile'] = BFRSA::encryptByCERFile($info['bankMobile'], config('baofu.cerFilePath'));
$data['notifyUrl'] = NotifyList::getNotifyUrl('card-bind', $token);
return $this->api('bind-card',$data);
}
public function fixedBinding($loginNo, $info, $returnUrl = 'bindCardCheck')
public function fixedBinding($loginNo, $info, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
$data['requestNo'] = $info['requestNo'];
$data['verifyCode'] = $info['verifyCode'];
$res = $this->api('bindCardCheck', $data);
return $this->withReturnUrl($res['url'], $returnUrl);
}
// 分账后退款-退款申请-请求示例
// {
// "merchantNo": "100026136",
// "terminalNo": "200001259",
// "orgNo": "100026136",
// "refundTradeId": "TID16317806300773",
// "refundTradeType": "REFUND_APPLY",
// "refundReason": "默认退款",
// "requestDate": "20210916162350",
// "loginNo": "13111111111",
// "refundSplitInfoList": [{
// "orgSubOutOrderNo": "subAH66EXyRAYP2SwGZ8663",
// "refundAmount": "250"
// }, {
// "orgSubOutOrderNo": "sub5dAfxGcncXPfD5AmRYDr",
// "refundAmount": "250"
// }],
// "orgTradeId": "TID16317805680623",
// "refundAmount": "500",
// "signData": "414875aa3a2c4c8ed4ded198ea1f4025277ab239a73c3d7d4f1a8aed2d918f7fb660328bd54c47770579e181cf76fa7ab653c8d0b28bad8bfdf161bc8dfb32184d1b9ce041baa2395761e70267d7f4a56721ae509510a5293237e8a93614ad25227e146c8a4d16097db852fb216841f50c43aaaaca3cdd33effc283f33bfc6ab"
// }
$result = $this->api('bind-card-check', $data);
return $this->withReturnUrl($result['url'], $token);
}
public function profitShareRefundApply($params){
$data = [];
$data['loginNo'] = $params['loginNo'] ?: "";// 匿名支付不需要传
$data['loginNo'] = $params['loginNo'] ?: '';// 匿名支付不需要传
$data['refundTradeId'] = $params['refundTradeId'];
$data['refundTradeType'] = 'REFUND_APPLY';
$data['orgTradeId'] = $params['orgTradeId'];
$data['refundAmount'] = $params['refundAmount']; // 单位:分
$data['refundReason'] = $params['refundReason'];
$data['refundSplitInfoList'] = $params['refundSplitInfoList'];
return $this->api('profit-share-refund-apply', $data);
}
// 响应示例
// {
// "success": true,
// "result": {
// "refundOrderId": "21091600000002659",
// "refundTradeId": "TID16317806300773",
// "refundAmount": "500",
// "refundSplitResultList": [{
// "orgSubOutOrderNo": "subAH66EXyRAYP2SwGZ8663",
// "status": "P",
// "message": null
// }, {
// "orgSubOutOrderNo": "sub5dAfxGcncXPfD5AmRYDr",
// "status": "P",
// "message": null
// }]
// },
// "errorCode": null,
// "errorMsg": null
// }
return $this->api('profitShareRefundApply', $data);
}
// 分账后退款-退款确认-请求示例
// {
// "merchantNo": "100026136",
// "terminalNo": "200001259",
// "orgNo": "100026136",
// "refundTradeId": "TID16317806300773",
// "refundTradeType": "REFUND_CONFIRM",
// "requestDate": "20210916163026",
// "notifyUrl": "http://10.0.60.55:8080/BF_BHT_DEMO_V1/notifyUrl.action?ct=profitShareRefundConfirm",
// "loginNo": "13111111111",
// "orgTradeId": "TID16317805680623",
// "refundAmount": "500",
// "signData": "b5d1d2fe99cdafd24cb77aabc29a4b361a5c83fcd218d98b729220dc720a0479e8ffe1a362074cb8b1cf3ad0bd843c52c54a1e44299f8b6e1d5cbaf140b9d4ac356e271b5ad56551a996271d23075a2637daf35376486d0623a884273d45dfcb50596d124a47cbda4f52d204daf25dddc274239f98c010b6a980d074064fd2ab"
// }
public function profitShareRefundConfirm($params){
$data = [];
$data['loginNo'] = $params['loginNo'] ?: "";// 匿名支付不需要传
$data['loginNo'] = $params['loginNo'] ?: '';// 匿名支付不需要传
$data['refundTradeId'] = $params['refundTradeId']; // 与退款申请中的退款请求订单号一致
$data['refundTradeType'] = 'REFUND_CONFIRM';
$data['orgTradeId'] = $params['orgTradeId']; // 原始支付商户订单号
$data['refundAmount'] = $params['refundAmount']; // 单位:分
$data['notifyUrl'] = $params['notifyUrl'];
return $this->api('profit-share-refund-confirm', $data);
}
// 响应示例
// {
// "success": true,
// "result": {
// "refundOrderId": "21091600000002659",
// "refundTradeId": "TID16317806300773",
// "refundMoney": "500",
// "refundStatus": "P",
// "refundType": "BALANCE",
// "message": null
// },
// "errorCode": null,
// "errorMsg": null
// }
return $this->api('profitShareRefundConfirm', $data);
}
// 分账后退款-退款撤销-请求示例
// {
// "merchantNo": "100026136",
// "terminalNo": "200001259",
// "refundTradeId": "TID16317811945423",
// "orgNo": "100026136",
// "refundTradeType": "REFUND_CANCEL",
// "requestDate": "20210916163400",
// "loginNo": "13111111111",
// "signData": "618d70be82967ff6b7b8821446df9476b32ea8442fae4283f3bbfa80034fbb2c42a7f0098522a4729a75182ba51e176401279f0a702a7e0b2a3581f62238ed9cb8e7cbc1295a640506d0fbce5d98b20536c9a46994d5a8f590d7492d9f10b561183307798630ddf74669cddbdf45bcc3c090b28925a4ed1b1353b4c3c798a2af"
// }
public function profitShareRefundCancel($params){
$data = [];
$data['loginNo'] = $params['loginNo'] ?: "";// 匿名支付不需要传
$data['loginNo'] = $params['loginNo'] ?: '';// 匿名支付不需要传
$data['refundTradeId'] = $params['refundTradeId']; // 与退款申请中的退款请求订单号一致
$data['refundTradeType'] = 'REFUND_CANCEL';
// 响应示例
// {
// "success": true,
// "result": true,
// "errorCode": null,
// "errorMsg": null
// }
return $this->api('profitShareRefundCancel', $data);
return $this->api('profit-share-refund-cancel', $data);
}
public function merchantReportCreate($params){
@ -491,26 +397,21 @@ class Baofu
$data['loginNo'] = $params['loginNo'];
$data['reportType'] = $params['reportType'];
$data['bizContent'] = json_encode([
"servicePhone" => $params['servicePhone'],
"businessLicense" => $params['businessLicense'],
"businessLicenseType" => $params['businessLicenseType'],
"merchantName" => $params['merchantName'],
"merchantShortName" => $params['merchantShortName'],
"channelId" => $this->getChannelId(),
"channelName" => $this->getChannelName(),
"business" => $params['business'],
"contactWechatIdType" => $params['contactWechatIdType'],
"contactWechatId" => $params['contactWechatId'],
"serviceCodes" => $params['serviceCodes'],
"addressInfo" => $params['addressInfo'],
"bankCardInfo" => $params['bankCardInfo']
'servicePhone' => $params['servicePhone'],
'businessLicense' => $params['businessLicense'],
'businessLicenseType' => $params['businessLicenseType'],
'merchantName' => $params['merchantName'],
'merchantShortName' => $params['merchantShortName'],
'channelId' => $this->getChannelId(),
'channelName' => $this->getChannelName(),
'business' => $params['business'],
'contactWechatIdType' => $params['contactWechatIdType'],
'contactWechatId' => $params['contactWechatId'],
'serviceCodes' => $params['serviceCodes'],
'addressInfo' => $params['addressInfo'],
'bankCardInfo' => $params['bankCardInfo']
]);
// 响应示例(成功)
// {"success":true,"result":{"state":"SUCCESS","simId":"472688640"},"errorCode":null,"errorMsg":null}
// 响应示例(失败)
// {"success":false,"result":null,"errorCode":"PARAMETER_VALID","errorMsg":"uniqueId格式不合法"}
return $this->api('merchantReportCreate', $data);
return $this->api('merchant-report-create', $data);
}
public function authBind($params){
@ -518,26 +419,6 @@ class Baofu
$data['simId'] = $params['simId'];
$data['authType'] = $params['authType'];
$data['authContent'] = $params['authContent'];
// 响应示例(成功)
// {"success":true,"result":{"state":"SUCCESS"},"errorCode":null,"errorMsg":null}
// 响应示例(失败)
// {"success":false,"result":null,"errorCode":"FAILED","errorMsg":"商户报备记录不存在"}
return $this->api('authBind', $data);
}
public function setToken($token, $apiName, $params) {
$key = RedisKey::getRequestTokenKey($token);
Redis::set($key, json_encode([
'appName' => $apiName,
'params' => $params,
]));
Redis::expire($key, 60 * 60);
}
public function getToken($token) {
$key = RedisKey::getRequestTokenKey($token);
Redis::set($key);
Redis::expire($key, 15 * 60);
return $this->api('auth-bind', $data);
}
}

@ -2,9 +2,9 @@
namespace App\Helper\Baofu;
use App\Exception\BusinessException;
use think\Config;
use think\Log;
use App\Exception\ApiException;
use App\Helper\Log;
use Exception;
trait Common
{
@ -13,10 +13,10 @@ trait Common
private function getConfig()
{
if (is_null($this->config)) {
$this->config = Config::get('baofu');
$this->config = config('baofu');
}
if (is_null($this->config)) {
throw new BusinessException('宝付未配置');
throw new ApiException('宝付未配置', 'ERROR_CONFIG');
}
return $this->config;
}
@ -78,7 +78,7 @@ trait Common
$simId = $this->getSimIDWx();
break;
default:
throw new BusinessException('未选择类型');
throw new ApiException('未选择类型', 'ERROR_SIMID');
break;
}
return $simId;
@ -98,7 +98,7 @@ trait Common
{
$pcItem = PcList::get($pcName);
if (is_null($pcItem)) {
throw new BusinessException('未定义PC接口');
throw new ApiException('未定义PC接口', 'ERROR_API');
}
$response = $this->post($data, $pcItem, 'form');
return $this->parseResponse($response, 'pc');
@ -108,7 +108,7 @@ trait Common
{
$h5Item = H5List::get($h5Name);
if (is_null($h5Item)) {
throw new BusinessException('未定义H5接口');
throw new ApiException('未定义H5接口', 'ERROR_API');
}
$response = $this->post($data, $h5Item);
return $this->withReturnUrl($this->parseResponse($response, 'h5'), $token);
@ -118,9 +118,9 @@ trait Common
{
$apiItem = ApiList::get($apiName);
if (is_null($apiItem)) {
throw new BusinessException('未定义API接口');
throw new ApiException('未定义API接口', 'ERROR_API');
}
if ($apiName == 'EnterpriseUnbindCard') {
if ($apiName == 'enterpriseUnbindCard') {
$response = $this->post($data, $apiItem, 'json');
$res = $this->parseResponse($response, 'api');
return $this->withReturnUrl($res['checkPwdUrl'], $token);
@ -136,11 +136,13 @@ trait Common
$data = $this->buildData($data, $apiOrH5Item);
$response = '';
try {
Log::write('BaofuPost{time: ' . date('Y-m-d H:i:s') . ', url: '. $url . ', data: '. json_encode(new \ArrayObject($data)) . ', dataType: '. $dataType . '}');
Log::info('Baofu Request Url: '. $url);
Log::info('Baofu Request Data: ', $data);
$response = HttpClient::post($url, $data, $dataType);
Log::write('BaofuPost{response: '. $response . '}');
} catch (BusinessException $e) {
throw new BusinessException('网络错误');
Log::info('Baofu Response: '. $response);
} catch (Exception $e) {
Log::info('Baofu Request Error: ' . $e->getMessage());
throw new ApiException('网络错误', 'ERROR_NETWORK');
}
return $response;
@ -150,27 +152,27 @@ trait Common
{
$result = json_decode($response, true);
if (is_null($result)) {
throw new BusinessException('接口返回数据异常');
throw new ApiException('接口返回数据异常', 'ERROR_RESPONSE');
}
if ($mode == 'api') {
if (!$result['success']) {
throw new BusinessException($result['errorMsg']);
throw new ApiException($result['errorMsg'], $result['errorCode']);
}
return $result['result'];
} elseif ($mode == 'pc') {
if (!$result['success']) {
throw new BusinessException($result['errorMsg']);
throw new ApiException($result['errorMsg'], $result['errorCode']);
}
return $result['result'];
} elseif ($mode == 'h5') {
if ($result['retCode'] != 'SUCCESS') {
throw new BusinessException($result['retMsg']);
throw new ApiException($result['retMsg'], $result['retCode']);
}
return $result['redirectUrl'];
}
throw new BusinessException('error parse response mode!!!');
throw new ApiException('error parse response mode!!!', 'ERROR_MODE');
}
private function buildData($data, $apiOrH5Item)
@ -199,7 +201,7 @@ trait Common
{
$paramList = explode('|', $needSignParams);
$signString = Tool::getSignStr($needSignParams, $paramList, $data, 'request');
Log::write('BaofuPost{signString: '. $signString . '}');
Log::info('Baofu SignString: ' . $signString);
return SignatureUtil::sign($signString, $this->getPfxFilePath(), $this->getPrivateKeyPassword());
}
@ -207,7 +209,7 @@ trait Common
{
$notifyItem = NotifyList::get($notifyName);
if (is_null($notifyItem)) {
throw new BusinessException('回调未定义');
throw new ApiException('回调未定义', 'ERROR_NOTIFY');
}
$needSignParams = $notifyItem['signParams'];
$paramList = explode('|', $needSignParams);

@ -16,13 +16,13 @@ class H5List
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|dataContent',
'callType' => 'REGISTER',
],
'cardBind' => [
'card-bind' => [
'description' => '个人银行卡签约',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|dataContent',
'callType' => 'CARDBIND',
],
'cardUnbind' => [
'card-unbind' => [
'description' => '个人银行卡解约',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|dataContent',
@ -34,55 +34,25 @@ class H5List
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null',
'callType' => 'WITHDRAW',
],
'pwdModify' => [
'pwd-modify' => [
'description' => '个人支付密码修改',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|',
'callType' => 'PWDMODIFY',
],
'mPwdModify' => [
'description' => '个人支付密码修改',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|',
'callType' => 'PWDMODIFY',
],
'pwdForget' => [
'pwd-forget' => [
'description' => '个人支付密码设置',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|',
'callType' => 'PWDFORGET',
],
'mPwdForget' => [
'description' => '个人支付密码设置',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|',
'callType' => 'PWDFORGET',
],
'pwdForgetWebView' => [
'description' => '个人支付密码设置',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|',
'callType' => 'PWDFORGET',
],
'mPwReset' => [
'description' => '企业支付密码设置',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null',
'callType' => 'BM_PWRESET',
],
'PwReset' => [
'pw-reset' => [
'description' => '企业支付密码设置',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null',
'callType' => 'BM_PWRESET',
],
'mEnterprisePwdModify' => [
'description' => '企业支付密码修改',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null',
'callType' => 'BM_PWDMODIFY'
],
'EnterprisePwdModify' => [
'enterprise-pwd-modify' => [
'description' => '企业支付密码修改',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null',

@ -7,11 +7,11 @@ use Exception;
class NotifyList
{
private static $list = [
'apply_auth' => [
'apply-auth' => [
'description' => '企业实名开户-小额鉴权',
'signParams' => 'orgNo|merchantNo|terminalNo|contractNo|loginNo|customerName|email|mobile|authFlag'
],
'apply_open_card' => [
'apply-open-card' => [
'description' => '企业实名开户-小额打款',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|applyNo|noticeType|successFlag'
],
@ -23,7 +23,7 @@ class NotifyList
'description' => '注册(H5)',
'signParams' => 'orgNo|merchantNo|terminalNo|contractNo|loginNo',
],
'cardBind' => [
'card-bind' => [
'description' => '绑卡(H5/API)',
'signParams' => 'orgNo|merchantNo|terminalNo|contractNo|loginNo|bindCardFlag',
],
@ -35,15 +35,15 @@ class NotifyList
'description' => '个人提现(API)',
'signParams' => 'orgNo|merchantNo|terminalNo|orderStatus|tradeId|paidType|orderMoney|loginId|finishTime|orderId|errorMsg',
],
'enterpriseWithdraw' => [
'enterprise-withdraw' => [
'description' => '企业提现(API)',
'signParams' => 'orgNo|merchantNo|terminalNo|tradeId|orderStatus|loginId|finishTime',
],
'confirmSplit' => [
'confirm-split' => [
'description' => '确认分账',
'signParams' => 'orgNo|merchantNo|terminalNo|tradeId|subOutOrderNo|orderStatus|loginId|finishTime|confirmType',
],
'confirmEscrowSplit' => [
'confirm-escrow-split' => [
'description' => '自助交易确认分账',
'signParams' => 'orgNo|merchantNo|terminalNo|tradeId|subOutOrderNo|orderStatus|loginId|finishTime|confirmType',
],
@ -51,11 +51,11 @@ class NotifyList
'description' => '退款',
'signParams' => 'orgNo|merchantNo|terminalNo|refundOrderId|refundTradeId|refundMoney|refundStatus|refundSuccTime|refundType|errorMsg',
],
'escrowRefund' => [
'escrow-refund' => [
'description' => '退款',
'signParams' => 'orgNo|merchantNo|terminalNo|refundOrderId|refundTradeId|refundMoney|refundStatus|refundSuccTime|refundType|errorMsg',
],
'unifyRefund' => [
'unify-refund' => [
'description' => '匿名支付退款',
'signParams' => 'orgNo|merchantNo|terminalNo|refundOrderId|refundTradeId|refundMoney|refundStatus|refundSuccTime|refundType|errorMsg',
],
@ -63,23 +63,19 @@ class NotifyList
'description' => '支付',
'signParams' => 'orgNo|merchantNo|terminalNo|orderStatus|tradeId|paidType|orderMoney|loginId|finishTime|orderId|errorMsg',
],
'escrowPayment' => [
'escrow-payment' => [
'description' => '自助交易支付',
'signParams' => 'orgNo|merchantNo|terminalNo|orderStatus|tradeId|paidType|orderMoney|loginId|finishTime|orderId|errorMsg',
],
'unifyPayment' => [
'unify-payment' => [
'description' => '匿名支付',
'signParams' => 'orgNo|merchantNo|terminalNo|orderStatus|tradeId|paidType|orderMoney|finishTime|orderId|errorMsg',
],
'mEnterpriseUnbindCard' => [
'enterprise-unbind-card' => [
'description' => '企业对公卡解绑',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|noticeType|successFlag|agreementNo'
],
'EnterpriseUnbindCard' => [
'description' => '企业对公卡解绑',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|noticeType|successFlag|agreementNo'
],
'applyBindCard' => [
'apply-bind-card' => [
'description' => '企业对公卡绑定',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|applyNo|noticeType|successFlag'
]
@ -96,6 +92,6 @@ class NotifyList
if (is_null($notifyItem)) {
throw new Exception('回调不存在');
}
return env('WEB_HOST') . '/notify/' . ($notifyItem['url'] ?: $notifyName) . '/' . $token;
return env('WEB_HOST') . '/notify/' . ($notifyItem['url'] ?? $notifyName) . '/' . $token;
}
}

@ -8,8 +8,10 @@ class StringHelper
{
const ORDER_NO_TYPE_PAY = 'pay';
const ORDER_NO_TYPE_PAY_SPLIT = 'pay_split';
const ORDER_NO_TYPE_REFUND= 'refund';
const ORDER_NO_TYPE_UNBIND_CARD = 'unbind_card';
const ORDER_NO_TYPE_QUERY_CUSTOMER_INFO = 'query_customer_info';
const ORDER_NO_TYPE_REQUEST_ID = 'request_id';
public static function getRandomString($length, $withSpecialChar = false)
{

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace App\Middleware;
use App\Service\AppService;
use Hyperf\Context\Context;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
use Hyperf\Contract\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class AppAuthMiddleWare implements MiddlewareInterface
{
protected ContainerInterface $container;
protected RequestInterface $request;
protected HttpResponse $response;
public function __construct(ContainerInterface $container, HttpResponse $response, RequestInterface $request)
{
$this->container = $container;
$this->response = $response;
$this->request = $request;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$params = $this->request->all();
/**
* @var AppService $appService
*/
$appService = $this->container->make(AppService::class);
$app = $appService->checkSign($params);
Context::set('app', $app);
return $handler->handle($request);
}
}

@ -4,13 +4,11 @@ declare(strict_types=1);
namespace App\Middleware;
use App\Helper\Redis;
use App\Helper\RedisKey;
use App\Model\RequestLog;
use App\Service\RequestService;
use Hyperf\Context\Context;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
use Psr\Container\ContainerInterface;
use Hyperf\Contract\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
@ -34,15 +32,11 @@ class RequestLogMiddleware implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$params = $this->request->all();
$appId = $params['app_id'] ?? 0;
$requestLog = new RequestLog();
$requestLog->app_id = $appId;
$requestLog->request_id = $this->generateOrderNo();
$requestLog->request_token = $requestLog->generateToken();
$requestLog->request_uri = $this->request->getRequestUri();
$requestLog->request_data = json_encode($params, JSON_UNESCAPED_UNICODE);
$requestLog->request_time = date('Y-m-d H:i:s');
$requestLog->save();
/**
* @var RequestService $requestService
*/
$requestService = $this->container->make(RequestService::class);
$requestLog = $requestService->createRequestLog($this->request->getRequestUri(), $params);
$ctxResponse = Context::get(ResponseInterface::class);
$ctxResponse = $ctxResponse->withHeader('X-Request-Id', $requestLog->request_id);
@ -55,14 +49,4 @@ class RequestLogMiddleware implements MiddlewareInterface
$requestLog->response_time = date('Y-m-d H:i:s');
return $response;
}
private function generateOrderNo() {
$now = time();
$key = RedisKey::getGenerateRequestIdKey($now);
$incrId = Redis::incr($key);
$incrId = '' . $incrId;
Redis::expire($key, 5*60);
$padLength = 8 - strlen($incrId);
$incrId = str_pad($incrId, $padLength, '0', STR_PAD_LEFT);
return date('YmdHis', $now) . $incrId;
}
}

@ -14,6 +14,10 @@ class Order extends Model
protected $table = 'orders';
protected $casts = [
'org_split_info_list' => 'array',
];
public function getStatusText() {
$statusMap = [
self::STATUS_APPLY_FAIL => '申请失败',

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Model;
class RefundOrder extends Model
class Refund extends Model
{
public const STATUS_PREPARE = 1;
public const STATUS_APPLY_SUCCESS = 2;
@ -12,5 +12,5 @@ class RefundOrder extends Model
public const STATUS_REFUND_SUCCESS = 8;
public const STATUS_REFUND_FAILED = 9;
protected $table = 'refund_orders';
protected $table = 'refunds';
}

@ -3,19 +3,10 @@ declare(strict_types=1);
namespace App\Request;
use App\Exception\BusinessException;
use App\Helper\Signer;
use App\Model\App;
class ApiRequest extends Request
{
protected App $app;
public function __construct(array $params = [])
{
$this->checkApp($params['app_id'] ?? null);
$this->checkSign($params);
$data = json_decode($params['data'], true);
foreach ($this->defaults() as $key => $value) {
if (isset($data[$key])) {
@ -28,32 +19,4 @@ class ApiRequest extends Request
}
$this->_data = $data;
}
protected function checkSign($params) {
if (!Signer::verify($params, $this->app->app_key)) {
throw new BusinessException('验签错误');
}
if ($params['timestamp'] < time() - 6000) {
throw new BusinessException('请求已过期');
}
}
protected function checkApp($appId) {
if (is_null($appId)) {
throw new BusinessException('[app_id]错误');
}
$app = App::query()->where('app_id', $appId)->first();
if (is_null($app)) {
throw new BusinessException('APP错误');
}
if ($app->status != 1) {
throw new BusinessException('应用暂未启用');
}
$this->app = $app;
}
public function getApp() {
return $this->app;
}
}

@ -2,7 +2,7 @@
namespace App\Request;
class UnBindCardRequest extends ApiRequest
class UnbindCardRequest extends ApiRequest
{
public function rules(): array
{

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace App\Service;
use App\Exception\BusinessException;
use App\Helper\Platform\Signer;
use App\Helper\Redis;
use App\Helper\RedisKey;
use App\Helper\StringHelper;
@ -12,17 +14,20 @@ use App\Model\Merchant;
class AppService extends AbstractService
{
public function createApp(Merchant $merchant) {
public function createApp(Merchant $merchant, string $appName)
{
$app = new App();
$app->merchant_id = $merchant->id;
$app->app_id = $this->generateAppId();
$app->app_key = StringHelper::getRandomString(32);
$app->app_name = $appName;
$app->status = App::STATUS_ACTIVE;
$app->save();
return $app;
}
private function generateAppId() {
private function generateAppId()
{
$now = time();
$key = RedisKey::getGenerateAppIdKey($now);
$expireAt = strtotime(date('Y-m-d 23:59:59', $now)) + 1;
@ -33,4 +38,36 @@ class AppService extends AbstractService
$incrId = str_pad($incrId, $padLength, '0', STR_PAD_LEFT);
return date('Ymd', $now) . $incrId;
}
private function checkApp($appId): App
{
if (is_null($appId)) {
throw new BusinessException('[app_id]错误');
}
$app = App::query()->where('app_id', $appId)->first();
if (is_null($app)) {
throw new BusinessException('APP错误');
}
if ($app->status != 1) {
throw new BusinessException('应用暂未启用');
}
return $app;
}
public function checkSign($params): App
{
$appId = $params['app_id'] ?? null;
$app = $this->checkApp($appId);
if (!Signer::verify($params, $app->app_key)) {
throw new BusinessException('验签错误');
}
if ($params['timestamp'] < time() - 6000) {
throw new BusinessException('请求已过期');
}
return $app;
}
}

@ -4,30 +4,16 @@ declare(strict_types=1);
namespace App\Service;
use App\Exception\ApiException;
use App\Exception\BasicException;
use App\Exception\BusinessException;
use App\Helper\Baofu\Baofu;
use App\Helper\Efps\Api;
use App\Helper\Efps\Result;
use App\Helper\Log;
use App\Helper\StringHelper;
use App\Model\App;
use App\Model\BankCard;
use App\Model\Order;
use App\Model\OrderSplitInfo;
use App\Model\PrePayLog;
use App\Model\RefundOrder;
use App\Model\Refund;
use App\Model\User;
use App\Request\BindCardConfirmRequest;
use App\Request\BindCardRequest;
use App\Request\PaymentQueryRequest;
use App\Request\PaymentRequest;
use App\Request\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest;
use App\Request\RefundQueryRequest;
use App\Request\RefundRequest;
use App\Request\UnBindCardRequest;
use Exception;
class PaymentService extends AbstractService
{
@ -39,21 +25,24 @@ class PaymentService extends AbstractService
return md5($appId . '-' . $outMemberId);
}
public function bindCardPay($params, $token) {
$req = new PaymentRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
$user = User::where('app_id', $app->app_id)->where('user_id', $reqData['userId'])->first();
if ($user) {
throw new BusinessException('用户已存在');
public function payment(array $data, App $app, string $token) {
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $reqData['outOrderNo'])->first();
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first();
if ($order) {
throw new BusinessException('订单号重复');
}
[$order, $orderSplitInfos] = $this->createOrder($app, $reqData, $user);
[$order, $orderSplitInfos] = $this->createOrder($app, $data, $user);
$splitInfoList = $this->buildSplitInfoList($orderSplitInfos);
return $this->paymentSplit($order, $user, $splitInfoList, $token);
}
private function buildSplitInfoList($orderSplitInfos) {
$splitInfoList = [];
foreach ($orderSplitInfos as $splitInfo) {
$splitInfoList[] = [
@ -64,27 +53,30 @@ class PaymentService extends AbstractService
'sellerFlag' => $splitInfo['seller_flag'],
];
}
return $splitInfoList;
}
$baofu = new Baofu();
private function paymentSplit(Order $order, User $user, array $splitInfoList, string $token)
{
try {
$baofu = new Baofu();
$url = $baofu->paymentSplit([
'loginNo' => $user->member_id,
'outOrderNo' => $order->order_no,
'amount' => $user->member_id,
'paidType' => 'CARD',
'agreementNo' => $order->agreement_no,
'pwdPayExpTime' => $order->getExpiresIn(),
'pwdPayExpTime' => strtotime($order->expired_at),
'splitInfoList' => $splitInfoList,
'notifyUrl' => '',
], $token);
$order->status = 'APPLY_SUCCESS';
$order->applied_at = date('Y-m-d H:i:s');
$order->pay_url = $url;
return $url;
} catch (BasicException $e) {
} catch (ApiException $e) {
$order->status = 'APPLY_FAILED';
$order->applied_at = date('Y-m-d H:i:s');
$order->error_code = $e->getCode();
$order->error_code = $e->getErrorCode();
$order->error_message = $e->getMessage();
$order->save();
throw $e;
@ -108,6 +100,7 @@ class PaymentService extends AbstractService
$order->pay_method = 'paymentSplit';
$order->pay_type = 'CARD';
$order->expired_at = date('Y-m-d H:i:s', $expiresIn);
$order->org_split_info_list = $params['splitInfoList'];
$order->save();
$fee = floor($order->amount * 0.007);
@ -171,382 +164,87 @@ class PaymentService extends AbstractService
return $order;
}
public function handlePayResult(Result $result, Order $order) {
if ($result->get('payState') === '00') {
$order->status = Order::STATUS_PAYED;
$order->fee = $result->get('procedureFee', 0);
$order->pay_order_no = $result->get('transactionNo', '');
$order->channel_order_no = $result->get('channelOrder', '');
$order->payed_at = date('Y-m-d H:i:s');
$order->save();
} elseif ($result->get('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();
}
}
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();
}
}
public function protocolPayPreRequest($params)
{
$req = new ProtocolPayPreRequest($params);
$app = $req->getApp();
$data = $req->getData();
if ($data['payAmount'] > 300000) {
throw new BusinessException('超出限额');
public function refundApply(array $data, App $app) {
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if ($user) {
throw new BusinessException('用户已存在');
}
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first();
if ($order) {
throw new BusinessException('订单重复');
}
$data['outTradeNo'] = StringHelper::generateOrderNo();
$result = Api::protocolPayPre($data);
$user = User::where('app_id', $app->app_id)->where('out_member_id', $data['outMemberId'])->first();
if (!$user) {
Log::error('UserUndefiend: ', $data);
throw new BusinessException('用户不存在');
}
$order = $this->createOrder($app, $data, $user);
if (!$result->isSuccess()) {
$order->status = Order::STATUS_APPLY_FAIL;
$order->save();
throw new BusinessException($result->getMessage());
if (empty($order)) {
throw new BusinessException('订单号不存在');
}
if ($order->status != 'FINISH') {
throw new BusinessException('该订单状态不能发起退款');
}
$refund = Refund::where('app_id', $app->app_id)->where('refund_no', $data['refundNo'])->first();
if ($refund) {
throw new BusinessException('该退款单已经存在');
}
$refund = new Refund();
$refund->app_id = $app->app_id;
$refund->user_id = $user->user_id;
$refund->member_id = $user->member_id;
$refund->order_no = $order->order_no;
$refund->out_order_no = $order->out_order_no;
$refund->refund_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_REFUND);
$refund->refund_amount = $data['refundAmount'];
$refund->refund_reason = $data['refundReason'];
$refund->org_refund_split_info_list = $data['refundSplitInfoList'];
$refund->remark = $data['remark'] ?: '';
$refund->applied_at = date('Y-m-d H:i:s');
$refundSplitInfoList = [];
$refundSplitInfos = [];
foreach ($order->order_split_infos as $splitInfo) {
$refundSplitInfoList[] = [
'orgSubOutOrderNo' => $splitInfo->sub_order_no,
'refundAmount' => $splitInfo->split_amount,
];
$refundSplitInfos[$splitInfo->sub_order_no] = [
'app_id' => $splitInfo->user_id,
'user_id' => $splitInfo->user_id,
'member_id' => $splitInfo->member_id,
'user_id' => $splitInfo->user_id,
'split_member_id' => $splitInfo->split_member_id,
'split_user_id' => $splitInfo->split_user_id,
'order_no' => $splitInfo->order_no,
'out_order_no' => $splitInfo->out_order_no,
'sub_order_no' => $splitInfo->sub_order_no,
'sub_out_order_no' => $splitInfo->sub_out_order_no,
'refund_amount' => $splitInfo->split_amount,
'status' => 'P',
'message' => '',
];
}
if (is_null($result->get('payResult'))) {
$order->token = $result->get('token', '');
$order->protocol = $result->get('protocol', '');
$order->status = Order::STATUS_WAIT_PAY;
$order->save();
} else {
$bankCard = BankCard::where('app_id', $app->app_id)
->where('out_member_id', $data['outMemberId'])
->where('sms_no', $data['smsNo'])
->where('status', BankCard::STATUS_WAIT_CONFIRM)
->first();
if ($bankCard) {
$bankCard->status = BankCard::STATUS_ACTIVE;
$bankCard->protocol = $result->get('protocol', '');
$bankCard->save();
try {
$baofu = new Baofu();
$result = $baofu->profitShareRefundApply([
'loginNo' => $user->member_id,
'refundTradeId' => $refund->refund_no,
'refundTradeType' => 'REFUND_APPLY',
'orgTradeId' => $refund->order_no,
'refundAmount' => $refund->refund_amount,
'refundReason' => $refund->refund_reason,
'refundSplitInfoList' => $refundSplitInfoList,
]);
$refund->status = 'F';
$refund->real_refund_amount = $result['refundAmount'];
foreach ($result['refundSplitResultList'] as $refundSplitResult) {
$subOrderNo = $refundSplitResult['orgSubOutOrderNo'];
$refundSplitResult[$subOrderNo]['status'] = $refundSplitResult['status'];
$refundSplitResult[$subOrderNo]['message'] = $refundSplitResult['message'];
}
$order->protocol = $result->get('protocol', '');
$order->status = Order::STATUS_WAIT_PAY;
$order->save();
}
return $result->getData();
}
public function protocolPayConfirm($params)
{
$req = new ProtocolPayConfirmRequest($params);
$app = $req->getApp();
$data = $req->getData();
$order = Order::where('app_id', $app->app_id)
->where('token', $data['token'])
->where('protocol', $data['protocol'])
->first();
if (!$order) {
throw new BusinessException('订单不存在');
}
$result = Api::protocolPayConfirm($req->getData());
if (!$result->isSuccess()) {
$order->status = Order::STATUS_FAILED;
$order->error_code = $result->getCode();
$order->error_msg = $result->getMessage();
$order->payed_at = date('Y-m-d H:i:s');
$order->save();
throw new BusinessException($result->getMessage());
}
// 00 01 03
$this->handlePayResult($result, $order);
return $result->getData();
}
public function bindCard($params) {
$req = new BindCardRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
$memberId = $this->generateMemberIdNew($app->app_id, $reqData['outMemberId']);
$reqData['memberId'] = $memberId;
$bankCard = BankCard::where('app_id', $app->app_id)
->where('out_member_id', $reqData['outMemberId'])
->where('bank_card_no', $reqData['bankCardNo'])
->where('status', BankCard::STATUS_ACTIVE)
->first();
if ($bankCard) {
throw new BusinessException('该卡已绑定');
}
$result = Api::bindCard($reqData);
if (!$result->isSuccess()) {
$message = $result->getMessage();
throw new BusinessException($message == '支付渠道未配置' ? '暂不支持该银行卡' : $message);
}
$user = User::where('out_member_id', $reqData['outMemberId'])->where('app_id', $app->app_id)->first();
if (!$user) {
$user = new User();
$user->member_id = $memberId;
$user->out_member_id = $reqData['outMemberId'];
$user->app_id = $app->app_id;
$user->real_name = $reqData['userName'];
$user->card_no = $reqData['certificatesNo'];
$user->mobile = $reqData['phoneNum'];
$user->save();
}
if ($user && empty($user->out_member_id)) {
$user->out_member_id = $reqData['outMemberId'];
$user->save();
} catch (BasicException $e) {
$refund->status = 'A';
$refund->error_code = $e->getCode();
$refund->error_message = $e->getMessage();
throw $e;
}
$bankCard = new BankCard();
$bankCard->member_id = $memberId;
$bankCard->out_member_id = $reqData['outMemberId'];
$bankCard->app_id = $app->app_id;
$bankCard->real_name = $reqData['userName'];
$bankCard->card_no = $reqData['certificatesNo'];
$bankCard->mobile = $reqData['phoneNum'];
$bankCard->sms_no = $result->get('smsNo', '');
$bankCard->bank_card_no = $reqData['bankCardNo'];
$bankCard->bank_card_type = $reqData['bankCardType'];
$bankCard->protocol = $result->get('protocol', '');
$bankCard->expired = $reqData['expired'] ?? '';
$bankCard->cvn = $reqData['cvn'] ?? '';
$bankCard->status = BankCard::STATUS_WAIT_CONFIRM;
$bankCard->save();
return array_merge($result->getData(), ['memberId' => $memberId]);
}
public function bindCardConfirm($params)
{
$req = new BindCardConfirmRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
$bankCard = BankCard::where('app_id', $app->app_id)
->where('out_member_id', $reqData['outMemberId'])
->where('sms_no', $reqData['smsNo'])
->where('status', BankCard::STATUS_WAIT_CONFIRM)
->first();
if (!$bankCard) {
throw new BusinessException('绑卡申请不存在');
}
$refund->save();
$reqData['memberId'] = $bankCard->member_id;
$result = Api::bindCardConfirm($reqData);
if (!$result->isSuccess()) {
throw new BusinessException($result->getMessage());
}
$bankCard->status = BankCard::STATUS_ACTIVE;
$bankCard->protocol = $result->get('protocol', '');
$bankCard->save();
return $result->getData();
}
public function refundQuery($params)
{
$req = new RefundQueryRequest($params);
$data = $req->getData();
$result = Api::refundQuery($data);
if (!$result->isSuccess()) {
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->handleRefundResult($result, $order);
}
return $result->getData([
'outRefundNo',
'transactionNo',
'amount',
'refundAmount',
'refundState'
]);
}
public function paymentQuery($params)
{
$req = new PaymentQueryRequest($params);
$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->handlePayResult($result, $order);
}
return $result->getData([
'outTradeNo',
'transactionNo',
'payState',
'procedureFee',
'amount'
]);
}
public function unbindCard($params)
{
$req = new UnBindCardRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
$bankCard = BankCard::where('app_id', $app->app_id)
->where('out_member_id', $reqData['outMemberId'])
->where('protocol', $reqData['protocol'])
->where('status', BankCard::STATUS_ACTIVE)
->first();
if (!$bankCard) {
throw new BusinessException('绑卡不存在');
}
$result = Api::unBindCard($reqData);
if (!$result->isSuccess()) {
throw new BusinessException($result->getMessage());
}
$bankCard->status = BankCard::STATUS_UNBIND;
$bankCard->save();
return $result->getData();
}
public function refund($params)
{
$req = new RefundRequest($params);
$app = $req->getApp();
$data = $req->getData();
$refundOrder = new RefundOrder();
$refundOrder->app_id = $app->app_id;
$refundOrder->out_order_no = $data['outTradeNo'] ?: '';
$refundOrder->out_refund_order_no = $data['outRefundNo'] ?: '';
$refundOrder->order_amount = $data['amount'] ?: '';
$refundOrder->refund_amount = $data['refundAmount'] ?: '';
$refundOrder->remark = $data['remark'] ?: '';
$refundOrder->notify_url = $data['notifyUrl'] ?: '';
$result = Api::refund($data);
if (!$result->isSuccess()) {
$refundOrder->status = RefundOrder::STATUS_APPLY_FAILED;
$refundOrder->error_code = $result->getCode();
$refundOrder->error_msg = $result->getMessage();
$refundOrder->save();
throw new BusinessException($result->getMessage());
}
$refundOrder->status = RefundOrder::STATUS_APPLY_SUCCESS;
$refundOrder->save();
return $result->getData();
}
public function payment($params)
{
$req = new PaymentRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
if (!$reqData['outOrderNo']) {
throw new BusinessException('订单号错误');
}
if (!$reqData['outMemberId']) {
throw new BusinessException('用户ID不能为空');
}
if (isset($reqData['amount'])) {
if (!is_numeric($reqData['amount'])) {
throw new BusinessException('请输入金额');
}
if ($reqData['amount'] < 100 || $reqData['amount'] > 300000) {
Log::error('reqData:', $reqData);
throw new BusinessException('充值金额必须为100~300000');
}
}
if (!$reqData['notifyUrl']) {
throw new BusinessException('通知地址不能为空');
}
$log = PrePayLog::where('app_id', $app->app_id)->where('out_order_no', $reqData['outOrderNo'])->first();
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $reqData['outOrderNo'])->first();
if ($log || $order) {
throw new BusinessException('订单重复');
}
$token = md5(microtime(true) . json_encode($reqData) . $app->app_id . $app->app_key);
$log = new PrePayLog();
$log->app_id = $app->app_id;
$log->out_order_no = $reqData['outOrderNo'];
$log->amount = $reqData['amount'] ?: 0;
$log->out_member_id = $reqData['outMemberId'];
$log->notify_url = $reqData['notifyUrl'];
$log->redirect_url = $reqData['redirectUrl'] ?? '';
$log->token = $token;
$log->save();
return ['payUrl' => env('WEB_HOST') . '/payment.html?token=' . $token];
}
public function query($params)
{
$req = new PaymentQueryRequest($params);
$data = $req->getData();
$app = $req->getApp();
if (empty($data['outOrderNo'])) {
throw new BusinessException('订单号不能为空');
}
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first();
if (!$order) {
throw new BusinessException('订单不存在');
}
$result = Api::paymentQuery(['outTradeNo' => $order->order_no]);
if (!$result->isSuccess()) {
throw new BusinessException($result->getMessage());
}
$this->handlePayResult($result, $order);
return [
'outOrderNo' => $data['outOrderNo'],
'orderNo' => $order->order_no,
'payState' => $result->get('payState'),
'amount' => $result->get('amount'),
];
}
}

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Service;
use App\Helper\StringHelper;
use App\Model\RequestLog;
class RequestService extends AbstractService
@ -12,4 +13,17 @@ class RequestService extends AbstractService
{
return RequestLog::where('request_token', $token)->first();
}
public function createRequestLog($requestUri, $params): RequestLog
{
$requestLog = new RequestLog();
$requestLog->app_id = $params['app_id'] ?? 0;
$requestLog->request_id = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_REQUEST_ID);
$requestLog->request_token = $requestLog->generateToken();
$requestLog->request_uri = $requestUri;
$requestLog->request_data = json_encode($params, JSON_UNESCAPED_UNICODE);
$requestLog->request_time = date('Y-m-d H:i:s');
$requestLog->save();
return $requestLog;
}
}

@ -6,26 +6,35 @@ namespace App\Service;
use App\Exception\BusinessException;
use App\Helper\Baofu\Baofu;
use App\Model\App;
use App\Model\BankCard;
use App\Model\RequestLog;
use App\Model\User;
use App\Request\BindCardRequest;
use App\Request\RegisterRequest;
use App\Request\UnBindCardRequest;
class UserService extends AbstractService
{
public function register($params, $token) {
$req = new RegisterRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
public function companyRegister(array $data, App $app, string $token)
{
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if ($user) {
throw new BusinessException('用户已存在');
}
$emial = $data['email'];
$memberId = $this->generateMemberId($app->app_id, $data['userId']);
$baofu = new Baofu();
$url = $baofu->apply($memberId, $emial, $token);
return $url;
}
$user = User::where('app_id', $app->app_id)->where('user_id', $reqData['userId'])->first();
public function register(array $data, App $app, string $token)
{
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if ($user) {
throw new BusinessException('用户已存在');
}
$memberId = $this->generateMemberId($app->app_id, $reqData['userId']);
$memberId = $this->generateMemberId($app->app_id, $data['userId']);
$baofu = new Baofu();
$url = $baofu->register($memberId, $token);
@ -39,34 +48,36 @@ class UserService extends AbstractService
}
public function saveUser($userInfo, $appId, $userId) {
$user = User::where('app_id', $appId)->where('member_id', $userInfo['loginNo'])->first();
$memberId = $userInfo['loginNo'] ?? $userInfo['loginMobile'];
$user = User::where('app_id', $appId)->where('member_id', $memberId)->first();
if ($user) {
$user->contract_no = $userInfo['contractNo'];
$user->realname_flag = $userInfo['realNameFlag'] ?: 'Y';
$user->realname_flag = $userInfo['realNameFlag'] ?? 'Y';
$user->bind_card_flag = $userInfo['bindCardFlag'];
$user->set_pwd_flag = $userInfo['setPwdFlag'];
$user->status = $userInfo['operatorStatus'] ?: $userInfo['status'];
$user->email = $userInfo['email'] ?: '';
$user->mobile = $userInfo['mobile'] ?: '';
$user->real_name = $userInfo['customerName'] ?: '';
$user->certificate_no = $userInfo['certificateNo'] ?: '';
$user->status = $userInfo['operatorStatus'] ?? $userInfo['status'];
$user->email = $userInfo['email'] ?? '';
$user->mobile = $userInfo['mobile'] ?? '';
$user->real_name = $userInfo['customerName'] ?? '';
$user->certificate_no = $userInfo['certificateNo'] ?? '';
$user->user_type = $userInfo['customerType'];
$user->apply_no = $userInfo['applyNo'] ?: '';
$user->apply_no = $userInfo['applyNo'] ?? '';
} else {
$user = new User();
$user->user_id = $userId;
$user->member_id = $this->generateMemberId($appId , $userId);
$user->app_id = $appId;
$user->member_id = $memberId;
$user->contract_no = $userInfo['contractNo'];
$user->realname_flag = $userInfo['realNameFlag'] ?: 'Y';
$user->realname_flag = $userInfo['realNameFlag'] ?? 'Y';
$user->bind_card_flag = $userInfo['bindCardFlag'];
$user->set_pwd_flag = $userInfo['setPwdFlag'];
$user->status = $userInfo['operatorStatus'] ?: $userInfo['status'];
$user->email = $userInfo['email'] ?: '';
$user->mobile = $userInfo['mobile'] ?: '';
$user->real_name = $userInfo['customerName'] ?: '';
$user->certificate_no = $userInfo['certificateNo'] ?: '';
$user->email = $userInfo['email'] ?? '';
$user->mobile = $userInfo['mobile'] ?? '';
$user->real_name = $userInfo['customerName'] ?? '';
$user->certificate_no = $userInfo['certificateNo'] ?? '';
$user->user_type = $userInfo['customerType'];
$user->apply_no = $userInfo['applyNo'] ?: '';
$user->apply_no = $userInfo['applyNo'] ?? '';
}
$user->save();
return $user;
@ -74,20 +85,25 @@ class UserService extends AbstractService
public function rsyncBankCards($memberId) {
$user = User::where('member_id', $memberId)->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$baofu = new Baofu();
$bankCards = $baofu->findBindBankCards([
'loginNo' => $memberId,
'contractNo' => $user->contract_no,
]);
foreach ($bankCards as $bankCard) {
$this->saveBankCard($bankCard, $user->app_id, $user->user_id);
$this->saveBankCard($bankCard, $user);
}
}
public function saveBankCard($data, $appId, $userId) {
public function saveBankCard(array $data, User $user)
{
$appId = $user->app_id;
$userId = $user->user_id;
$bankCard = BankCard::where('app_id', $appId)
->where('member_id', $data['loginNo'])
->where('member_id', $user->member_id)
->where('agreement_no', $data['agreementNo'])
->first();
if ($bankCard) {
@ -107,8 +123,9 @@ class UserService extends AbstractService
$bankCard->remark = $data['remark'] ?: '';
} else {
$bankCard = new BankCard();
$bankCard->app_id = $appId;
$bankCard->user_id = $userId;
$bankCard->member_id = $this->generateMemberId($appId , $userId);
$bankCard->member_id = $user->member_id;
$bankCard->agreement_no = $data['agreementNo'];
$bankCard->card_user_name = $data['cardUserName'];
$bankCard->last_card_no = $data['lastCardNo'];
@ -132,12 +149,9 @@ class UserService extends AbstractService
return md5($appId . '-' . $userId);
}
public function bindCard($params, $token) {
$req = new BindCardRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
$user = User::where('app_id', $app->app_id)->where('user_id', $reqData['userId'])->first();
public function bindCard(array $data, App $app, string $token)
{
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
@ -147,22 +161,38 @@ class UserService extends AbstractService
return $url;
}
public function unbindCard($params) {
$req = new UnBindCardRequest($params);
$app = $req->getApp();
$reqData = $req->getData();
$user = User::where('app_id', $app->app_id)->where('user_id', $reqData['userId'])->first();
public function unbindCard(array $data, App $app) {
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$baofu = new Baofu();
$result = $baofu->cardUnbind($user->member_id, $reqData['agreementNo']);
$result = $baofu->cardUnbind($user->member_id, $data['agreementNo']);
if ($result && $result != 'false') {
$this->rsyncBankCards($user->member_id) ;
return true;
}
return false;
}
public function pwdForget(array $data, App $app, $token) {
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$baofu = new Baofu();
return $baofu->pwdForget($user->member_id, $token);
}
public function pwdModify(array $data, App $app, $token) {
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$baofu = new Baofu();
return $baofu->pwdModify($user->member_id, $token);
}
}

@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIICWTCCAcKgAwIBAgIGAWmff/EAMA0GCSqGSIb3DQEBDQUAMHAxHTAbBgNVBAMMFDEwMDAyNjEz
NkBAMjAwMDAxMjU5MREwDwYDVQQHDAhzaGFuZ2hhaTERMA8GA1UECAwIU2hhbmdIYWkxCzAJBgNV
BAYTAkNOMQswCQYDVQQKDAJiZjEPMA0GA1UECwwGYmFvZm9vMB4XDTE5MDMyMTA5MDU1NVoXDTI5
MDMzMTA5MDU1NVowcDEdMBsGA1UEAwwUMTAwMDI2MTM2QEAyMDAwMDEyNTkxETAPBgNVBAcMCHNo
YW5naGFpMREwDwYDVQQIDAhTaGFuZ0hhaTELMAkGA1UEBhMCQ04xCzAJBgNVBAoMAmJmMQ8wDQYD
VQQLDAZiYW9mb28wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMXgePGIUnUfOvK8YUaMfW6r
mDeG8TdP0ldFo/eIRU8iOamxYujcpd1OfY++xO42h4Pv0g7ZzIFOWc3NCkRTvWg02ycMd00uaDBo
w0d1W4XCKpV22JUo1fseHF8Jzpa59nXQ+sSmQjTsNjfbMcpek8GXeqlpDFX5AYHgt3FirbDVAgMB
AAEwDQYJKoZIhvcNAQENBQADgYEAvtayiw6G2GNSm2d6qQzQLm2Ra9OgjzlzSUuTMh4G3rxkfn/N
6a2wBcraay+TMrqaxzoy5HTemAL3qzGPe3O7btp2ZAFF/emiPGw9OtschLHUft2gaSvJAP704IWw
25k02n8r3MgdngbcY5tyaNTIQW4ViSkDhtWnqeI+Nna2aEk=
-----END CERTIFICATE-----

@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIENzCCAx+gAwIBAgIFFCiGWFEwDQYJKoZIhvcNAQEFBQAwITELMAkGA1UEBhMC
Q04xEjAQBgNVBAoTCUNGQ0EgT0NBMTAeFw0yMzA3MTExMDM4MDdaFw0yNjA3MTEx
MDM4MDdaMIGiMQswCQYDVQQGEwJDTjESMBAGA1UEChMJQ0ZDQSBPQ0ExMQ8wDQYD
VQQLEwZCYW9mb28xGTAXBgNVBAsTEE9yZ2FuaXphdGlvbmFsLTExUzBRBgNVBAMM
SkJhb2Zvb0DoibrlsI/lkKfvvIjmiJDpg73vvInkv6Hmga/np5HmioDmnInpmZDl
hazlj7hATjkxNTEwMTA2TUFDNE5DUkE0SkAxMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEA4ny/vlHs0B2dff/aK5U7mtCfC+1DAmutUyLUBCNK8rLnSaX6
8AdsZkR6Em5htqX2HyjSqs99KN5j5O9hNqYaXfKrNW7CMxWjUZZGK8oVRNiPKTpW
JekciUSOyggFxgdcefYNxAEZkH7OqaWJaJpK4lNWwqGHn5odYUG1du12Kf93RbCU
hBPbPi8IcrmsLkQUJ76J7zprF+2xsgTYziJQfZwU669+kF7xJ9PPofHP1eORJR59
kFfp2UgbRFc6b2Xtf5W7nQaV7R/t0E2QsRnfn8fn60X3jG4hLqzZWwQ3sCLgvWff
Bu6cSIHa34vmg4mEAuQZfIkUKvsPYLZVB6QF8QIDAQABo4HzMIHwMB8GA1UdIwQY
MBaAFNHb6YiC5d0aj0yqAIy+fPKrG/bZMEgGA1UdIARBMD8wPQYIYIEchu8qAQEw
MTAvBggrBgEFBQcCARYjaHR0cDovL3d3dy5jZmNhLmNvbS5jbi91cy91cy0xNC5o
dG0wOAYDVR0fBDEwLzAtoCugKYYnaHR0cDovL2NybC5jZmNhLmNvbS5jbi9SU0Ev
Y3JsMzM5MDQuY3JsMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQUqEBMA01hc2h5SpDC
1eDAQDXnWUYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMA0GCSqGSIb3
DQEBBQUAA4IBAQAPHhdetiaVZ9forWXSxi5vGlartW25g/4dP3HsnsKcMz7LugSb
9mBAGVVpSAqaij+xTQimY/x2SSLL4NIie9GDeHsdmoDijifC9S30q0ahWespEf0T
flaiKptUMa+FnK0w69dxESixkIRBEne1x9G42OMNDcA/KOHbRJIYRh/+s1j7Tfhf
POZRBzaagdChgk45TJTy5zXAdz2mJ8bXasTlDJkcaDwM+Qgo6GQxGIeKJGb9Ewgh
D/jbKQBcGe5JsspyZxGlnfd4+rRKK9/8otEONLPL/+Et87BWwPPILX9t6++1k1Fj
GInStTqT9LwJTLD54IXlp2YBZH1ATC8jSzkH
-----END CERTIFICATE-----

Binary file not shown.

@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDgDCCAmigAwIBAgIFEFmDdYIwDQYJKoZIhvcNAQEFBQAwITELMAkGA1UEBhMC
Q04xEjAQBgNVBAoTCUNGQ0EgT0NBMTAeFw0xNjEwMjQwNzIzMjRaFw0yMTEwMjQw
NzIzMjRaMHExCzAJBgNVBAYTAkNOMRIwEAYDVQQKEwlDRkNBIE9DQTExDzANBgNV
BAsTBkJhb2ZvbzEZMBcGA1UECxMQT3JnYW5pemF0aW9uYWwtMTEiMCAGA1UEAwwZ
QmFvZm9vQOWuneS7mEBaNjg4MTk5OTlAMTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
gYkCgYEA30bgCAY6agzuJccSKfLe/2NeOeUm2GZFuajai6CB9E0SOg6QymWuGw/f
XyL6rcZd/eavew1Ec2EDTeq4DgVudah6HZbI3EXt2TSxLpn6AwDMwKgSGhWpxR2V
1HnEiIyTOCjdWe5gUJl62UnE5acErjO0G9w+o+qGy13r0/ZZ6h0CAwEAAaOB8jCB
7zAfBgNVHSMEGDAWgBTR2+mIguXdGo9MqgCMvnzyqxv22TBIBgNVHSAEQTA/MD0G
CGCBHIbvKgEBMDEwLwYIKwYBBQUHAgEWI2h0dHA6Ly93d3cuY2ZjYS5jb20uY24v
dXMvdXMtMTQuaHRtMDcGA1UdHwQwMC4wLKAqoCiGJmh0dHA6Ly9jcmwuY2ZjYS5j
b20uY24vUlNBL2NybDQ0MDEuY3JsMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQURqt0
qRdCkRebpuVAmkiDlMQj95IwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwME
MA0GCSqGSIb3DQEBBQUAA4IBAQAHTgkQg47p4Fy5PCFcdGzX5LnHqyHK/cysjcpo
lHSj89/s/kX1pXU7Jqgp/FD1RJu/Ng6rmgHSNDR9ZHwapdc++PRSxDBN/+2BnR6J
4CoxHb0e7sjDddb7R1ceTuRXNjZuruV80j5HFycgrHSsSLI/LeZq1up0NLM+YOxt
/+zsnkAiGfLvRCVTlppwgfhpsT1LhdVvrDkYMedbgrA1zqL/kbXe0DIdb8kn2G8Q
7zR8SEYPXnWsDR2Ktno53mxKhx9kg3DQayWMudNY8qy+So0uBT1CqCsWR7SWoMpX
VSnKLXWBCRDqevVt4B2fpTHoo4uM4oZDggYaf14ky90d0lWH
-----END CERTIFICATE-----

@ -0,0 +1 @@
如果下载的内容为空,请联系宝付

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
// return [
// 'baseUrl' => 'https://account.baofoo.com',
// 'merchantNo' => '100026136',
// 'orgNo' => '100026136',
// 'terminalNo' => '200001259',
// 'privateKeyPassword' => '100026136_259652',
// 'simIDWx' => '',
// 'simIDAli' => '',
// 'channelId' => '',
// 'channelName' => '',
// 'pfxFilePath' => BASE_PATH . '/certs/dev/bfkey_100026136@@200001259.pfx',
// 'cerFilePath' => BASE_PATH . '/certs/dev/bfkey_100026136@@200001259.cer',
// ];
return [
'baseUrl' => 'https://bht.mandao.com',
'merchantNo' => '1274207',
'orgNo' => '1274207',
'terminalNo' => '82254',
'privateKeyPassword' => 'Ntp2Mx3MtqPZ',
'simIDWx' => '',
'simIDAli' => '',
'channelId' => '',
'channelName' => '',
'pfxFilePath' => BASE_PATH . '/certs/prod/baofu-xy.pfx',
'cerFilePath' => BASE_PATH . '/certs/prod/baofu.cer',
];

@ -4,11 +4,10 @@ declare(strict_types=1);
use App\Controller\Payment\NotifyController;
use App\Controller\Payment\PayController;
use App\Controller\Recharge\RechargeController;
use Hyperf\HttpServer\Router\Router;
Router::get('/favicon.ico', function () {
return 'sdfsd';
return 'abc';
});
Router::addGroup('/payment',function () {
@ -23,20 +22,11 @@ Router::addGroup('/payment',function () {
Router::post('/payment-query', [PayController::class, 'paymentQuery']);
Router::post('/query', [PayController::class, 'query']);
Router::post('/pay', [PayController::class, 'payment']);
}, ['middleware' => [\App\Middleware\RequestLogMiddleware::class]]);
Router::addGroup('/recharge',function () {
Router::post('/recharge', [RechargeController::class, 'recharge']);
Router::post('/confirm-bind-card', [RechargeController::class, 'confirmBindCard']);
Router::post('/confirm-bind-card-and-pay', [RechargeController::class, 'confirmBindCardAndPay']);
Router::post('/confirm-pay', [RechargeController::class, 'confirmPay']);
Router::post('/orders', [RechargeController::class, 'orders']);
Router::post('/login', [RechargeController::class, 'login']);
Router::post('/get-member-info', [RechargeController::class, 'getMemberInfo']);
});
}, ['middleware' => [\App\Middleware\RequestLogMiddleware::class, \App\Middleware\AppAuthMiddleWare::class]]);
Router::addGroup('/notify',function () {
Router::addRoute(['GET', 'POST'], '/payment', [NotifyController::class, 'payment']);
Router::addRoute(['GET', 'POST'], '/refund', [NotifyController::class, 'refund']);
Router::addRoute(['GET', 'POST'], '/refund', [NotifyController::class, 'refund']);
});

@ -1,3 +1,53 @@
CREATE TABLE `merchants` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`username` varchar(32) NOT NULL COMMENT '用户名',
`password` varchar(64) NOT NULL COMMENT '密码',
`email` varchar(32) NOT NULL DEFAULT '' COMMENT '用户邮箱',
`mobile` varchar(16) NOT NULL DEFAULT '' COMMENT '用户手机',
`register_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间',
`register_ip` varchar(15) NOT NULL DEFAULT '' COMMENT '注册IP',
`last_login_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后登录时间',
`last_login_ip` varchar(15) NOT NULL DEFAULT '' COMMENT '最后登录IP',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '用户状态',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `username` (`username`) USING BTREE
) ENGINE=InnoDB COMMENT='用户表';
CREATE TABLE `apps` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`app_id` varchar(16) NOT NULL COMMENT 'appId',
`app_key` varchar(32) NOT NULL COMMENT 'appKey',
`app_name` varchar(64) NOT NULL COMMENT '应用名称',
`merchant_id` int NOT NULL COMMENT '商户ID',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `udx_appid` (`app_id`) USING BTREE
) ENGINE=InnoDB COMMENT='应用表';
CREATE TABLE `request_logs` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`request_id` varchar(22) NOT NULL COMMENT '请求ID',
`app_id` varchar(16) NOT NULL COMMENT '应用ID',
`request_uri` varchar(255) NOT NULL COMMENT '请求URI',
`request_token` varchar(32) NOT NULL COMMENT 'Token',
`request_data` text COMMENT '请求内容',
`response_data` text COMMENT '响应内容',
`request_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`response_time` datetime DEFAULT NULL,
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '订单状态',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `udx_requestid` (`request_id`) USING BTREE,
UNIQUE KEY `udx_requesttoken` (`request_token`) USING BTREE,
KEY `idx_appid` (`app_id`) USING BTREE,
KEY `idx_createdat` (`created_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
CREATE TABLE `users` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`app_id` varchar(16) NOT NULL COMMENT '应用ID',
@ -19,7 +69,8 @@ CREATE TABLE `users` (
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_appid` (`app_id`) USING BTREE,
KEY `idx_memberid` (`member_id`) USING BTREE,
UNIQUE KEY `udx_memberid` (`member_id`) USING BTREE,
UNIQUE KEY `udx_userid_appid` (`user_id`, `app_id`) USING BTREE,
KEY `idx_createdat` (`created_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
@ -46,6 +97,7 @@ CREATE TABLE `bank_cards` (
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_appid` (`app_id`) USING BTREE,
UNIQUE KEY `udx_agreementno` (`agreement_no`) USING BTREE,
KEY `idx_memberid` (`member_id`) USING BTREE,
KEY `idx_createdat` (`created_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
@ -66,9 +118,10 @@ CREATE TABLE `orders` (
`applied_at` datetime DEFAULT NULL,
`notify_url` varchar(255) NOT NULL DEFAULT '',
`return_url` varchar(255) NOT NULL DEFAULT '',
`org_split_info_list` varchar(512) NOT NULL DEFAULT '',
`pay_url` varchar(255) NOT NULL DEFAULT '',
`status` varchar(16) NOT NULL DEFAULT '',
`error_code` varchar(20) NOT NULL DEFAULT '',
`error_code` varchar(64) NOT NULL DEFAULT '',
`error_message` varchar(120) NOT NULL DEFAULT '',
`finished_at` datetime DEFAULT NULL,
`third_order_no` varchar(32) NOT NULL DEFAULT '',
@ -113,14 +166,19 @@ CREATE TABLE `refunds` (
`user_id` varchar(32) NOT NULL,
`order_no` varchar(32) NOT NULL,
`out_order_no` varchar(32) NOT NULL,
`refund_order_no` varchar(32) NOT NULL,
`refund_out_order_no` varchar(32) NOT NULL,
`refund_no` varchar(32) NOT NULL,
`out_refund_no` varchar(32) NOT NULL,
`refund_amount` int(11) NOT NULL DEFAULT 0,
`refund_reason` varchar(255) NOT NULL DEFAULT '',
`refund_type` varchar(16) NOT NULL DEFAULT '',
`real_refund_amount` int(11) NOT NULL DEFAULT 0,
`remark` varchar(255) NOT NULL DEFAULT '',
`notify_url` varchar(255) NOT NULL DEFAULT '',
`org_refund_split_info_list` varchar(512) NOT NULL DEFAULT '',
`status` varchar(16) NOT NULL DEFAULT '',
`applied_at` datetime DEFAULT NULL,
`error_code` varchar(20) NOT NULL DEFAULT '',
`error_message` varchar(120) NOT NULL DEFAULT '',
`finished_at` datetime DEFAULT NULL,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -142,6 +200,8 @@ CREATE TABLE `refund_split_infos` (
`sub_order_no` varchar(32) NOT NULL,
`sub_out_order_no` varchar(32) NOT NULL,
`refund_amount` int(11) NOT NULL DEFAULT 0,
`status` varchar(16) NOT NULL DEFAULT '',
`message` varchar(32) NOT NULL DEFAULT '',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE,

Loading…
Cancel
Save