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