| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?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 leagues($params = [])
- {
- return static::get('leagues', $params);
- }
- // 联赛赛季 获取特定联赛的赛季列表。
- public static function leaguesSeasons($params = [])
- {
- return static::get('leagues/seasons', $params);
- }
- // This endpoint returns in-play odds for fixtures in progress.
- // 此端点会返回正在进行的比赛的实时赔率。
- // Update Frequency : This endpoint is updated every 5 seconds.
- // 更新频率:此端点每 5 秒钟更新一次。
- public static function oddsLive($params = [])
- {
- return static::get('odds/live', $params);
- }
- public static function fixturesRounds($params = [])
- {
- return static::get('fixtures/rounds', $params);
- }
- // 赛程
- public static function fixtures($params = [])
- {
- return self::get('fixtures', $params);
- }
- }
|