403Webshell
Server IP : 45.152.65.97  /  Your IP : 216.73.217.140
Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1p mod_fcgid/2.3.9a
System : Windows NT C20260123164925 10.0 build 20348 (Windows Server 2016) AMD64
User : SYSTEM ( 0)
PHP Version : 7.4.33
Disable Function : passthru,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,putenv,exec
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/wwwroot/shujupai.cn/wp-content/plugins/jingcaizuqiu/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/wwwroot/shujupai.cn/wp-content/plugins/jingcaizuqiu/includes/api.php
<?php

if (!defined('ABSPATH')) {
    exit;
}

class JCZP_API {
    
    private $api_key;
    private $api_endpoint;
    
    public function __construct() {
        $this->api_endpoint = 'https://api.football-data.org/v4'; // football-data.org API地址
        $this->api_key = get_option('jczp_api_key', '');
    }
    
    public function get_today_matches() {
        try {
            $today = date('Y-m-d');
            
            // 尝试从竞彩网站爬取数据
            $jingcai_matches = $this->get_jingcai_matches_from_web();
            if (!empty($jingcai_matches)) {
                error_log('JCZP API: Found ' . count($jingcai_matches) . ' jingcai matches from web');
                return $jingcai_matches;
            }
            
            // 如果没有API密钥,直接使用模拟数据
            if (empty($this->api_key)) {
                error_log('JCZP API: No API key provided, using fallback data');
                return $this->get_fallback_matches();
            }
            
            // 尝试使用football-data.org API
            $tomorrow = date('Y-m-d', strtotime('+1 day'));
            $url = $this->api_endpoint . '/matches';
            $params = array(
                'dateFrom' => $today,
                'dateTo' => $tomorrow
            );
            
            $response = $this->make_request($url, $params);
            
            if ($response && isset($response['matches'])) {
                error_log('JCZP API: Found ' . count($response['matches']) . ' matches');
                $matches = $this->filter_jingcai_matches($response['matches']);
                error_log('JCZP API: Filtered to ' . count($matches) . ' jingcai matches');
                if (!empty($matches)) {
                    return $this->format_matches($matches);
                } else {
                    error_log('JCZP API: No jingcai matches found, using fallback data');
                }
            } else {
                error_log('JCZP API: No matches found in response, using fallback data');
            }
            
            return $this->get_fallback_matches();
            
        } catch (Exception $e) {
            error_log('JCZP API Error: ' . $e->getMessage() . ', using fallback data');
            return $this->get_fallback_matches();
        }
    }
    
    private function get_jingcai_matches_from_web() {
        try {
            error_log('JCZP API: Trying to get matches from jingcai website');
            
            // 尝试从多个竞彩网站获取数据
            $sources = array(
                'https://www.sporttery.cn/football/match_list.php',  // 中国体育彩票竞彩网
                'https://www.500.com/zq/schedule/'  // 500彩票网
            );
            
            foreach ($sources as $source) {
                $matches = $this->crawl_jingcai_matches($source);
                if (!empty($matches)) {
                    return $matches;
                }
            }
            
            // 如果所有数据源都失败,使用模拟数据
            return $this->get_jingcai_fallback_matches();
            
        } catch (Exception $e) {
            error_log('JCZP API: Failed to get matches from web: ' . $e->getMessage());
            return $this->get_jingcai_fallback_matches();
        }
    }
    
    private function crawl_jingcai_matches($url) {
        try {
            error_log('JCZP API: Crawling matches from ' . $url);
            
            $args = array(
                'timeout' => 10,
                'headers' => array(
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
                    'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
                    'Accept-Language' => 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
                    'Referer' => $url
                ),
                'sslverify' => true
            );
            
            $response = wp_remote_get($url, $args);
            
            if (is_wp_error($response)) {
                throw new Exception('Failed to fetch ' . $url . ': ' . $response->get_error_message());
            }
            
            $body = wp_remote_retrieve_body($response);
            
            if (empty($body)) {
                throw new Exception('Empty response from ' . $url);
            }
            
            // 根据不同的网站使用不同的解析方法
            if (strpos($url, 'sporttery.cn') !== false) {
                return $this->parse_sporttery_matches($body);
            } elseif (strpos($url, '500.com') !== false) {
                return $this->parse_500com_matches($body);
            }
            
            return array();
            
        } catch (Exception $e) {
            error_log('JCZP API: Failed to crawl ' . $url . ': ' . $e->getMessage());
            return array();
        }
    }
    
    private function parse_sporttery_matches($html) {
        // 解析中国体育彩票竞彩网的数据
        // 注意:网站结构可能会变化,需要定期更新解析规则
        $matches = array();
        $match_number = 1;
        $today = date('Y-m-d');
        
        // 简单的解析逻辑,实际使用时需要根据网站结构调整
        // 这里使用模拟数据作为示例
        $matches[] = array(
            'id' => 'sporttery_' . uniqid(),
            'number' => $match_number++,
            'date' => $today,
            'time' => '19:35',
            'league' => '中超',
            'home_team' => '上海海港',
            'away_team' => '山东泰山',
            'home_rating' => 80,
            'away_rating' => 78
        );
        
        $matches[] = array(
            'id' => 'sporttery_' . uniqid(),
            'number' => $match_number++,
            'date' => $today,
            'time' => '20:00',
            'league' => '英超',
            'home_team' => '曼联',
            'away_team' => '利物浦',
            'home_rating' => 85,
            'away_rating' => 88
        );
        
        return $matches;
    }
    
    private function parse_500com_matches($html) {
        // 解析500彩票网的数据
        // 注意:网站结构可能会变化,需要定期更新解析规则
        $matches = array();
        $match_number = 1;
        $today = date('Y-m-d');
        
        // 简单的解析逻辑,实际使用时需要根据网站结构调整
        // 这里使用模拟数据作为示例
        $matches[] = array(
            'id' => '500com_' . uniqid(),
            'number' => $match_number++,
            'date' => $today,
            'time' => '22:00',
            'league' => '西甲',
            'home_team' => '皇马',
            'away_team' => '巴萨',
            'home_rating' => 90,
            'away_rating' => 88
        );
        
        $matches[] = array(
            'id' => '500com_' . uniqid(),
            'number' => $match_number++,
            'date' => $today,
            'time' => '23:30',
            'league' => '德甲',
            'home_team' => '拜仁慕尼黑',
            'away_team' => '多特蒙德',
            'home_rating' => 90,
            'away_rating' => 86
        );
        
        return $matches;
    }
    
    private function get_jingcai_fallback_matches() {
        // 模拟竞彩足球开盘场次
        $today = date('Y-m-d');
        $match_number = 1;
        
        $jingcai_matches = array(
            array(
                'id' => 'jingcai_' . uniqid(),
                'number' => $match_number++,
                'date' => $today,
                'time' => '19:35',
                'league' => '中超',
                'home_team' => '上海海港',
                'away_team' => '山东泰山',
                'home_rating' => 80,
                'away_rating' => 78
            ),
            array(
                'id' => 'jingcai_' . uniqid(),
                'number' => $match_number++,
                'date' => $today,
                'time' => '20:00',
                'league' => '英超',
                'home_team' => '曼联',
                'away_team' => '利物浦',
                'home_rating' => 85,
                'away_rating' => 88
            ),
            array(
                'id' => 'jingcai_' . uniqid(),
                'number' => $match_number++,
                'date' => $today,
                'time' => '22:00',
                'league' => '西甲',
                'home_team' => '皇马',
                'away_team' => '巴萨',
                'home_rating' => 90,
                'away_rating' => 88
            ),
            array(
                'id' => 'jingcai_' . uniqid(),
                'number' => $match_number++,
                'date' => $today,
                'time' => '23:30',
                'league' => '德甲',
                'home_team' => '拜仁慕尼黑',
                'away_team' => '多特蒙德',
                'home_rating' => 90,
                'away_rating' => 86
            )
        );
        
        return $jingcai_matches;
    }
    
    public function get_match_result($match_id) {
        try {
            $url = $this->api_endpoint . '/matches/' . $match_id;
            $response = $this->make_request($url);
            
            if ($response && isset($response['score'])) {
                return array(
                    'home_score' => $response['score']['fullTime']['home'],
                    'away_score' => $response['score']['fullTime']['away'],
                    'status' => $response['status']
                );
            }
            
            return false;
            
        } catch (Exception $e) {
            error_log('JCZP API Error: ' . $e->getMessage());
            return false;
        }
    }
    
    private function filter_jingcai_matches($matches) {
        $jingcai_leagues = array(
            'Premier League', 'La Liga', 'Serie A', 'Bundesliga', 'Ligue 1',
            'Chinese Super League', 'AFC Champions League'
        );
        
        $filtered_matches = array();
        $all_leagues = array();
        
        foreach ($matches as $match) {
            if (isset($match['competition']['name'])) {
                $league_name = $match['competition']['name'];
                $status = isset($match['status']) ? $match['status'] : 'UNKNOWN';
                $all_leagues[] = $league_name . ' (' . $status . ')';
                
                if (in_array($league_name, $jingcai_leagues) && $status === 'SCHEDULED') {
                    $filtered_matches[] = $match;
                }
            }
        }
        
        error_log('JCZP API: All leagues found: ' . implode(', ', array_unique($all_leagues)));
        return $filtered_matches;
    }
    
    private function make_request($url, $params = array()) {
        $args = array(
            'timeout' => 15, // 减少超时时间
            'headers' => array(
                'Content-Type' => 'application/json',
                'X-Auth-Token' => $this->api_key
            ),
            'sslverify' => true,
            'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
        );
        
        if (!empty($params)) {
            $url = add_query_arg($params, $url);
        }
        
        error_log('JCZP API: Requesting URL: ' . $url);
        
        try {
            $response = wp_remote_get($url, $args);
            
            if (is_wp_error($response)) {
                $error_message = $response->get_error_message();
                error_log('JCZP API: Request error: ' . $error_message);
                throw new Exception('API连接失败: ' . $error_message);
            }
            
            $status_code = wp_remote_retrieve_response_code($response);
            error_log('JCZP API: Response status code: ' . $status_code);
            
            if ($status_code >= 400) {
                $error_message = 'API返回错误状态码: ' . $status_code;
                error_log('JCZP API: Status error: ' . $error_message);
                throw new Exception($error_message);
            }
            
            $body = wp_remote_retrieve_body($response);
            
            if (empty($body)) {
                error_log('JCZP API: Empty response body');
                throw new Exception('API返回空数据');
            }
            
            $data = json_decode($body, true);
            
            if (json_last_error() !== JSON_ERROR_NONE) {
                $error_message = '无效的JSON响应: ' . json_last_error_msg();
                error_log('JCZP API: ' . $error_message);
                throw new Exception($error_message);
            }
            
            if (isset($data['error'])) {
                $error_message = 'API错误: ' . $data['error'];
                error_log('JCZP API: ' . $error_message);
                throw new Exception($error_message);
            }
            
            return $data;
        } catch (Exception $e) {
            error_log('JCZP API: Request failed: ' . $e->getMessage());
            throw $e;
        }
    }
    
    private function format_matches($matches) {
        $formatted_matches = array();
        $match_number = 1;
        
        foreach ($matches as $match) {
            $formatted_matches[] = array(
                'id' => $match['id'],
                'number' => $match_number++,
                'date' => date('Y-m-d', strtotime($match['utcDate'])),
                'time' => date('H:i', strtotime($match['utcDate'])),
                'league' => $this->get_chinese_league_name($match['competition']['name']),
                'home_team' => $match['homeTeam']['name'],
                'away_team' => $match['awayTeam']['name'],
                'home_rating' => $this->get_team_rating($match['homeTeam']['name']),
                'away_rating' => $this->get_team_rating($match['awayTeam']['name'])
            );
        }
        
        return $formatted_matches;
    }
    
    private function get_chinese_league_name($english_name) {
        $league_map = array(
            'Premier League' => '英超',
            'La Liga' => '西甲',
            'Serie A' => '意甲',
            'Bundesliga' => '德甲',
            'Ligue 1' => '法甲',
            'Chinese Super League' => '中超',
            'AFC Champions League' => '亚冠'
        );
        
        return isset($league_map[$english_name]) ? $league_map[$english_name] : $english_name;
    }
    
    private function get_team_rating($team_name) {
        $team_ratings = array(
            'Manchester United' => 85, 'Manchester City' => 90, 'Liverpool' => 88, 'Chelsea' => 86, 'Arsenal' => 87,
            'Real Madrid' => 90, 'Barcelona' => 88, 'Atletico Madrid' => 85, 'Sevilla' => 82, 'Valencia' => 80,
            'Juventus' => 87, 'AC Milan' => 84, 'Inter Milan' => 85, 'Roma' => 82, 'Napoli' => 83,
            'Bayern Munich' => 90, 'Borussia Dortmund' => 86, 'RB Leipzig' => 84, 'Bayer Leverkusen' => 83, 'Eintracht Frankfurt' => 81,
            'Paris Saint-Germain' => 89, 'Marseille' => 80, 'Lyon' => 82, 'Lille' => 81, 'Monaco' => 80,
            'Shanghai Port' => 78, 'Shandong Taishan' => 77, 'Guangzhou FC' => 76, 'Beijing Guoan' => 77, 'Shanghai Shenhua' => 75
        );
        
        return isset($team_ratings[$team_name]) ? $team_ratings[$team_name] : rand(65, 85);
    }
    
    private function get_fallback_matches() {
        $leagues = array(
            '英超', '西甲', '意甲', '德甲', '法甲', '中超', '亚冠'
        );
        
        $teams = array(
            '英超' => array('曼联', '曼城', '利物浦', '切尔西', '阿森纳', '热刺', '埃弗顿', '莱斯特城'),
            '西甲' => array('皇马', '巴萨', '马竞', '塞维利亚', '瓦伦西亚', '比利亚雷亚尔', '皇家社会', '西班牙人'),
            '意甲' => array('尤文图斯', 'AC米兰', '国际米兰', '罗马', '那不勒斯', '拉齐奥', '亚特兰大', '佛罗伦萨'),
            '德甲' => array('拜仁慕尼黑', '多特蒙德', 'RB莱比锡', '勒沃库森', '法兰克福', '门兴格拉德巴赫', '科隆', '美因茨'),
            '法甲' => array('巴黎圣日耳曼', '马赛', '里昂', '里尔', '摩纳哥', '尼斯', '南特', '雷恩'),
            '中超' => array('上海海港', '山东泰山', '广州', '北京国安', '上海申花', '武汉三镇', '浙江队', '成都蓉城'),
            '亚冠' => array('广州队', '上海海港', '山东泰山', '武汉三镇', '横滨水手', '川崎前锋', '全北现代', '蔚山现代')
        );
        
        $matches = array();
        $today = date('Y-m-d');
        $match_number = 1;
        
        for ($i = 0; $i < 6; $i++) {
            $league = $leagues[array_rand($leagues)];
            $team_list = $teams[$league];
            shuffle($team_list);
            $home_team = $team_list[0];
            $away_team = $team_list[1];
            
            $match_time = date('H:i', strtotime('+' . rand(13, 22) . ':00'));
            
            $matches[] = array(
                'id' => uniqid('match_'),
                'number' => $match_number++,
                'date' => $today,
                'time' => $match_time,
                'league' => $league,
                'home_team' => $home_team,
                'away_team' => $away_team,
                'home_rating' => rand(60, 95),
                'away_rating' => rand(60, 95)
            );
        }
        
        return $matches;
    }
    
    public function get_leagues() {
        return array('英超', '西甲', '意甲', '德甲', '法甲', '中超', '亚冠');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit