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.
332 lines
10 KiB
PHP
332 lines
10 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Command;
|
|
|
|
use App\Helper\Log;
|
|
use App\Helper\Platform\Notification;
|
|
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\RequestService;
|
|
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->getBalance();
|
|
return;
|
|
// $this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_register', $this->getApp(), ['userId' => '30684']);
|
|
$this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_bind_card', $this->getApp(), ['userId' => '23121', 'bindCardFlag' => true]);
|
|
return;
|
|
$this->rsyncUser('4673f922e30cfd2efeeb992ff6a32ece', '202308070000001', 'ELF1990');
|
|
$this->rsyncUser('247eda1b7de0c76603123c477f2072fa', '202308070000001', 'RLX1990');
|
|
$this->rsyncUser('13f366c46bb842b6cb732e6a30836a9b', '202308070000001', '30684');
|
|
}
|
|
|
|
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 = '202308070000001') {
|
|
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' => 'CWX1989'
|
|
]);
|
|
$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($memberId, $appId, $userId)
|
|
{
|
|
/**
|
|
* @var UserService $userService
|
|
*/
|
|
$userService = $this->container->make(UserService::class);
|
|
$userService->rsyncUser($memberId, $appId, $userId);
|
|
}
|
|
|
|
protected function rsyncBankCards() {
|
|
/**
|
|
* @var UserService $userService
|
|
*/
|
|
$userService = $this->container->make(UserService::class);
|
|
$userService->rsyncBankCards('4673f922e30cfd2efeeb992ff6a32ece');
|
|
}
|
|
|
|
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 unbindCard()
|
|
{
|
|
/**
|
|
* @var UserService $userService
|
|
*/
|
|
$userService = $this->container->make(UserService::class);
|
|
$result = $userService->unbindCard(['userId' => 'ELF1990', 'agreementNo' => '312023080400002047764'], $this->getApp());
|
|
var_dump($result);
|
|
}
|
|
|
|
protected function payment()
|
|
{
|
|
/**
|
|
* @var PaymentService $paymentService
|
|
*/
|
|
$paymentService = $this->container->make(PaymentService::class);
|
|
$data = [
|
|
'userId' => 'ELF1990',
|
|
'agreementNo' => '312023081200002052866',
|
|
'notifyUrl' => 'http://www.baidu.com',
|
|
'returnUrl' => 'http://www.baidu.com',
|
|
'amount' => 100,
|
|
'outOrderNo' => time() . rand(1000, 9999),
|
|
'splitInfoList' => [
|
|
[
|
|
'splitUserId' => '1427419924@qq.com',
|
|
'sellerFlag' => 1,
|
|
'splitAmount' => 100,
|
|
'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);
|
|
}
|
|
|
|
public function getRequestLog()
|
|
{
|
|
/**
|
|
* @var RequestService $requestService
|
|
*/
|
|
$requestService = $this->container->make(RequestService::class);
|
|
$requestLog = $requestService->getRequestLogByToken('21a640fdfc8dad25ad44512b22da9324');
|
|
|
|
$userId = $requestLog->getDataValue('userId');
|
|
var_dump($userId);
|
|
}
|
|
|
|
public function getBalance()
|
|
{
|
|
/**
|
|
* @var UserService $userService
|
|
*/
|
|
$userService = $this->container->make(UserService::class);
|
|
$result = $userService->getBalance('4673f922e30cfd2efeeb992ff6a32ece');
|
|
echo 'ELF: ' . $result . PHP_EOL;
|
|
$result = $userService->getBalance('247eda1b7de0c76603123c477f2072fa');
|
|
echo 'RLX: ' . $result . PHP_EOL;
|
|
$result = $userService->getBalance('f27f7786068387029a126de736bb84b2');
|
|
echo 'WHQ: ' . $result . PHP_EOL;
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
protected function transferPay()
|
|
{
|
|
/**
|
|
* @var PaymentService $paymentService
|
|
*/
|
|
$paymentService = $this->container->make(PaymentService::class);
|
|
$data = [
|
|
'userId' => 'ELF1990',
|
|
'goodsName' => '测试商品',
|
|
'agreementNo' => '312023081200002052866',
|
|
'notifyUrl' => 'http://www.baidu.com',
|
|
'returnUrl' => 'http://www.baidu.com',
|
|
'amount' => 100,
|
|
'outOrderNo' => time() . rand(1000, 9999),
|
|
'validDate' => '2023-08-15',
|
|
'marketInfo' => [
|
|
'amount' => 0,
|
|
'remark' => 'test',
|
|
],
|
|
'splitInfoList' => [
|
|
[
|
|
'splitUserId' => 'RLX1990',
|
|
'sellerFlag' => 1,
|
|
'splitAmount' => 100,
|
|
'subOutOrderNo' => time() . rand(1000, 9999),
|
|
]
|
|
]
|
|
];
|
|
$result = $paymentService->transferPay($data, $this->getApp(), $this->getToken());
|
|
var_dump($result);
|
|
}
|
|
} |