PHP
  • Introduction
  • PHPMailer
  • UploadFile
  • PHP link MySQL to insert
  • rand功能
  • Create GUID by random
  • Coding problem
  • PHP+MySQL樹狀圖
  • JWT(Json Web Token)
  • 小功能
    • array_push
    • array_chunk
  • 遞迴
  • 生成json
  • 註解方式
  • Call API
  • google url shortener
  • 身分證字號驗證
  • google maps api 取兩點路線規劃的距離
  • 兩點座標的直線距離
  • 將傳入的陣列重新根據某個欄位做排序
  • 抓取最準的IP,從近到遠做判斷
  • 利用curl推播ios,用ios的token
  • 在local端onServer
Powered by GitBook
On this page

Call API

Previous註解方式Nextgoogle url shortener

Last updated 5 years ago

Was this helpful?

CtrlK

Was this helpful?

    /**
     * Curl模組化使用
     * @param type array $post 傳送資料
     * @param type string $route 傳送route
     * @return array or null
     */
    public static function curlModule ($post
,
$route){
try {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $route,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode(json_encode($post)),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new \Exception($err);
} else {
return \App\library\Commontools::ConvertStringToArray($response);
}
} catch(\Exception $ex) {
CommonTools::writeErrorLogByException($ex);
return false;
}
}