You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
payment/app/Command/MineCommand.php

260 lines
7.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Command;
use App\Helper\Efps\Api;
use App\Helper\Efps\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\Service\PaymentService;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ContainerInterface;
/**
* @Command
*/
class MineCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
protected $admin;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('mine');
}
public function configure(): void
{
parent::configure();
$this->setDescription('我的测试');
}
public function handle(): void
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$params = $this->pay();
$data = $paymentService->payment($params);
var_dump($data);
return;
return;
// $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();
// $this->confirmPay();
// $this->refund();
// $this->refundQuery();
// $this->paymentQuery();
$this->unbindCard();
return;
}
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);
}
public function comfirmBindCard()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'memberId' => 'ABC',
'smsNo' => 'QY888888888888888',
'smsCode' => '123456',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new BindCardRequest($params);
$params = $request->getData();
var_dump($params);
}
public function prepay($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;
}
public function confirmPay($token, $protocol, $smsCode)
{
$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;
}
public function refund()
{
$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);
}
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);
}
public function paymentQuery()
{
$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);
}
public function unbindCard()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'protocol' => 'p88888888888888888',
'memberId' => 'ABC',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new UnBindCardRequest($params);
$params = $request->getData();
var_dump($params);
}
public function pay()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outOrderNo' => time().rand(1000, 9999),
'outMemberId' => 'T001',
'amount' => 200,
'notifyUrl' => 'https://www.baidu.com',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
return $params;
}
}