-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClient.php
45 lines (37 loc) · 975 Bytes
/
Client.php
1
<?phpnamespace Helper;/** * Class Client * curl发送get|post请求 * @package Helper */class Client{ public static function curl($uri, $data = FALSE, $timeOut = 30, $is_post = 0) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, $is_post); curl_setopt($ch, CURLOPT_URL, $uri); if(false != $data){ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); } curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $r = curl_exec($ch); $result = json_decode ($r ,true); if($result){ if($result['status']) { return $result['data']; } else { return false; } }else{ return $r; } }}