httpGet('showapi_expInfo',$querys); return json_decode($data,true); } /** * @param $url * @param $query * @return bool|string */ private function httpGet($url,$query) { $headers = array(); array_push($headers, "Authorization:APPCODE " . $this->appcode); $url = $this->host . $url . '?' . $query; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$".$this->host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $res = curl_exec($curl); curl_close($curl); return $res; } function curlPost($url, $post_data = array(), $timeout = 5, $data_type = "") { //支持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, '', '&'); $post_string = urldecode($post_string); } $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_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($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 $result = curl_exec($ch); curl_close($ch); return $result; } }