| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Services;
- use Illuminate\Support\Facades\Http;
- class SportClientService
- {
- //
- public static function get($endpoint, $params = [])
- {
- $response = Http::withHeaders([
- 'x-apisports-key' => env('API_FOOTBALL_KEY'),
- ])
- ->withoutVerifying() // 临时跳过 SSL 验证
- ->get(env('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 odds($params = [])
- {
- return static::get('odds', $params);
- }
- public static function fixturesRounds($params = [])
- {
- return static::get('fixtures/rounds', $params);
- }
- // 赛程
- public static function fixtures($params = [])
- {
- return self::get('fixtures', $params);
- }
- }
|