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/Controller/Payment/NotifyController.php

113 lines
3.3 KiB
PHTML

2 years ago
<?php
declare(strict_types=1);
namespace App\Controller\Payment;
2 years ago
use App\Helper\Baofu\Baofu;
2 years ago
use App\Helper\Log;
use App\Helper\Platform\Notification;
2 years ago
use App\Helper\Platform\Signer as PlatformSigner;
use App\Helper\StringHelper;
2 years ago
use App\Service\PaymentService;
2 years ago
use App\Service\RequestService;
use App\Service\UserService;
2 years ago
use Hyperf\HttpServer\Contract\RequestInterface;
2 years ago
class NotifyController extends AbstractController
{
2 years ago
2 years ago
private PaymentService $paymentService;
2 years ago
private UserService $userService;
private RequestService $requestService;
public function __construct(
PaymentService $paymentService,
UserService $userService,
RequestService $requestService
) {
2 years ago
$this->paymentService = $paymentService;
2 years ago
$this->userService = $userService;
$this->requestService = $requestService;
2 years ago
}
2 years ago
public function register(RequestInterface $request)
2 years ago
{
2 years ago
$token = $request->route('token');
$requestLog = $this->requestService->getRequestLogByToken($token);
2 years ago
$params = $request->all();
2 years ago
Log::info('registerNotifyParams:', $params);
$baofu = new Baofu();
if (!$baofu->notifyVerify($params, 'register')) {
Log::info('registerNotifyVerifyFail: ' . $params);
return $baofu->notifySuccess();
2 years ago
}
2 years ago
$userId = $requestLog->getDataValue('userId');
$appId = $requestLog->app_id;
$this->userService->rsyncUser($params['loginNo'], $appId, $userId);
$result = $this->notify(
$requestLog->getDataValue('notify_url'),
$requestLog->app,
[
'user_id' => $params['loginNo'],
]
);
$baofu->notifySuccess();
2 years ago
}
2 years ago
2 years ago
public function bindCard(RequestInterface $request)
2 years ago
{
2 years ago
$token = $request->route('token');
$requestLog = $this->requestService->getRequestLogByToken($token);
2 years ago
$params = $request->all();
2 years ago
Log::info('registerNotifyParams:', $params);
$baofu = new Baofu();
if (!$baofu->notifyVerify($params, 'register')) {
Log::info('registerNotifyVerifyFail: ' . $params);
return $baofu->notifySuccess();
2 years ago
}
2 years ago
$bindCardFlag = $params['bindCardFlag'] && $params['bindCardFlag'] != 'false' ? true : false;
if ($bindCardFlag) {
$this->userService->rsyncBankCards($params['loginNo']);
2 years ago
}
2 years ago
2 years ago
$result = $this->notify(
$requestLog->getDataValue('notify_url'),
$requestLog->app,
[
'bind_card_flag' => $bindCardFlag,
'user_id' => $params['loginNo'],
]
);
$baofu->notifySuccess();
2 years ago
}
2 years ago
protected function notify($url, $app, $data)
{
2 years ago
if (empty($url)) {
return 'empty url';
}
2 years ago
$params = [
'app_id' => $app->app_id,
'nonce_str' => StringHelper::getRandomString(32),
'timestamp' => time(),
];
$params['data'] = json_encode($data);
$params['sign'] = PlatformSigner::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');
return $result;
2 years ago
}
2 years ago
}