class my_curl {
public function
__construct() {
!extension_loaded ( 'curl' ) && exit (
'CURL扩展未加载,程序终止运行' );
header ( 'Content-Type: text/html;
charset=utf-8' );
}
public function go($url,
$vars = '') {
$ch = curl_init ();
$array [CURLOPT_URL] = $url;
$array [CURLOPT_HEADER] = false;
$array [CURLOPT_RETURNTRANSFER] = true;
$array [CURLOPT_FOLLOWLOCATION] = true;
//https请求
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
FALSE);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
false);
if (! empty ( $vars )) {
$postfields = $this->render_postfields ( $vars );
//生成urlcode的url
$array
[CURLOPT_POST] = true;
$array
[CURLOPT_POSTFIELDS] = $postfields;
}
curl_setopt_array ( $ch, $array );
//传入curl参数
$content = curl_exec ( $ch ); //执行
curl_close ( $ch ); //关闭
return $content; //返回
}
protected function
render_postfields($vars) {
$postdata = '';
foreach ( $vars as $key => $values ) {
$postdata
.= $key . "=" . $values . "&";
}
return $postdata;
}
}