<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>

                get方法 ~~~php /** * get方法 * @param string $url 地址 * @return string 返回頁面信息 */ function get_url($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); //設置訪問的url地址 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//不輸出內容 $result = curl_exec($ch); curl_close ($ch); return $result; } ~~~ post方法 ~~~ /** * post方法 * @param string $url 地址 * @param string $data 提交的數據 * @return string 返回結果 */ function post_url($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_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); // 模擬用戶使用的瀏覽器 //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自動跳轉 //curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自動設置Referer curl_setopt($curl, CURLOPT_POST, 1); // 發送一個常規的Post請求 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的數據包x curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 設置超時限制 防止死循環 curl_setopt($curl, CURLOPT_HEADER, 0); // 顯示返回的Header區域內容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 執行操作 if(curl_errno($curl)) { echo 'Errno'.curl_error($curl);//捕捉異常 } curl_close($curl); // 關閉CURL會話 return $tmpInfo; // 返回數據 } ~~~ 對象轉化為數組 ~~~ /** * 對象轉化為數組 * @param object $obj 對象 * @return array 數組 */ function object_to_array($obj){ $_arr = is_object($obj) ? get_object_vars($obj) :$obj; foreach ($_arr as $key=>$val){ $val = (is_array($val) || is_object($val)) ? object_to_array($val):$val; $arr[$key] = $val; } return $arr; } ~~~ 數組轉xml ~~~ /** * 數組轉xml * @param string $arr array * @return string XML */ function arrayToXml($arr) { $xml = "<xml>"; foreach ($arr as $key=>$val) { if (is_numeric($val)) { $xml.="<".$key.">".$val."</".$key.">"; } else $xml.="<".$key."><![CDATA[".$val."]]></".$key.">"; } $xml.="</xml>"; return $xml; } ~~~ 封裝 ~~~ /** * 調用api接口 * @param url $apiurl api.muxiangdao.cn/Article/articleList 接口地址 * @param array $param ['status'=>'1','page'=>'2','pageshow'=>'10']; 參數(數組格式) * @param string $format eg:array(arr),object(obj),json;defalut = array 返回數據格式 * @param string $method get or post 請求方法 */ function get_api($apiurl, $param, $format = 'array', $method = 'get'){ if (is_array($param)) { $string = '?'; foreach ($param as $key => $val){ $string .= $key.'='.$val.'&'; } $param = substr($string, 0, -1); } $url = $apiurl.$param; switch (strtolower($method)){ case '':$json = get_url($url);break; case 'get':$json = get_url($url);break; case 'g':$json = get_url($url);break; case 'post':$json = post_url($apiurl,$param);break; case 'p':$json = post_url($apiurl,$param);break; default:$json = get_url($url);break; } $start = strpos($json, '{'); $end = -1*(strlen(strrchr($json, '}'))-1); if ($end) { $json = substr($json, $start, $end); }else { $json = substr($json, $start); } $obj = json_decode($json); $array = object_to_array($obj); $xml = arrayToXml($array); switch ($format){ case 'array':$data = $array;break; case 'arr':$data = $array;break; case 'obj':$data = $obj;break; case 'object':$data = $obj;break; case 'json':$data = $json;break; default:$data = $array; } return $data; } ~~~
                  <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>

                              哎呀哎呀视频在线观看