Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
e8c55e6c8a
@ -4,6 +4,7 @@ namespace app\controller;
|
||||
|
||||
use app\service\GoogleOAuthService;
|
||||
use app\service\BpsAdAccountService;
|
||||
use app\service\GoogleAdsAccountService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use DI\Annotation\Inject;
|
||||
@ -32,6 +33,12 @@ class OAuthController
|
||||
*/
|
||||
private $bpsAdAccountService;
|
||||
|
||||
/**
|
||||
* @Inject
|
||||
* @var GoogleAdsAccountService
|
||||
*/
|
||||
private $googleAdsAccountService;
|
||||
|
||||
|
||||
public function getAuthCode(Request $request)
|
||||
{
|
||||
@ -71,10 +78,10 @@ class OAuthController
|
||||
public function handleCallback(Request $request)
|
||||
{
|
||||
// $state = $request->input('state') ?? $request->jwtClaims['uid'];
|
||||
$state = $request->input('state') ?? $request->jwtClaims['merchant_id'];
|
||||
$state = $request->input('state') ?? $request->jwtClaims['merchant_id'];
|
||||
$merchantId = $request->jwtClaims['merchant_id'];
|
||||
$userId = $request->jwtClaims['uid'];
|
||||
$code = $request->input('code'); // 授权码
|
||||
$userId = $request->jwtClaims['uid'];
|
||||
$code = $request->input('code'); // 授权码
|
||||
|
||||
if (!$state) {
|
||||
return $this->errorResponse(300, 'Invalid state parameter');
|
||||
@ -97,18 +104,30 @@ class OAuthController
|
||||
}
|
||||
return $this->errorResponse(300, 'Refresh Token getting failed');
|
||||
} else {
|
||||
//如果这个授权用户名下没有任何广告账号
|
||||
$option = [];
|
||||
$option['refresh_token'] = $tokens['refresh_token'];
|
||||
|
||||
$listAccessibleCustomers = $this->googleAdsAccountService->runListAccessibleCustomers($option);
|
||||
if (empty($listAccessibleCustomers)) {
|
||||
$googleOAuthService = new GoogleOAuthService();
|
||||
$googleOAuthService->revokeToken($tokens['refresh_token'], $merchantId);
|
||||
|
||||
return $this->errorResponse(300, 'has not any google ads account');
|
||||
}
|
||||
|
||||
// $googleOAuthService->saveRefreshToken($tokens['refresh_token'], $state); //作废2025-2-13
|
||||
$googleOAuthService->saveRefreshTokenNew($tokens['refresh_token'],$tokens['access_token'], $merchantId,$userId);
|
||||
$googleOAuthService->saveRefreshTokenNew($tokens['refresh_token'], $tokens['access_token'], $merchantId, $userId);
|
||||
|
||||
// 生成 UUID
|
||||
$uuid = $this->generateUuid();
|
||||
// echo $uuid; // 例如:f47ac10b-58cc-4372-a567-0e02b2c3d479
|
||||
// echo $uuid; // 例如:f47ac10b-58cc-4372-a567-0e02b2c3d479
|
||||
$redisKey = self::REDIS_KEY_PREFIX . $uuid;
|
||||
//把$tokens['refresh_token']存入redis的redisKey, 并设置过期时间为10分钟
|
||||
Redis::setex($redisKey, 600, $tokens['refresh_token']);
|
||||
// 保存refresh token到数据库
|
||||
// $googleOAuthService->saveRefreshToken($tokens['refresh_token'], $state, $uuid);
|
||||
// // 触发事件
|
||||
// $googleOAuthService->saveRefreshToken($tokens['refresh_token'], $state, $uuid);
|
||||
// // 触发事件
|
||||
return $this->successResponse(['token' => $uuid], $request);
|
||||
}
|
||||
// return $this->successResponse($tokens, $request);
|
||||
|
Loading…
Reference in New Issue
Block a user