<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ~~~ <?php namespace app\util; /** * 網絡請求類 */ class Http { /** * 發送一個POST請求 * @param string $url 請求URL * @param array $params 請求參數 * @param array $options 擴展參數 * @return mixed|string */ public static function post($url, $params = [], $options = []) { $req = self::sendRequest($url, $params, 'POST', $options); return $req['ret'] ? $req['msg'] : ''; } /** * 發送一個GET請求 * @param string $url 請求URL * @param array $params 請求參數 * @param array $options 擴展參數 * @return mixed|string */ public static function get($url, $params = [], $options = []) { $req = self::sendRequest($url, $params, 'GET', $options); return $req['ret'] ? $req['msg'] : ''; } /** * CURL發送Request請求,含POST和REQUEST * @param string $url 請求的鏈接 * @param mixed $params 傳遞的參數 * @param string $method 請求的方法 * @param mixed $options CURL的參數 * @return array */ public static function sendRequest($url, $params = [], $method = 'POST', $options = []) { $method = strtoupper($method); $protocol = substr($url, 0, 5); $query_string = is_array($params) ? http_build_query($params) : $params; $ch = curl_init(); $defaults = []; if ('GET' == $method) { $geturl = $query_string ? $url . (stripos($url, "?") !== false ? "&" : "?") . $query_string : $url; $defaults[CURLOPT_URL] = $geturl; } else { $defaults[CURLOPT_URL] = $url; if ($method == 'POST') { $defaults[CURLOPT_POST] = 1; $defaults[CURLOPT_POSTFIELDS] = json_encode($params,JSON_UNESCAPED_SLASHES); } else { $defaults[CURLOPT_CUSTOMREQUEST] = $method; $defaults[CURLOPT_POSTFIELDS] = $query_string; } } $defaults[CURLOPT_HEADER] = false; $defaults[CURLOPT_USERAGENT] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.98 Safari/537.36"; $defaults[CURLOPT_FOLLOWLOCATION] = true; $defaults[CURLOPT_RETURNTRANSFER] = true; $defaults[CURLOPT_CONNECTTIMEOUT] = 3; $defaults[CURLOPT_TIMEOUT] = 3; // disable 100-continue curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); if ('https' == $protocol) { $defaults[CURLOPT_SSL_VERIFYPEER] = false; $defaults[CURLOPT_SSL_VERIFYHOST] = false; } curl_setopt_array($ch, (array)$options + $defaults); $ret = curl_exec($ch); $err = curl_error($ch); if (false === $ret || !empty($err)) { $errno = curl_errno($ch); $info = curl_getinfo($ch); curl_close($ch); return [ 'ret' => false, 'errno' => $errno, 'msg' => $err, 'info' => $info, ]; } curl_close($ch); return [ 'ret' => true, 'msg' => $ret, ]; } /** * 異步發送一個請求 * @param string $url 請求的鏈接 * @param mixed $params 請求的參數 * @param string $method 請求的方法 * @return boolean TRUE */ public static function sendAsyncRequest($url, $params = [], $method = 'POST') { $method = strtoupper($method); $method = $method == 'POST' ? 'POST' : 'GET'; //構造傳遞的參數 if (is_array($params)) { $post_params = []; foreach ($params as $k => &$v) { if (is_array($v)) { $v = implode(',', $v); } $post_params[] = $k . '=' . urlencode($v); } $post_string = implode('&', $post_params); } else { $post_string = $params; } $parts = parse_url($url); //構造查詢的參數 if ($method == 'GET' && $post_string) { $parts['query'] = isset($parts['query']) ? $parts['query'] . '&' . $post_string : $post_string; $post_string = ''; } $parts['query'] = isset($parts['query']) && $parts['query'] ? '?' . $parts['query'] : ''; //發送socket請求,獲得連接句柄 $fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80, $errno, $errstr, 3); if (!$fp) { return false; } //設置超時時間 stream_set_timeout($fp, 3); $out = "{$method} {$parts['path']}{$parts['query']} HTTP/1.1\r\n"; $out .= "Host: {$parts['host']}\r\n"; $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; $out .= "Content-Length: " . strlen($post_string) . "\r\n"; $out .= "Connection: Close\r\n\r\n"; if ($post_string !== '') { $out .= $post_string; } fwrite($fp, $out); //不用關心服務器返回結果 //echo fread($fp, 1024); fclose($fp); return true; } /** * 發送文件到客戶端 * @param string $file * @param bool $delaftersend * @param bool $exitaftersend */ public static function sendToBrowser($file, $delaftersend = true, $exitaftersend = true) { if (file_exists($file) && is_readable($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment;filename = ' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check = 0, pre-check = 0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); if ($delaftersend) { unlink($file); } if ($exitaftersend) { exit; } } } } ~~~ ~~~ if (!function_exists('curl_url')) { /** * 獲取當前訪問的完整URL * @return string 返回結果 * @author 牧羊人 * @date 2020-04-21 */ function curl_url() { $pageURL = 'http'; if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on') { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } return $pageURL; } } if (!function_exists('curl_get')) { /** * curl請求(GET) * @param string $url 請求地址 * @param array $data 請求參數 * @return bool|string 返回結果 * @author 牧羊人 * @date 2020-04-21 */ function curl_get($url, $data = []) { // 處理get數據 if (!empty($data)) { $url = $url . '?' . http_build_query($data); } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //這個是重點。 $result = curl_exec($curl); curl_close($curl); return $result; } } if (!function_exists('curl_post')) { /** * curl請求(POST) * @param string $url 請求地址 * @param array $data 請求參數 * @return bool|string 返回結果 * @author 牧羊人 * @date 2020-04-21 */ function curl_post($url, $data = []) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); return $result; } } if (!function_exists('curl_request')) { /** * curl請求(支持get和post) * @param $url 請求地址 * @param array $data 請求參數 * @param string $type 請求類型(默認:post) * @param bool $https 是否https請求true或false * @return bool|string 返回請求結果 * @author 牧羊人 * @date 2020-04-21 */ function curl_request($url, $data = [], $type = 'post', $https = false) { // 初始化 $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // 設置超時時間 curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 是否要求返回數據 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($https) { // 對認證證書來源的檢查 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 從證書中檢查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } if (strtolower($type) == 'post') { // 設置post方式提交 curl_setopt($ch, CURLOPT_POST, true); // 提交的數據 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } elseif (!empty($data) && is_array($data)) { // get網絡請求 $url = $url . '?' . http_build_query($data); } // 設置抓取的url curl_setopt($ch, CURLOPT_URL, $url); // 執行命令 $result = curl_exec($ch); if ($result === false) { return false; } // 關閉URL請求(釋放句柄) curl_close($ch); return $result; } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看