更新鉴权
This commit is contained in:
parent
938caef787
commit
d1c91de640
@ -248,7 +248,7 @@ class GoogleAdsController
|
||||
*/
|
||||
public function getCampaigns($options): Response
|
||||
{
|
||||
$resourceName = $this->googleAdsCampaignService->runListCampaigns($options['customer_id']);
|
||||
$resourceName = $this->googleAdsCampaignService->runListCampaigns($options['customer_id'], $options);
|
||||
return $this->successResponse(['campaigns_list' => $resourceName]);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class OAuthController
|
||||
|
||||
public function handleCallback(Request $request)
|
||||
{
|
||||
$state = $request->input('state'); // 从Google回调中获取state
|
||||
$state = $request->input('state') ?? $request->jwtClaims['uid'];
|
||||
$code = $request->input('code'); // 授权码
|
||||
|
||||
if (!$state) {
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use app\model\ThirdUserAdvertiser;
|
||||
use app\model\ThirdUser;
|
||||
|
||||
//use ReflectionClass;
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
@ -14,33 +15,36 @@ class OauthCheck implements MiddlewareInterface
|
||||
{
|
||||
|
||||
$requestData = $request->all(); // 获取请求数据
|
||||
$customerId = isset($requestData['ad_customer_id']) ? $requestData['ad_customer_id'] : getenv('GOOGLE_ADS_CUSTOMER_ID');
|
||||
// 通过 advertiser_id 查询 ThirdUserAdvertiser,联表查询 ThirdUser 数据
|
||||
$userAdvertiser = ThirdUserAdvertiser::with('googleUser') // 联表查询 user 关联
|
||||
->where('advertiser_id', $customerId) // 根据 advertiser_id 查询
|
||||
->find(); // 获取第一个结果
|
||||
// 如果找到广告主数据
|
||||
if ($userAdvertiser && $userAdvertiser->googleUser) {
|
||||
// 获取关联用户的 access_token
|
||||
$accessToken = $userAdvertiser->googleUser->access_token;
|
||||
if (empty($accessToken)) {
|
||||
// $customerId = isset($requestData['ad_customer_id']) ? $requestData['ad_customer_id'] : getenv('GOOGLE_ADS_CUSTOMER_ID');
|
||||
$uid = $request->jwtClaims['uid'];
|
||||
// 查询指定 user_id 的 ThirdUser
|
||||
$thirdUser = ThirdUser::where('user_id', $uid)->find();
|
||||
|
||||
if ($thirdUser) {
|
||||
// 获取 access_token
|
||||
$request->access_token = $thirdUser->access_token;
|
||||
|
||||
// 获取关联的广告主数据
|
||||
$advertiser = $thirdUser->advertisers()->find(); // 获取第一个广告主记录
|
||||
|
||||
if ($advertiser) {
|
||||
// 获取 google_login_customer_id
|
||||
$request->login_customer_id = $advertiser->google_login_customer_id;
|
||||
} else {
|
||||
return Json([
|
||||
'code' => 300,
|
||||
'msg' => 'AccessToken 为空或过期',
|
||||
'code' => 0,
|
||||
'msg' => 'Ads Data is ready to collect,please wait',
|
||||
'data' => []
|
||||
]);
|
||||
}
|
||||
$request->login_customer_id = $customerId;
|
||||
$request->access_token = $accessToken;
|
||||
} else {
|
||||
return Json([
|
||||
'code' => 300,
|
||||
'msg' => '未找到该广告主或关联的用户',
|
||||
'msg' => 'AccessToken 为空或过期',
|
||||
'data' => []
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// if (session('user')) {
|
||||
// // 已经登录,请求继续向洋葱芯穿越
|
||||
// return $handler($request);
|
||||
|
@ -32,9 +32,6 @@ class GoogleAdsReportService
|
||||
$query->whereIn('a.customer_id', $customerIds); // 添加 customer_id 的查询约束
|
||||
} else {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '接口正常响应',
|
||||
'data' => [
|
||||
'pagination' => [
|
||||
'startIndex' => 0,
|
||||
'maxResults' => $pageSize,
|
||||
@ -53,7 +50,6 @@ class GoogleAdsReportService
|
||||
'be_roas' => '-',
|
||||
],
|
||||
'data' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -158,13 +154,9 @@ class GoogleAdsReportService
|
||||
];
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '接口正常响应',
|
||||
'data' => [
|
||||
'pagination' => $pagination,
|
||||
'statistics' => $statistics,
|
||||
'data' => $result,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -308,9 +300,6 @@ class GoogleAdsReportService
|
||||
// 检查 customerIds 是否为空,直接返回空结构
|
||||
if (empty($customerIds)) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '接口正常响应',
|
||||
'data' => [
|
||||
'pagination' => [
|
||||
'startIndex' => 0,
|
||||
'maxResults' => $pageSize,
|
||||
@ -329,7 +318,6 @@ class GoogleAdsReportService
|
||||
'be_roas' => '-',
|
||||
],
|
||||
'data' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
// 动态构建日期条件
|
||||
@ -426,13 +414,9 @@ class GoogleAdsReportService
|
||||
];
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '接口正常响应',
|
||||
'data' => [
|
||||
'pagination' => $pagination,
|
||||
'statistics' => $statistics,
|
||||
'data' => $result,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -631,9 +615,6 @@ class GoogleAdsReportService
|
||||
// 检查 customerIds 是否为空,直接返回空结构
|
||||
if (empty($customerIds)) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '接口正常响应',
|
||||
'data' => [
|
||||
'pagination' => [
|
||||
'startIndex' => 0,
|
||||
'maxResults' => $pageSize,
|
||||
@ -652,7 +633,6 @@ class GoogleAdsReportService
|
||||
'be_roas' => '-',
|
||||
],
|
||||
'data' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -748,13 +728,9 @@ class GoogleAdsReportService
|
||||
|
||||
// 返回结果
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '接口正常响应',
|
||||
'data' => [
|
||||
'pagination' => $pagination,
|
||||
'statistics' => $statistics,
|
||||
'data' => $result,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user