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

599 lines
21 KiB
PHTML

2 years ago
<?php
declare(strict_types=1);
namespace App\Command;
1 year ago
use App\Helper\Baofu\Baofu;
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;
1 year ago
use App\Model\BankCard;
use App\Model\User;
1 year ago
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
{
11 months ago
$this->getBalance();
return;
11 months ago
$this->rsyncUser('289a092602845b1a40793db5409333f5', '202308070000001', 'ACT_5');
11 months ago
$this->rsyncBankCards();
return;
1 year ago
$this->withdraw();
1 year ago
// $this->transferWithdrawNotify();
1 year ago
$this->getBalance();
return;
1 year ago
$this->querySignEntrust();
1 year ago
return;
1 year ago
$this->getBalance();
1 year ago
$this->getRequestData();
1 year ago
return;
1 year ago
// $this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_register', $this->getApp(), ['userId' => '30684']);
1 year ago
$this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_bind_card', $this->getApp(), ['userId' => '23121', 'bindCardFlag' => true]);
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();
1 year ago
$data = [
1 year ago
'userId' => 'ELF1990',
'goodsName' => '测试商品',
'agreementNo' => '312023082200002060225',
1 year ago
'notifyUrl' => 'http://124.223.222.61:9501/notify/test-notify',
'returnUrl' => 'http://124.223.222.61:9501/notify/test-notify',
1 year ago
'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),
]
]
1 year ago
];
1 year ago
$data = [
'userId' => 'ELF1990',
'oldOutOrderNo' => '16926878308874',
'outOrderNo' => time() . rand(1000, 9999),
'amount' => '100',
'notifyUrl' => 'http://124.223.222.61:9501/notify/test-notify',
'assureConfirmSplitInfoList' => [
[
'oldSubOutOrderNo' => '16926878304208',
'splitAmount' => '100',
]
],
];
1 year ago
$data = [
'userId' => 'ELF1990',
'accountName' => '廖金灵',
'outApplyNo' => time() . rand(1000, 9999),
1 year ago
'amount' => '10',
1 year ago
'summary' => '测试',
'notifyUrl' => 'http://124.223.222.61:9501/notify/test-notify'
];
1 year ago
// $data = [
// 'userId' => 'ELF1990',
// 'agreementNo' => '312023082200002060225',
// 'outWithdrawNo' => time() . rand(1000, 9999),
// 'amount' => '1',
// 'notifyUrl' => 'http://124.223.222.61:9501/notify/test-notify',
// 'returnUrl' => 'https://www.baidu.com',
// ];
1 year ago
// $data = [
// 'userId' => 'ELF1990',
// 'outApplyNo' => '16934203547527',
// ];
// $data = [
// 'type' => 'WITHDRAW',
// 'outOrderNo' => '16934198607215',
// ];
1 year ago
$data = [
'userId' => 'ELF1990',
'agreementNo' => '312023081500002054664',
'outOrderNo' => time() . rand(1000, 9999),
1 year ago
'amount' => 10,
1 year ago
'goodsName' => '测试商品',
1 year ago
'payMethod' => 'unionPay',
'payType' => 'ALIPAY_ALXCX',
'notifyUrl' => 'http://124.223.222.61:9501/notify/test-notify',
'returnUrl' => 'http://124.223.222.61:9501/notify/test-notify',
'channelId' => '20880055945509133097978700117397',
'appId' => '2021004111671035',
1 year ago
// 'validDate' => '2023-09-30',
1 year ago
'splitInfoList' => [
[
'splitUserId' => 'RLX1990',
'sellerFlag' => 1,
1 year ago
'splitAmount' => 10,
1 year ago
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
];
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' => json_encode($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);
11 months ago
$userService->rsyncUser($memberId, $appId, $userId, 'MERCHANT');
1 year ago
}
1 year ago
1 year ago
protected function rsyncBankCards() {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
11 months ago
$userService->rsyncBankCards('289a092602845b1a40793db5409333f5');
1 year ago
}
1 year ago
protected function bindCard()
1 year ago
{
1 year ago
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
1 year ago
$url = $userService->bindCard(['userId' => 'CWX1989'], $this->getApp(), $this->getToken());
1 year ago
echo $url;
1 year ago
}
1 year ago
1 year ago
protected function unbindCard()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
1 year ago
$result = $userService->unbindCard(['userId' => 'ELF1990', 'agreementNo' => '312023081200002052866'], $this->getApp());
1 year ago
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),
'splitInfoList' => [
[
1 year ago
'splitUserId' => '1427419924@qq.com',
1 year ago
'sellerFlag' => 1,
1 year ago
'splitAmount' => 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);
1 year ago
$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;
11 months ago
$result = $userService->getBalance('f9c0bea79725d71cc7969571c345de54');
echo 'CWX: ' . $result . PHP_EOL;
$result = $userService->getBalance('289a092602845b1a40793db5409333f5');
echo 'WRTC: ' . $result . PHP_EOL;
1 year ago
}
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
protected function transferPay()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
'userId' => 'ELF1990',
'goodsName' => '测试商品',
1 year ago
'agreementNo' => '312023082200002060225',
1 year ago
'notifyUrl' => 'http://www.baidu.com',
'returnUrl' => 'http://www.baidu.com',
'amount' => 100,
'outOrderNo' => time() . rand(1000, 9999),
'validDate' => '2023-08-15',
'marketInfo' => [
1 year ago
'amount' => 0,
1 year ago
'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);
}
1 year ago
protected function unionPay()
{
/**
* @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',
'payMethod' => 'unionPay',
'payType' => 'ALIPAY_NATIVE',
'splitInfoList' => [
[
'splitUserId' => 'RLX1990',
'sellerFlag' => 1,
'splitAmount' => 100,
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
];
$result = $paymentService->payment($data, $this->getApp(), $this->getToken());
var_dump($result);
}
1 year ago
public function queryOrder()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
1 year ago
'outOrderNo' => '16926878308874',
1 year ago
];
$order = $paymentService->queryOrder($data, $this->getApp());
var_dump($order->toArray());
}
1 year ago
public function paymentNotify() {
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
/**
* @var RequestService $requestService
*/
$requestService = $this->container->make(RequestService::class);
$params = json_decode('{"orgNo":"1274207","merchantNo":"1274207","terminalNo":"82254","orderStatus":"FINISH","tradeId":"2023082115523700001","paidType":"","orderMoney":"100","loginId":"1f32d22ff571ebc692bd50785c883ca8","finishTime":"20230821155509","orderId":"23082100711351457","errorMsg":"成功","signature":"c369c2670607f4e840d7a9644e854da9b1858aa9df1c465fa893b8a9610bde561704fe8f63af41cb1528f601a6fafcbb42ec7fa4838cdc76dc86593ae0c60ae15bae227e60a82ce376a4a7c137047f3db0bb366c21e484458abed0bb9135b653948f90b7d0b4c89d29e0b1939915c80d49c6e6cc0549a1eb84fb2c14704d81fd"}', true);
$token = 'f49e9fc5bf6f4768fb47a5721ede7d47';
$baofu = new Baofu();
if (!$baofu->notifyVerify($params, 'payment')) {
Log::info('paymentNotifyVerifyFail: ', $params);
return $baofu->notifySuccess();
}
$requestLog = $requestService->getRequestLogByToken($token);
$info = [
'member_id' => $params['loginId'],
'order_no' => $params['tradeId'],
'third_order_no' => $params['orderId'],
'status' => $params['orderStatus'],
'amount' => $params['orderMoney'],
'finished_at' => $params['finishTime'],
'error_message' => $params['errorMsg'],
'transaction_id' => $params['transactionId'] ?? '',
'out_transaction_id' => $params['outTransactionId'] ?? '',
];
$order = $paymentService->updateOrder($info, ['APPLY_SUCCESS', 'PROCESS', 'CONFIRM_SUCCESS']);
if (empty($order)) {
return $baofu->notifySuccess();
}
$result = $this->notify(
$requestLog->getDataValue('notifyUrl'),
$requestLog->app,
[
'amount' => $order->amount,
'status' => $order->status,
'userId' => $order->user_id,
'orderNo' => $order->order_no,
'outOrderNo' => $order->out_order_no,
'finishTime' => $order->finished_at,
]
);
$baofu->notifySuccess();
}
1 year ago
public function transferWithdraw() {
$baofu = new Baofu();
$data = [
'transContent' => [
[
'transNo' => time() . rand(1000, 9999),
'transMoney' => 0.1,
'transType' => 2,
1 year ago
'transAccNo' => '3177000500533754',
'transAccName' => '廖金灵',
1 year ago
'transSummary' => '测试',
// 'cardBankName' => '',
// 'cardProName' => '',
// 'cardCityName' => '',
// 'cardAccDept' => '',
// 'cardCnap' => '',
// 'transIdCard' => '',
// 'transMobile' => '',
]
]
];
$baofu->transferWithdraw($data);
}
1 year ago
protected function unbindWithdrawEntrust($userId = 'ELF1990') {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->unbindWithdrawEntrust(['userId' => $userId], $this->getApp(), $this->getToken());
echo $url;
}
1 year ago
protected function signWithdrawEntrust($userId = 'ELF1990') {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->signWithdrawEntrust(['userId' => $userId], $this->getApp(), $this->getToken());
echo $url;
}
1 year ago
protected function querySignEntrust($userId = 'ELF1990') {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->querySignEntrust(['userId' => $userId], $this->getApp(), $this->getToken());
echo $url;
}
1 year ago
protected function transferWithdrawNotify()
{
$data = '{"member_id":"1274207","terminal_id":"82254","data_type":"json","data_content":"54902c7f11a5d1f151ee7a8f014dfa61fa35908dcbf9f763df0ac4ebde99a58208c5dd82b53b84b9387ba230accafa11540ddbed70bec1c18a3c9692338ab618e940553b77136ae08a168df767a2a4467cc20cc88ceac9676e83b6536a052df84aa24af87965f694699a569ad9f931c8f50c14bbd6b8f1a4eb8dbbe06f362a648e256a3fd4d558771f85148d62fb3099845571dbfbcdbb0e44b2b58316d25ef5cf17b02be2c1f509e592b0d32c7911a4b63974b0fc8f2b5ca216c905aeb9d81a95982fe00d1bf6e9e2251e58976dd54856b0001c1b6745532a0df5cd0a6cb72d686b43b1aa6dec349206592b5da833ed2f0d6f858661c3679e0cc7ca6fb15abdcab53548beb12ab46991efe02dcad6d27f80ef5f1523540db4a6076cc5bec6dce2ee4aa625d3e7fef47d6cd1345e660b78b078395e000ce23c8c8e8a6f921a9c0622e73e6ccb18b4143ecc7529a7d40ef707024282a40e4d49c4f1d237acf17e02cf255ad5fa033739f9fdf40e23f86ee0b79507fd7d2a02b602fbedf0579af63fc3115525b2b7c645cd81ed84e20dd866dec67446850fa65c16134a0a1c3f3b90d89564a6a794b21102c70a9e8e44f8929fdb19f6f59694bc359afe27fca758f8af272bb4ebd7e7ed49125d26608947b60330f46c4bd4b9e373967e59b6e353808b4a6fe62db53fc71312298df312b4695f79a22d3dc9f22f639bfad0a3f7dd"}';
1 year ago
$data = json_decode($data, true);
1 year ago
$baofu = new Baofu();
$content = $baofu->decryptUnionPayData($data['data_content']);
var_dump($content);
$result = json_decode($content, true);
var_dump($result);
}
1 year ago
protected function withdraw() {
$bankCard = BankCard::where('member_id', 'f27f7786068387029a126de736bb84b2')->first();
$baofu = new Baofu();
$result = $baofu->withdraw([
'amount' => intval(726687),
'loginNo' => 'f27f7786068387029a126de736bb84b2',
'agreementNo' => $bankCard->agreement_no,
'outOrderNo' => time() . rand(1000, 9999),
], 'elf');
var_dump($result);
}
1 year ago
}