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
PHP

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