request->param("match_id"); // 获取赛事详细信息 $archives = new Archives(); @$toArray = $archives->alias("archives") ->join("cms_addonproduct" . ' addon', 'addon.id=archives.id', 'LEFT') ->where("archives.id", "eq", $match_id) ->field("archives.title, archives.flag, archives.status, archives.publishtime, archives.id, archives.channel_id, archives.style, addon.content, archives.image, addon.phoneimg, addon.zbf, addon.cbf, addon.bsd, addon.csrs, addon.xsaddress, addon.stime, addon.starttime, addon.endtime, addon.etime, addon.jszn, addon.poster, addon.isopen") ->find() ->toArray(); if (@empty($toArray)) { $this->error("赛事信息不存在"); } // 获取已报名人数 $matchContestant = new MatchContestant(); $toArray['entry_player'] = $matchContestant->where("match_id", $match_id) ->whereIn("status", [1, 2]) ->count("*"); $httpPost = $this->httpPost("118.89.120.104:14859/api/v1/processHtml", http_build_query(['mach_id' => $match_id])); $html = json_decode($httpPost, true); if (empty($html)) { $this->error("服务端错误!"); } $toArray['content'] = $html['data']['html'] ? $html['data']['html'] : $toArray['content']; $toArray['schedule'] = $html['data']['schedule'] ? $html['data']['schedule'] : " "; $toArray['regulation'] = $html['data']['regulation'] ? $html['data']['regulation'] : " "; $toArray['commitment'] = $html['data']['commitment'] ? $html['data']['commitment'] : " "; $toArray['rule'] = $html['data']['rule'] ? $html['data']['rule'] : " "; $this->result("获取成功", $toArray, 1); } public function entry_match() { $token = $this->auth->getToken(); $token_info = \app\common\library\Token::get($token); $expiretime = date("Y-m-d H:i:s", $token_info['expiretime']); $where['member_id'] = $token_info['user_id']; $plyaerinfo = \app\common\model\Players::get($where); if (empty($plyaerinfo) || $plyaerinfo->player_status != 9) { $this->error("你还不是正式的飞手"); } // 获取参与的赛事 $matchContestant = new MatchContestant(); $entry_list = $matchContestant->where("player_id", $plyaerinfo->id) ->select(); if (empty($entry_list)) { $this->error("您还未参加过赛事"); } $key = 0; foreach ($entry_list as $key => $val) { $archives = Archives::get($val->match_id); if (empty($archives)) { unset($entry_list[$key]); continue; } $res_data[$key]['match_title'] = $archives->title; $res_data[$key]['status'] = $val->status; $res_data[$key]['mark'] = $val->mark; $res_data[$key]['player_id'] = $plyaerinfo->id; $res_data[$key]['match_id'] = $val->match_id; $key++; } if (empty($res_data)) { $this->error("您还未参加过赛事"); } $this->result("获取成功", $res_data, 200); } public function getindexmatch() { $res['match_id'] = "413"; $this->result("获取成功", $res); } function curlPost($url, $post_data = array(), $timeout = 5, $header = "", $data_type = "") { $header = empty($header) ? '' : $header; //支持json数据数据提交 if($data_type == 'json'){ $post_string = json_encode($post_data); }elseif($data_type == 'array') { $post_string = $post_data; }elseif(is_array($post_data)){ $post_string = http_build_query($post_data, '', '&'); } $ch = curl_init(); // 启动一个CURL会话 curl_setopt($ch, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 // https请求 不验证证书和hosts curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 //curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置超时限制防止死循环 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); //curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头 $result = curl_exec($ch); // 打印请求的header信息 //$a = curl_getinfo($ch); //var_dump($a); curl_close($ch); return $result; } // 模拟提交数据函数 public function httpPost($url,$data){ $curl = curl_init(); // 启动一个CURL会话 curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 $result = curl_exec($curl); // 执行操作 if (curl_errno($curl)) { return 'Error POST'.curl_error($curl); } curl_close($curl); // 关键CURL会话 return $result; // 返回数据 } }