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

617 lines
22 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Command;
use App\Helper\Baofu\Baofu;
use App\Helper\Log;
use App\Helper\Platform\Notification;
use App\Helper\Platform\Signer;
use App\Helper\StringHelper;
use App\Model\App;
use App\Model\BankCard;
use App\Model\User;
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->withdraw();
$this->getBalance();
return;
$result = $baofu->applyBindCard($user->member_id, [
'cardNo' => '80094800000009440000053437',
'cardName' => '福建省万瑞天成企业管理服务有限公司',
'bankName' => '厦门国际银行',
'branchName' => '厦门国际银行股份有限公司',
'provinceName' => '福建省',
'cityName' => '福建省厦门市',
], 'xxxxxxxxxxxxxxxxxx');
var_dump($result);
return;
$this->querySignEntrust('ACT_5');
$this->getBalance();
return;
$this->rsyncUser('289a092602845b1a40793db5409333f5', '202308070000001', 'ACT_5');
$this->rsyncBankCards();
return;
$this->withdraw();
// $this->transferWithdrawNotify();
$this->getBalance();
return;
$this->querySignEntrust();
return;
$this->getBalance();
$this->getRequestData();
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 = [
'userId' => 'ELF1990',
'goodsName' => '测试商品',
'agreementNo' => '312023082200002060225',
'notifyUrl' => 'http://124.223.222.61:9501/notify/test-notify',
'returnUrl' => 'http://124.223.222.61:9501/notify/test-notify',
'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),
]
]
];
$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',
]
],
];
$data = [
'userId' => 'ELF1990',
'accountName' => '廖金灵',
'outApplyNo' => time() . rand(1000, 9999),
'amount' => '10',
'summary' => '测试',
'notifyUrl' => 'http://124.223.222.61:9501/notify/test-notify'
];
// $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',
// ];
// $data = [
// 'userId' => 'ELF1990',
// 'outApplyNo' => '16934203547527',
// ];
// $data = [
// 'type' => 'WITHDRAW',
// 'outOrderNo' => '16934198607215',
// ];
$data = [
'userId' => 'ELF1990',
'agreementNo' => '312023081500002054664',
'outOrderNo' => time() . rand(1000, 9999),
'amount' => 10,
'goodsName' => '测试商品',
'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',
// 'validDate' => '2023-09-30',
'splitInfoList' => [
[
'splitUserId' => 'RLX1990',
'sellerFlag' => 1,
'splitAmount' => 10,
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
];
$params = [
'app_id' => $app->app_id,
'nonce_str' => StringHelper::getRandomString(16),
'timestamp' => time(),
'data' => json_encode($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, 'MERCHANT');
}
protected function rsyncBankCards() {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$userService->rsyncBankCards('289a092602845b1a40793db5409333f5');
}
protected function bindCard()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->bindCard(['userId' => 'CWX1989'], $this->getApp(), $this->getToken());
echo $url;
}
protected function unbindCard()
{
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$result = $userService->unbindCard(['userId' => 'ELF1990', 'agreementNo' => '312023081200002052866'], $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;
$result = $userService->getBalance('f9c0bea79725d71cc7969571c345de54');
echo 'CWX: ' . $result . PHP_EOL;
$result = $userService->getBalance('289a092602845b1a40793db5409333f5');
echo 'WRTC: ' . $result . PHP_EOL;
$user = User::where('user_id', 'ACT_9')->first();
$result = $userService->getBalance($user->member_id);
echo 'NEW: ' . $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' => '312023082200002060225',
'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);
}
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);
}
public function queryOrder()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$data = [
'outOrderNo' => '16926878308874',
];
$order = $paymentService->queryOrder($data, $this->getApp());
var_dump($order->toArray());
}
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();
}
public function transferWithdraw() {
$baofu = new Baofu();
$data = [
'transContent' => [
[
'transNo' => time() . rand(1000, 9999),
'transMoney' => 0.1,
'transType' => 2,
'transAccNo' => '3177000500533754',
'transAccName' => '廖金灵',
'transSummary' => '测试',
// 'cardBankName' => '',
// 'cardProName' => '',
// 'cardCityName' => '',
// 'cardAccDept' => '',
// 'cardCnap' => '',
// 'transIdCard' => '',
// 'transMobile' => '',
]
]
];
$baofu->transferWithdraw($data);
}
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;
}
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;
}
protected function querySignEntrust($userId = 'ELF1990') {
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$url = $userService->querySignEntrust(['userId' => $userId], $this->getApp(), $this->getToken());
var_dump($url);
}
protected function transferWithdrawNotify()
{
$data = '{"member_id":"1274207","terminal_id":"82254","data_type":"json","data_content":"54902c7f11a5d1f151ee7a8f014dfa61fa35908dcbf9f763df0ac4ebde99a58208c5dd82b53b84b9387ba230accafa11540ddbed70bec1c18a3c9692338ab618e940553b77136ae08a168df767a2a4467cc20cc88ceac9676e83b6536a052df84aa24af87965f694699a569ad9f931c8f50c14bbd6b8f1a4eb8dbbe06f362a648e256a3fd4d558771f85148d62fb3099845571dbfbcdbb0e44b2b58316d25ef5cf17b02be2c1f509e592b0d32c7911a4b63974b0fc8f2b5ca216c905aeb9d81a95982fe00d1bf6e9e2251e58976dd54856b0001c1b6745532a0df5cd0a6cb72d686b43b1aa6dec349206592b5da833ed2f0d6f858661c3679e0cc7ca6fb15abdcab53548beb12ab46991efe02dcad6d27f80ef5f1523540db4a6076cc5bec6dce2ee4aa625d3e7fef47d6cd1345e660b78b078395e000ce23c8c8e8a6f921a9c0622e73e6ccb18b4143ecc7529a7d40ef707024282a40e4d49c4f1d237acf17e02cf255ad5fa033739f9fdf40e23f86ee0b79507fd7d2a02b602fbedf0579af63fc3115525b2b7c645cd81ed84e20dd866dec67446850fa65c16134a0a1c3f3b90d89564a6a794b21102c70a9e8e44f8929fdb19f6f59694bc359afe27fca758f8af272bb4ebd7e7ed49125d26608947b60330f46c4bd4b9e373967e59b6e353808b4a6fe62db53fc71312298df312b4695f79a22d3dc9f22f639bfad0a3f7dd"}';
$data = json_decode($data, true);
$baofu = new Baofu();
$content = $baofu->decryptUnionPayData($data['data_content']);
var_dump($content);
$result = json_decode($content, true);
var_dump($result);
}
protected function withdraw() {
$bankCard = BankCard::where('member_id', 'f27f7786068387029a126de736bb84b2')->first();
$baofu = new Baofu();
$result = $baofu->withdraw([
'amount' => intval(1089256),
'loginNo' => 'f27f7786068387029a126de736bb84b2',
'agreementNo' => $bankCard->agreement_no,
'outOrderNo' => time() . rand(1000, 9999),
], 'elf');
var_dump($result);
}
}