diff --git a/app/Utils/API/Facebook.php b/app/Utils/API/Facebook.php new file mode 100644 index 0000000..819eb0d --- /dev/null +++ b/app/Utils/API/Facebook.php @@ -0,0 +1,99 @@ +setLogger(new CurlLogger()); + } + + /** + * 发送 Facebook 事件 + * @param string $event_name 事件名称 (PageView / CompleteRegistration) + * @param string $access_token + * @param string $pixel_id + */ + private static function sendEvent(string $event_name, string $access_token, string $pixel_id): void + { + try { + self::initFacebookApi($access_token); + + $event = (new Event()) + ->setEventName($event_name) + ->setEventTime(time()) + ->setUserData(new UserData()) // 可以扩展用户数据 + ->setCustomData(new CustomData()) // 可以扩展自定义数据 + ->setActionSource("website"); + + (new EventRequest($pixel_id)) + ->setEvents([$event]) + ->execute(); + } catch (Exception $e) { + error_log("Facebook API Error: " . $e->getMessage()); + } + } + + /** + * 触发 PageView 事件 + * @param string $access_token + * @param string $pixel_id + */ + public static function PageView(string $access_token, string $pixel_id): void + { + self::sendEvent("PageView", $access_token, $pixel_id); + } + + /** + * 触发 CompleteRegistration 事件 + * @param string $access_token + * @param string $pixel_id + */ + public static function CompleteRegistration(string $access_token, string $pixel_id): void + { + self::sendEvent("CompleteRegistration", $access_token, $pixel_id); + } + + /** + * 处理 Facebook 事件 + * @param int $type 事件类型 (1 = PageView, 2 = CompleteRegistration) + * @param string $invite_code 邀请码 + */ + public static function handleEvent(int $type, string $invite_code): void + { + $recommend = Recommend::where('invite_code', $invite_code)->first(); + + if ($recommend) { + $facebookConf = Facebookconf::where('promotionid', $recommend->id)->first(); + if ($facebookConf) { + $access_token = $facebookConf->access_token; + $pixel_id = $facebookConf->pixel_id; + + match ($type) { + 1 => self::PageView($access_token, $pixel_id), + 2 => self::CompleteRegistration($access_token, $pixel_id), + default => error_log("Invalid event type: " . $type), + }; + } + } + } +} diff --git a/app/Utils/API/Payment.php b/app/Utils/API/Payment.php index face383..dd90177 100644 --- a/app/Utils/API/Payment.php +++ b/app/Utils/API/Payment.php @@ -65,13 +65,13 @@ class Payment ]; $encrypt_value = self::generate_encrypt_value($payload, $secret_key); $payload["EncryptValue"] = $encrypt_value; - var_dump(111111111111111); - var_dump($payload); + // var_dump(111111111111111); + // var_dump($payload); $response = $client->post($url, [ 'json' => $payload, // 以 JSON 格式发送数据 'headers' => $headers ]); - var_dump($response); + // var_dump($response); // $json_payload = json_encode($payload); // $ch = curl_init(); diff --git a/app/Utils/API/PaymentNew.php b/app/Utils/API/PaymentNew.php index 02adbe2..0cfbe9b 100644 --- a/app/Utils/API/PaymentNew.php +++ b/app/Utils/API/PaymentNew.php @@ -40,7 +40,7 @@ class PaymentNew $param_str = rtrim($param_str, '&'); // 添加 HashKey $param_str .= "&HashKey=" . trim(self::$secret_key); - + // 输出拼接后的字符串以供调试(可选) // echo "Lowercase string: $param_str\n"; @@ -49,7 +49,7 @@ class PaymentNew // 5. 计算 sha256 哈希 $hash_value = hash('sha256', $param_str); - + Log::warning("param_str:" . $param_str." hash_value:".$hash_value); // 6. 转换为大写返回 return strtoupper($hash_value); } @@ -81,7 +81,6 @@ class PaymentNew "PayeeAccountName" => $payeeAccountName, "PayeeAccountNumber" => $payeeAccountNumber, "PayeeBankName" => $payeeBankName, - "PayeeIFSCCode" => "", "PaymentChannelId" => $PaymentChannelId, "ShopInformUrl" => "http://38.54.94.131/api/withdraw/callback", "ShopOrderId" => $orderId . "", diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 350ab2c..c38ef25 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -2,6 +2,7 @@ namespace app\controller; +use App\Utils\API\Fackbook; use App\Utils\API\PaymentNew; use support\Request; @@ -13,7 +14,6 @@ class IndexController public function index(Request $request) { - return response()->file(public_path() . '/index.html'); } diff --git a/app/controller/RecommendController.php b/app/controller/RecommendController.php index c9a9f73..dc29996 100644 --- a/app/controller/RecommendController.php +++ b/app/controller/RecommendController.php @@ -3,6 +3,7 @@ namespace app\controller; use app\model\Recommend; +use App\Utils\API\Facebook; use App\Utils\API\PaymentNew; use support\Request; @@ -13,7 +14,7 @@ class RecommendController { protected $noNeedLogin = ['index']; /** - * @Apidoc\Title("1.0 获取vip等级赠送积分") + * @Apidoc\Title("1.0 推广链接") * @Apidoc\Url("Recommend/index") * @Apidoc\Method("POST") */ @@ -22,10 +23,9 @@ class RecommendController $invite_code = $request->get('invite_code'); $Recommend = Recommend::where('invite_code', $invite_code)->first(); if (!empty($Recommend)) { - $Recommend->open += 1; - $Recommend->save(); - return redirect("http://127.0.0.1:8787/#/reg?i=$invite_code", 302); + Facebook::handleEvent(1, $invite_code); + return redirect("https://v8job.online/#/reg?i=$invite_code", 302); } - return 0; + return redirect("https://v8job.online/#/", 302); } } diff --git a/app/controller/admin/api/v1/AccountController.php b/app/controller/admin/api/v1/AccountController.php index bd7eada..b6068cd 100644 --- a/app/controller/admin/api/v1/AccountController.php +++ b/app/controller/admin/api/v1/AccountController.php @@ -9,6 +9,7 @@ use hg\apidoc\annotation as Apidoc; use Intervention\Image\ImageManagerStatic as Image; use Exception; use support\exception\BusinessException; +use support\Log; use Tinywan\Jwt\JwtToken; /** @@ -57,7 +58,7 @@ class AccountController ]; // 如果密码正确,生成 JWT 令牌 $token = JwtToken::generateToken($user); - + Log::info('生成的token:' . json_encode($token)); // 返回成功响应和用户信息(可以将 token 添加到响应中) return ApiResponse::success(200, [ 'user' => $user, // 返回用户信息 diff --git a/app/controller/api/CommonController.php b/app/controller/api/CommonController.php index e10c82a..7de02da 100644 --- a/app/controller/api/CommonController.php +++ b/app/controller/api/CommonController.php @@ -84,7 +84,7 @@ class CommonController // 执行查询并获取结果 $list = $query->get(); - var_dump(1111); + // var_dump(1111); // 准备返回的数据 $map = [ diff --git a/app/controller/api/UserController.php b/app/controller/api/UserController.php index d71681d..3638459 100644 --- a/app/controller/api/UserController.php +++ b/app/controller/api/UserController.php @@ -18,6 +18,7 @@ use app\model\Recommend; use app\model\Reward; use app\model\UserPhone; use app\model\UserReward; +use App\Utils\API\Facebook; use hg\apidoc\annotation as Apidoc; /** @@ -99,6 +100,7 @@ class UserController $user->robot_invite_code = $invitation; $Recommend->register += 1; $Recommend->save(); + Facebook::handleEvent(2, $invitation); } } diff --git a/app/middleware/JwtAuthMiddleware.php b/app/middleware/JwtAuthMiddleware.php index 47140f3..11497b2 100644 --- a/app/middleware/JwtAuthMiddleware.php +++ b/app/middleware/JwtAuthMiddleware.php @@ -79,7 +79,7 @@ class JwtAuthMiddleware implements MiddlewareInterface // } // var_dump($decoded); } catch (\Exception $e) { - var_dump($e); + // var_dump($e); // 解码失败,返回无效令牌错误 // return ApiResponse::error(401, ['error' => '无效的令牌'], '无效的令牌'); return response('',401,['error' => '无效的令牌']); diff --git a/app/model/Facebookconf.php b/app/model/Facebookconf.php new file mode 100644 index 0000000..2a0e90c --- /dev/null +++ b/app/model/Facebookconf.php @@ -0,0 +1,25 @@ +=8.0" + }, + "require-dev": { + "mockery/mockery": "1.3.3", + "phpunit/phpunit": "~9", + "symfony/finder": "~2.6" + }, + "type": "library", + "autoload": { + "psr-4": { + "FacebookAds\\": "src/FacebookAds/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "description": "PHP SDK for Facebook Business", + "homepage": "https://developers.facebook.com/", + "keywords": [ + "ads", + "business", + "facebook", + "instagram", + "page", + "sdk" + ], + "support": { + "issues": "https://github.com/facebook/facebook-php-business-sdk/issues", + "source": "https://github.com/facebook/facebook-php-business-sdk/tree/19.0.1" + }, + "time": "2024-03-07T21:30:58+00:00" + }, { "name": "firebase/php-jwt", "version": "v6.4.0", diff --git a/process/Task.php b/process/Task.php index 625b577..689ac0e 100644 --- a/process/Task.php +++ b/process/Task.php @@ -50,7 +50,7 @@ class Task $GetLodeLog = GetLodeLog::where('status', 0)->get(); foreach ($GetLodeLog as $key => $value) { $res = SendCode::get_code($value->phone); - var_dump($res); + // var_dump($res); if ($res['status'] == 1 && $res['scanCode'] != null) { $value->status = 1; $value->code = $res['scanCode'];