查看3平台授权状态

This commit is contained in:
huangguancheng 2025-01-10 16:03:34 +08:00
parent 4029a20e3c
commit 5313df7d90
3 changed files with 41 additions and 10 deletions

View File

@ -3,6 +3,7 @@
namespace app\controller;
use app\service\GoogleOAuthService;
use app\service\BpsAdAccountService;
use support\Request;
use support\Response;
use DI\Annotation\Inject;
@ -20,6 +21,11 @@ class OAuthController
* @var GoogleOAuthService
*/
private $googleOAuthService;
/**
* @Inject
* @var BpsAdAccountService
*/
private $bpsAdAccountService;
public function getAuthCode(Request $request)
@ -28,7 +34,31 @@ class OAuthController
$authUrl = $this->googleOAuthService->getAuthUrl($state);
return $this->successResponse([
'url' => $authUrl,
],$request);
], $request);
}
public function listThirdUserInfos(Request $request)
{
$options = $request->all();
$options['jwtClaims'] = $request->jwtClaims;
$authorizedThirdUsers =
[
'facebook' => ['status' => 0],
'google' => ['status' => 0],
'tiktok' => ['status' => 0],
];
$accounts = $this->bpsAdAccountService->getAllThirdUsers(['uid' => $options['jwtClaims']['uid']]);
foreach ($accounts as $account) {
$authorizedThirdUsers[$account['third_type']] = [
'status' => 1,
'id' => $account['id'],
];
}
// 返回结果
return $this->successResponse($authorizedThirdUsers, $request);
}
@ -54,7 +84,7 @@ class OAuthController
$googleOAuthService->saveRefreshToken($tokens['refresh_token'], $state);
}
return $this->successResponse($tokens,$request);
return $this->successResponse($tokens, $request);
}
@ -70,7 +100,7 @@ class OAuthController
$tokens = $googleOAuthService->getRefreshToken($authCode);
if (!isset($tokens['refresh_token'])) {
return $this->successResponse($tokens,$request);
return $this->successResponse($tokens, $request);
}
// 保存refresh token到数据库
// $googleOAuthService->saveRefreshToken($tokens['refresh_token'], $tokens['access_token'], $request->user_id);
@ -84,7 +114,7 @@ class OAuthController
$googleOAuthService = new GoogleOAuthService();
$newAccessToken = $googleOAuthService->useRefreshToken($refreshToken);
return $this->successResponse(['access_token' => $newAccessToken],$request);
return $this->successResponse(['access_token' => $newAccessToken], $request);
}
public function revokeRefreshToken(Request $request)
@ -106,7 +136,7 @@ class OAuthController
$googleOAuthService = new GoogleOAuthService();
$googleOAuthService->revokeToken($accessToken, $thirdUser->id);
return $this->successResponse(['deleted' => 'success'],$request);
return $this->successResponse(['deleted' => 'success'], $request);
}
@ -202,7 +232,7 @@ class OAuthController
// 可以加入一些公共方法
protected function successResponse($data,Request $request): Response
protected function successResponse($data, Request $request): Response
{
if ($request->jwtNewToken) {
return new Response(200,

View File

@ -263,7 +263,7 @@ class BpsAdAccountService
->join('bps.bps_third_user tu', 'tua.doc_ = tu.id') // 连接 bps_third_user 表
->where('tu.user_id', $userId) // 筛选 user_id 的记录
->where('tu.access_token', '<>', '') // 筛选 access_token 不为空的记录
->field('tu.id, tu.access_token as refresh_token') // 获取相关字段
->field('tu.id, tu.third_type, tu.access_token as refresh_token') // 获取相关字段
->select();
// 如果没有找到符合条件的用户,返回空数组

View File

@ -147,6 +147,7 @@ Route::group('/googleads', function () {
Route::post('/refresh_token_use', [OAuthController::class, 'useRefreshToken']);
Route::post('/refresh_token_test', [OAuthController::class, 'testRefreshToken']);
Route::post('/refresh_token_revoke', [OAuthController::class, 'revokeRefreshToken']);
Route::post('/list_third_status', [OAuthController::class, 'listThirdUserInfos']);
})->middleware([
app\middleware\JwtLocal::class,
]);