查看3平台授权状态
This commit is contained in:
parent
4029a20e3c
commit
5313df7d90
@ -3,6 +3,7 @@
|
|||||||
namespace app\controller;
|
namespace app\controller;
|
||||||
|
|
||||||
use app\service\GoogleOAuthService;
|
use app\service\GoogleOAuthService;
|
||||||
|
use app\service\BpsAdAccountService;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
use DI\Annotation\Inject;
|
use DI\Annotation\Inject;
|
||||||
@ -20,6 +21,11 @@ class OAuthController
|
|||||||
* @var GoogleOAuthService
|
* @var GoogleOAuthService
|
||||||
*/
|
*/
|
||||||
private $googleOAuthService;
|
private $googleOAuthService;
|
||||||
|
/**
|
||||||
|
* @Inject
|
||||||
|
* @var BpsAdAccountService
|
||||||
|
*/
|
||||||
|
private $bpsAdAccountService;
|
||||||
|
|
||||||
|
|
||||||
public function getAuthCode(Request $request)
|
public function getAuthCode(Request $request)
|
||||||
@ -28,13 +34,37 @@ class OAuthController
|
|||||||
$authUrl = $this->googleOAuthService->getAuthUrl($state);
|
$authUrl = $this->googleOAuthService->getAuthUrl($state);
|
||||||
return $this->successResponse([
|
return $this->successResponse([
|
||||||
'url' => $authUrl,
|
'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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function handleCallback(Request $request)
|
public function handleCallback(Request $request)
|
||||||
{
|
{
|
||||||
$state = $request->input('state') ?? $request->jwtClaims['uid'];
|
$state = $request->input('state') ?? $request->jwtClaims['uid'];
|
||||||
$code = $request->input('code'); // 授权码
|
$code = $request->input('code'); // 授权码
|
||||||
|
|
||||||
if (!$state) {
|
if (!$state) {
|
||||||
@ -54,7 +84,7 @@ class OAuthController
|
|||||||
$googleOAuthService->saveRefreshToken($tokens['refresh_token'], $state);
|
$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);
|
$tokens = $googleOAuthService->getRefreshToken($authCode);
|
||||||
if (!isset($tokens['refresh_token'])) {
|
if (!isset($tokens['refresh_token'])) {
|
||||||
return $this->successResponse($tokens,$request);
|
return $this->successResponse($tokens, $request);
|
||||||
}
|
}
|
||||||
// 保存refresh token到数据库
|
// 保存refresh token到数据库
|
||||||
// $googleOAuthService->saveRefreshToken($tokens['refresh_token'], $tokens['access_token'], $request->user_id);
|
// $googleOAuthService->saveRefreshToken($tokens['refresh_token'], $tokens['access_token'], $request->user_id);
|
||||||
@ -84,7 +114,7 @@ class OAuthController
|
|||||||
$googleOAuthService = new GoogleOAuthService();
|
$googleOAuthService = new GoogleOAuthService();
|
||||||
|
|
||||||
$newAccessToken = $googleOAuthService->useRefreshToken($refreshToken);
|
$newAccessToken = $googleOAuthService->useRefreshToken($refreshToken);
|
||||||
return $this->successResponse(['access_token' => $newAccessToken],$request);
|
return $this->successResponse(['access_token' => $newAccessToken], $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function revokeRefreshToken(Request $request)
|
public function revokeRefreshToken(Request $request)
|
||||||
@ -93,7 +123,7 @@ class OAuthController
|
|||||||
// $customerId = isset($requestData['customer_id']) ? $requestData['customer_id'] : getenv('GOOGLE_ADS_CUSTOMER_ID');
|
// $customerId = isset($requestData['customer_id']) ? $requestData['customer_id'] : getenv('GOOGLE_ADS_CUSTOMER_ID');
|
||||||
// $customerId = getenv('GOOGLE_ADS_CUSTOMER_ID'); //临时指定
|
// $customerId = getenv('GOOGLE_ADS_CUSTOMER_ID'); //临时指定
|
||||||
|
|
||||||
$uid = $request->input('user_id') ?? $request->jwtClaims['uid'];
|
$uid = $request->input('user_id') ?? $request->jwtClaims['uid'];
|
||||||
|
|
||||||
// 通过 advertiser_id 查询 ThirdUserAdvertiser,联表查询 ThirdUser 数据
|
// 通过 advertiser_id 查询 ThirdUserAdvertiser,联表查询 ThirdUser 数据
|
||||||
$thirdUser = ThirdUser::where('user_id', $uid)->where('third_type', 'google')->find(); // 获取第一个结果
|
$thirdUser = ThirdUser::where('user_id', $uid)->where('third_type', 'google')->find(); // 获取第一个结果
|
||||||
@ -106,7 +136,7 @@ class OAuthController
|
|||||||
|
|
||||||
$googleOAuthService = new GoogleOAuthService();
|
$googleOAuthService = new GoogleOAuthService();
|
||||||
$googleOAuthService->revokeToken($accessToken, $thirdUser->id);
|
$googleOAuthService->revokeToken($accessToken, $thirdUser->id);
|
||||||
return $this->successResponse(['deleted' => 'success'],$request);
|
return $this->successResponse(['deleted' => 'success'], $request);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +161,7 @@ class OAuthController
|
|||||||
{
|
{
|
||||||
$options = $request->all();
|
$options = $request->all();
|
||||||
// dump($options);
|
// dump($options);
|
||||||
return $this->googleOAuthService->queue($options);
|
return $this->googleOAuthService->queue($options);
|
||||||
|
|
||||||
// return $this->successResponse([],$request);
|
// return $this->successResponse([],$request);
|
||||||
|
|
||||||
@ -202,7 +232,7 @@ class OAuthController
|
|||||||
|
|
||||||
|
|
||||||
// 可以加入一些公共方法
|
// 可以加入一些公共方法
|
||||||
protected function successResponse($data,Request $request): Response
|
protected function successResponse($data, Request $request): Response
|
||||||
{
|
{
|
||||||
if ($request->jwtNewToken) {
|
if ($request->jwtNewToken) {
|
||||||
return new Response(200,
|
return new Response(200,
|
||||||
|
@ -263,7 +263,7 @@ class BpsAdAccountService
|
|||||||
->join('bps.bps_third_user tu', 'tua.doc_ = tu.id') // 连接 bps_third_user 表
|
->join('bps.bps_third_user tu', 'tua.doc_ = tu.id') // 连接 bps_third_user 表
|
||||||
->where('tu.user_id', $userId) // 筛选 user_id 的记录
|
->where('tu.user_id', $userId) // 筛选 user_id 的记录
|
||||||
->where('tu.access_token', '<>', '') // 筛选 access_token 不为空的记录
|
->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();
|
->select();
|
||||||
|
|
||||||
// 如果没有找到符合条件的用户,返回空数组
|
// 如果没有找到符合条件的用户,返回空数组
|
||||||
|
@ -147,6 +147,7 @@ Route::group('/googleads', function () {
|
|||||||
Route::post('/refresh_token_use', [OAuthController::class, 'useRefreshToken']);
|
Route::post('/refresh_token_use', [OAuthController::class, 'useRefreshToken']);
|
||||||
Route::post('/refresh_token_test', [OAuthController::class, 'testRefreshToken']);
|
Route::post('/refresh_token_test', [OAuthController::class, 'testRefreshToken']);
|
||||||
Route::post('/refresh_token_revoke', [OAuthController::class, 'revokeRefreshToken']);
|
Route::post('/refresh_token_revoke', [OAuthController::class, 'revokeRefreshToken']);
|
||||||
|
Route::post('/list_third_status', [OAuthController::class, 'listThirdUserInfos']);
|
||||||
})->middleware([
|
})->middleware([
|
||||||
app\middleware\JwtLocal::class,
|
app\middleware\JwtLocal::class,
|
||||||
]);
|
]);
|
||||||
|
Loading…
Reference in New Issue
Block a user