efps-version
elf 1 year ago
parent e85fda2b90
commit 85fe14db3e

@ -4,13 +4,15 @@ declare(strict_types=1);
namespace App\Command;
use App\Helper\Efps\Api;
use App\Helper\StringHelper;
use App\Request\BindCardRequest;
use App\Request\PaymentQueryRequest;
use App\Request\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest;
use App\Request\RefundQueryRequest;
use App\Request\UnBindCardRequest;
use App\Service\PaymentService;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ContainerInterface;
@ -41,6 +43,24 @@ class MineCommand extends HyperfCommand
public function handle(): void
{
// $ret = Api::withdrawalToCard([]);
// var_dump($ret);
// return;
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$memberId = 'T01';
$protocol = 'p202305296288304915744';
// $result = $paymentService->protocolPayPreRequest($this->prepay($memberId, $protocol, 1));
// var_dump($result);
$token = 'de83e93fc3594dab8d5c8707fcbc8f5c';
$smsCode = '454925';
$result = $paymentService->protocolPayConfirm($this->confirmPay($token, $protocol, $smsCode));
var_dump($result);
return;
// $this->bindCard();
// $this->comfirmBindCard();
// $this->prepay();
@ -96,45 +116,39 @@ class MineCommand extends HyperfCommand
var_dump($params);
}
public function prepay()
public function prepay($memberId, $protocol, $amount)
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'memberId' => 'T01',
'memberId' => $memberId,
'outTradeNo' => time() . rand(1000, 9999),
'protocol' => 'p88888888888888888',
'payAmount' => 1,
'protocol' => $protocol,
'payAmount' => $amount,
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new ProtocolPayPreRequest($params);
$params = $request->getData();
var_dump($params);
return $params;
}
public function confirmPay()
public function confirmPay($token, $protocol, $smsCode)
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'token' => 's3skls8d3402skfj23',
'protocol' => 'p88888888888888888',
'smsCode' => '123456',
'token' => $token,
'protocol' => $protocol,
'smsCode' => $smsCode,
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new ProtocolPayConfirmRequest($params);
$params = $request->getData();
var_dump($params);
return $params;
}
public function refund()

@ -60,50 +60,14 @@ class PayController extends AbstractController
public function protocolPayPreRequest(RequestInterface $request)
{
$req = new ProtocolPayPreRequest($request->all());
$app = $req->getApp();
$data = $req->getData();
$result = Api::protocolPayPre($data);
$order = $this->paymentService->createOrder($app, $data);
if (!$result->isSuccess()) {
$order->status = Order::STATUS_APPLY_FAIL;
$order->save();
throw new BusinessException($result->getMessage());
}
$order->token = $result->get('token', '');
$order->protocol = $result->get('protocol', '');
$order->status = Order::STATUS_WAIT_PAY;
$order->save();
return $this->success($result->getData());
$data = $this->paymentService->protocolPayPreRequest($request->all());
return $this->success($data);
}
public function protocolPayConfirm(RequestInterface $request)
{
$req = new ProtocolPayConfirmRequest($request->all());
$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->paymentService->handlePayResult($result, $order);
return $this->success($result->getData());
$data = $this->paymentService->protocolPayConfirm($request->all());
return $this->success($data);
}
public function refund(RequestInterface $request) {

@ -7,50 +7,6 @@ use App\Helper\StringHelper;
class Api extends AbstractApi
{
public static function apply()
{
$paper = [
"certificateName" => "李四",
"contactPhone" => "13531231222",
"email" => "test1@test.cn",
"lawyerCertNo" => "430481198104234557",
"lawyerCertType" => "0",
"merchantType" => "3",
"openBank" => "中国银行",
"openingLicenseAccountPhoto" => "https://www.epaylinks.cn/www/wimages/epl_logo.png",
"settleAccount" => "李四",
"settleAccountNo" => "6214830201234567",
"settleAccountType" => "2",
"settleTarget" => "2"
];
$business = [
[
"businessCode" => "WITHDRAW_TO_SETTMENT_DEBIT",
"creditcardsEnabled" => 0,
"refundEnabled" => 1,
"refundFeePer" => 0,
"refundFeeRate" => 0,
"settleCycle" => "D+0",
"stage" => [
[
"amountFrom" => 0,
"feePer" => 50
]
]
]
];
$params = [
'acqSpId' => self::getConfig('customerCode'),
'merchantName' => "测试商户20211202",
'acceptOrder' => 0,
'openAccount' => 1,
'paper' => json_encode($paper, JSON_UNESCAPED_UNICODE),
'business' => $business
];
$sign = Signer::sign(json_encode($params));
return self::request($uri, $params, $sign);
}
public static function register($params)
{
$merId = $params['merId'] ?? '';
@ -175,6 +131,7 @@ class Api extends AbstractApi
'payAmount' => $payAmount,
'payCurrency' => 'CNY',
'isInstalments' => 0,
'isSendSmsCode' => 2,
'notifyUrl' => 'http://146.70.113.165:9501/notify/payment',
'transactionStartTime' => date('YmdHis'),
'nonceStr' => StringHelper::getRandomString(32),
@ -257,4 +214,27 @@ class Api extends AbstractApi
$sign = Signer::sign(json_encode($params));
return self::request($uri, $params, $sign);
}
public static function withdrawalToCard($params)
{
$bankUserName = $params['bankUserName'] ?? '';
$bankUserCert = $params['bankUserCert'] ?? '';
$bankCardNo = $params['bankCardNo'] ?? '';
$uri = '/api/txs/pay/withdrawalToCard';
$params = [
'version' => '3.0',
'customerCode' => self::getConfig('customerCode'),
'outTradeNo' => time() . rand(1000, 9999),
'bankName' => '工商银行',
'amount' => 1,
'bankUserName' => Signer::publicEncrypt('饶丽秀'),
'bankUserCert' => Signer::publicEncrypt('350824199001045864'),
'bankCardNo' => Signer::publicEncrypt('6212261402022689613'),
'bankAccountType' => 2,
'payCurrency' => 'CNY',
'nonceStr' => StringHelper::getRandomString(32),
];
$sign = Signer::sign(json_encode($params));
return self::request($uri, $params, $sign);
}
}

@ -4,12 +4,16 @@ declare(strict_types=1);
namespace App\Service;
use App\Exception\BusinessException;
use App\Helper\Efps\Api;
use App\Helper\Efps\Result;
use App\Helper\Redis;
use App\Helper\RedisKey;
use App\Model\App;
use App\Model\Order;
use App\Model\RefundOrder;
use App\Request\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest;
class PaymentService extends AbstractService
{
@ -65,4 +69,52 @@ class PaymentService extends AbstractService
$incrId = str_pad($incrId, $padLength, '0', STR_PAD_LEFT);
return date('YmdHis', $now) . $incrId;
}
public function protocolPayPreRequest($params)
{
$req = new ProtocolPayPreRequest($params);
$app = $req->getApp();
$data = $req->getData();
$result = Api::protocolPayPre($data);
$order = $this->createOrder($app, $data);
if (!$result->isSuccess()) {
$order->status = Order::STATUS_APPLY_FAIL;
$order->save();
throw new BusinessException($result->getMessage());
}
$order->token = $result->get('token', '');
$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();
}
}

Loading…
Cancel
Save