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

294 lines
8.8 KiB
PHTML

2 years ago
<?php
declare(strict_types=1);
namespace App\Command;
1 year ago
use App\Helper\Log;
1 year ago
use App\Helper\Platform\Notification;
1 year ago
use App\Helper\Platform\Signer;
1 year ago
use App\Helper\StringHelper;
1 year ago
use App\Model\App;
use App\Service\AppService;
use App\Service\MerchantService;
1 year ago
use App\Service\PaymentService;
1 year ago
use App\Service\RequestService;
1 year ago
use App\Service\UserService;
1 year ago
use Hyperf\Command\Annotation\Command;
2 years ago
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ContainerInterface;
/**
* @Command
*/
1 year ago
class MineCommand extends HyperfCommand
2 years ago
{
/**
* @var ContainerInterface
*/
protected $container;
protected $admin;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
1 year ago
parent::__construct('mine');
2 years ago
}
2 years ago
public function configure(): void
2 years ago
{
parent::configure();
1 year ago
$this->setDescription('我的测试');
2 years ago
}
2 years ago
public function handle(): void
2 years ago
{
1 year ago
$this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_register', $this->getApp(), ['userId' => '30684']);
1 year ago
return;
1 year ago
$this->rsyncUser('4673f922e30cfd2efeeb992ff6a32ece', '202308070000001', 'ELF1990');
$this->rsyncUser('247eda1b7de0c76603123c477f2072fa', '202308070000001', 'RLX1990');
$this->rsyncUser('13f366c46bb842b6cb732e6a30836a9b', '202308070000001', '30684');
1 year ago
}
protected function generateToken() {
return md5('1-' . microtime());
}
protected function createMerchant() {
1 year ago
/**
1 year ago
* @var MerchantService $merchantService
1 year ago
*/
1 year ago
$merchantService = $this->container->make(MerchantService::class);
return $merchantService->createMerchant([
'username' => 'main',
'password' => StringHelper::getRandomString('10'),
1 year ago
'email' => '1427419924@qq.com',
'mobile' => '17788888525',
1 year ago
'ip' => '127.0.0.1'
]);
}
1 year ago
1 year ago
protected function createApp($merchant, $appName) {
1 year ago
/**
1 year ago
* @var AppService $appService
1 year ago
*/
1 year ago
$appService = $this->container->make(AppService::class);
return $appService->createApp($merchant, $appName);
}
1 year ago
1 year ago
protected function createRequestLog($uri, $params) {
/**
* @var RequestService $requestService
*/
$requestService = $this->container->make(RequestService::class);
return $requestService->createRequestLog('/', $params);
}
1 year ago
1 year ago
protected function getApp($appId = '202308070000001') {
1 year ago
return App::where('app_id', $appId)->first();
2 years ago
}
1 year ago
1 year ago
protected function getToken() {
return md5(microtime() . '-' . rand(1000, 9999) );
1 year ago
}
1 year ago
protected function getRequestData() {
$app = $this->getApp();
$data = json_encode([
'userId' => 'ELF1991'
]);
1 year ago
$params = [
1 year ago
'app_id' => $app->app_id,
'nonce_str' => StringHelper::getRandomString(16),
1 year ago
'timestamp' => time(),
1 year ago
'data' => $data,
1 year ago
];
1 year ago
$params['sign'] = Signer::sign($params, $app->app_key);
echo json_encode($params);
1 year ago
}
1 year ago
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;
1 year ago
}
1 year ago
protected function companyRegister($userId = 'COMPANY1990')
1 year ago
{
1 year ago
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->companyRegister(['userId' => $userId, 'email' => '360197197@qq.com'], $this->getApp(), $this->getToken());
echo $url;
1 year ago
}
1 year ago
protected function rsyncUser($memberId, $appId, $userId)
1 year ago
{
1 year ago
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
1 year ago
$userService->rsyncUser($memberId, $appId, $userId);
1 year ago
}
1 year ago
1 year ago
protected function rsyncBankCards() {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
1 year ago
$userService->rsyncBankCards('4673f922e30cfd2efeeb992ff6a32ece');
1 year ago
}
1 year ago
protected function bindCard()
1 year ago
{
1 year ago
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->bindCard(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
echo $url;
1 year ago
}
1 year ago
1 year ago
protected function unbindCard()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->unbindCard(['userId' => 'ELF1990', 'agreementNo' => '312023080400002047764'], $this->getApp());
var_dump($result);
}
1 year ago
protected function payment()
1 year ago
{
1 year ago
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
1 year ago
'userId' => 'ELF1990',
1 year ago
'agreementNo' => '312023081200002052866',
1 year ago
'notifyUrl' => 'http://www.baidu.com',
'returnUrl' => 'http://www.baidu.com',
1 year ago
'amount' => 100,
1 year ago
'outOrderNo' => time() . rand(1000, 9999),
1 year ago
'expiresIn' => 10*60,
1 year ago
'splitInfoList' => [
[
1 year ago
'userId' => 'RLX1990',
1 year ago
'sellerFlag' => 1,
1 year ago
'amount' => 100,
1 year ago
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
1 year ago
];
1 year ago
$result = $paymentService->payment($data, $this->getApp(), $this->getToken());
var_dump($result);
1 year ago
}
1 year ago
1 year ago
public function pwdForget()
1 year ago
{
1 year ago
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->pwdForget(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
var_dump($result);
1 year ago
}
1 year ago
1 year ago
public function pwdModify()
1 year ago
{
1 year ago
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->pwdModify(['userId' => 'ELF1990'], $this->getApp(), $this->getToken());
var_dump($result);
1 year ago
}
1 year ago
public function getRequestLog()
{
/**
* @var RequestService $requestService
*/
$requestService = $this->container->make(RequestService::class);
$requestLog = $requestService->getRequestLogByToken('21a640fdfc8dad25ad44512b22da9324');
$userId = $requestLog->getDataValue('userId');
var_dump($userId);
}
1 year ago
public function getBalance()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->getBalance('1274207');
var_dump($result);
}
public function refund()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
'userId' => 'ELF1990',
'outOrderNo' => '16918297262208',
'notifyUrl' => 'http://www.baidu.com',
'returnUrl' => 'http://www.baidu.com',
'outRefundNo' => time() . rand(1000, 9999),
'refundAmount' => 100,
'refundReason' => '不想买了',
'refundSplitInfoList' => [
]
];
$result = $paymentService->refundApply($data, $this->getApp());
var_dump($result);
}
public function refundConfirm()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
'userId' => 'ELF1990',
'outOrderNo' => '16918297262208',
'outRefundNo' => '16919422375337',
'notifyUrl' => 'http://www.baidu.com',
'refundAmount' => 100,
];
$paymentService->refundConfirm($data, $this->getApp(), $this->getToken());
}
1 year ago
protected function notify($url, $app, $data)
{
if (empty($url)) {
return 'empty url';
}
$params = [
'app_id' => $app->app_id,
'nonce_str' => StringHelper::getRandomString(32),
'timestamp' => time(),
];
$params['data'] = json_encode($data);
$params['sign'] = Signer::sign($params, $app->app_key);
Log::info('notifyToOut params:', $params, 'platform');
Log::info('notifyToOut url:' . $url, [], 'platform');
$result = Notification::post($url, $params);
Log::info('notifyToOut response:' . $result, [], 'platform');
var_dump($result);
}
1 year ago
}