From 5d8d1085ba6eda738b436dac6e4cac08cebb8c7a Mon Sep 17 00:00:00 2001 From: huangguancheng Date: Fri, 10 Jan 2025 17:41:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E5=B9=B3=E5=8F=B0=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E4=B8=AD=E9=97=B4=E4=BB=B6=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/middleware/OauthThirdCheck.php | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 app/middleware/OauthThirdCheck.php diff --git a/app/middleware/OauthThirdCheck.php b/app/middleware/OauthThirdCheck.php new file mode 100644 index 0000000..72e081d --- /dev/null +++ b/app/middleware/OauthThirdCheck.php @@ -0,0 +1,46 @@ +all(); // 获取请求数据 +// $customerId = isset($requestData['ad_customer_id']) ? $requestData['ad_customer_id'] : getenv('GOOGLE_ADS_CUSTOMER_ID'); + $uid = $request->jwtClaims['uid']; + // 查询指定 user_id 的 ThirdUser + $thirdUserGoogle = ThirdUser::where('user_id', $uid)->where('third_type', 'google')->find(); + if ($thirdUserGoogle && $thirdUserGoogle->access_token) { + // 获取 access_token + $request->refresh_token_google = $thirdUserGoogle->access_token; + // 获取关联的广告主数据 + $advertiserGoogle = $thirdUserGoogle->advertisers()->find(); // 获取第一个广告主记录 + + if ($advertiserGoogle) { + // 获取 google_login_customer_id + $request->login_customer_id = $advertiserGoogle->google_login_customer_id; +// dump( $request->access_token,$request->login_customer_id); + } + } + $thirdUserFacebook = ThirdUser::where('user_id', $uid)->where('third_type', 'facebook')->find(); + if ($thirdUserFacebook && $thirdUserFacebook->access_token) { + // 获取 access_token + $request->refresh_token_facebook = $thirdUserFacebook->access_token; + } + $thirdUserTiktok = ThirdUser::where('user_id', $uid)->where('third_type', 'tiktok')->find(); + if($thirdUserTiktok && $thirdUserTiktok->access_token){ + $request->refresh_token_tiktok = $thirdUserTiktok->access_token; + } + // 不需要登录,请求继续向洋葱芯穿越 + return $handler($request); + } +} \ No newline at end of file