php curl操作API介面類完整示例

2022-09-26 05:24:12 字數 1724 閱讀 3915

<?php namespace curl;

/** * created by phpstorm.

* user: administrator

* date: 2017/6/16

* time: 9:54

*/class apiclient

程式設計客棧 $this->requesttype = strtolower($requesttype);

$paramurl = '';

// pathinfo模式

if (!empty($data))

$url = $url .'?'. $paramurl;

} //初始化類中的資料

$this->url = $url;

$this->data = $data;

try;

}catch (exception $e)

curl_setopt($this->curl, curlopt_url, $this->url);

curl_setopt($this->curl, curlopt_returntransfer, 1);

//curl_setopt($this->curl, curlopt_header, 1);

} /**

* [_post 設定get請求的引數]

* @return [type] [description]

*/public function _get()

/*** [_post 設定post請求的引數]

* post 新增資源

* @return [type] [description]

*/public function _post()

/*** [_put 設定put請求]

* put 更新資源

* @return [type] [description]

*/public function _put()

/*** [_delete 刪除資源]

* delete 刪除資源

* @return [type] [description]

*/public function _delete()

/*** [dorequest 執行傳送請求]

* @return [type] [description]

*/public function dorequest()

//傳送頭部資訊

$this->setheader();

//傳送請求方式

switch ($this->requesttype)

//執行curl請求

$info = curl_exec($this->curl);

//獲取curl執行狀態資訊

$this->status = $this->getinfo();

return json_decode($info);

} /**

* 設定傳送的頭部資訊

*/private function setheader()

/*** 生成授權碼

* @return string 授權碼

*/private function setauthorization()

/*** 獲取curl中的狀態資訊

*/public function getinfo()

/*** 關閉curl連線

*/public function __destruct()

php curl 介面請求

通過url獲取頁面資訊 param string url 位址 return string 返回頁面資訊 function get url url 模擬post提交 param string url 位址 param string data 提交的資料 return string 返回結果 func...

檔案操作的主要介面API

朱老師物聯網大講堂 學習筆記 學習乙個作業系統,就是學習如何使用這個作業系統的api,就好像練習乙個新英雄,要學會使用他的技能,並結合召喚師峽谷環境特點,發揮你的實力。操作檔案,得先open,得到檔案描述符,若沒有open成功,無法得到檔案描述符,也就無法操作,在進行read,write等操作後,要...

api介面 php PHP關於API介面例項分享

api就是作業系統留給應用程式的乙個呼叫介面,應用程式通過呼叫作業系統的 api 而使作業系統去執行應用程式的命令 動作 本文主要和大家分享php關於api介面例項,希望能幫助到大家。php生成json資料 json encode value 方法 response.php和testapi.php ...