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

197 lines
5.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Command;
use App\Helper\Platform\Signer;
use App\Helper\StringHelper;
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;
/**
* @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
{
$this->payment();
}
protected function generateToken() {
return md5('1-' . microtime());
}
protected function createMerchant() {
/**
* @var MerchantService $merchantService
*/
$merchantService = $this->container->make(MerchantService::class);
return $merchantService->createMerchant([
'username' => 'main',
'password' => StringHelper::getRandomString('10'),
'email' => '1427419924@qq.com',
'mobile' => '17788888525',
'ip' => '127.0.0.1'
]);
}
protected function createApp($merchant, $appName) {
/**
* @var AppService $appService
*/
$appService = $this->container->make(AppService::class);
return $appService->createApp($merchant, $appName);
}
protected function createRequestLog($uri, $params) {
/**
* @var RequestService $requestService
*/
$requestService = $this->container->make(RequestService::class);
return $requestService->createRequestLog('/', $params);
}
protected function getApp($appId = '202308040000002') {
return App::where('app_id', $appId)->first();
}
protected function getToken() {
return md5(microtime() . '-' . rand(1000, 9999) );
}
protected function getRequestData() {
$app = $this->getApp();
$data = json_encode([
'userId' => 'ELF1991'
]);
$params = [
'app_id' => $app->app_id,
'nonce_str' => StringHelper::getRandomString(16),
'timestamp' => time(),
'data' => $data,
];
$params['sign'] = Signer::sign($params, $app->app_key);
echo json_encode($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;
}
protected function companyRegister($userId = 'COMPANY1990')
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->companyRegister(['userId' => $userId, 'email' => '360197197@qq.com'], $this->getApp(), $this->getToken());
echo $url;
}
protected function rsyncUser()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$userService->rsyncUser('4673f922e30cfd2efeeb992ff6a32ece', '202308040000002', 'ELF1990');
}
protected function rsyncBankCards() {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$userService->rsyncBankCards('247eda1b7de0c76603123c477f2072fa');
}
protected function bindCard()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->bindCard(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
echo $url;
}
protected function payment()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
'userId' => 'RLX1990',
'agreementNo' => '312023080700002049466',
'notifyUrl' => 'http://www.baidu.com',
'returnUrl' => 'http://www.baidu.com',
'amount' => 10,
'outOrderNo' => time() . rand(1000, 9999),
'expiresIn' => 10*60,
'splitInfoList' => [
[
'userId' => 'ELF1990',
'sellerFlag' => 1,
'amount' => 10,
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
];
$result = $paymentService->payment($data, $this->getApp(), $this->getToken());
var_dump($result);
}
public function pwdForget()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->pwdForget(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
var_dump($result);
}
public function pwdModify()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->pwdModify(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
var_dump($result);
}
}