PHP封装CURL类请求阿里云测试接口

/**
 * 调用腾讯 IM
 * @param $url
 * @param $post
 * @return bool|mixed
 */
if(!function_exists('get_client_curl_live')) {
    function get_client_curl_live($url, $post) {
        if (!is_string($url)) return false;
        if(empty($post)){
            $data = json_encode($post, JSON_FORCE_OBJECT);
        }else{
            $data = json_encode($post);
        }
        $header[] = 'Content-Type: application/json';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    //设置SSL验证
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    //是否检测服务器的域名与证书上的是否一致
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_URL, $url);                        //设置链接
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);          //设置是否返回信息
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $data = curl_exec($ch);
        curl_close($ch);
        return json_decode(trim($data,chr(239).chr(187).chr(191)),true);
    }
}

  

你可能感兴趣的:(PHP封装CURL类请求阿里云测试接口)