|
@@ -0,0 +1,59 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Services\ApiFootball;
|
|
|
|
|
+
|
|
|
|
|
+use Illuminate\Support\Facades\Http;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class Client
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ //
|
|
|
|
|
+ public static function get($endpoint, $params = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ $response = Http::withHeaders([
|
|
|
|
|
+ 'x-apisports-key' => config('services.api_football.key'),
|
|
|
|
|
+ ])
|
|
|
|
|
+ ->withoutVerifying() // 临时跳过 SSL 验证
|
|
|
|
|
+ ->get(config('services.api_football.host') .'/'. $endpoint, $params);
|
|
|
|
|
+
|
|
|
|
|
+ if ($response->successful()) {
|
|
|
|
|
+ return $response->json();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Handle errors as needed
|
|
|
|
|
+ throw new \Exception("API request failed: " . $response->body());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function post($endpoint, $data = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ $response = Http::withHeaders([
|
|
|
|
|
+ 'x-apisports-key' => config('services.api_football.key'),
|
|
|
|
|
+ ])->post(config('services.api_football.host') .'/'. $endpoint, $data);
|
|
|
|
|
+
|
|
|
|
|
+ if ($response->successful()) {
|
|
|
|
|
+ return $response->json();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Handle errors as needed
|
|
|
|
|
+ throw new \Exception("API request failed: " . $response->body());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 时区
|
|
|
|
|
+ public static function timezone()
|
|
|
|
|
+ {
|
|
|
|
|
+ return self::get('timezone');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 国家/地区
|
|
|
|
|
+ public static function countries($params = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ return self::get('countries', $params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 赛程
|
|
|
|
|
+ public static function fixtures($params = [])
|
|
|
|
|
+ {
|
|
|
|
|
+ return self::get('fixtures', $params);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|