Detailed PHP interface to submit payment butt curl Post manner

In doing payment interface docking when encountered using PHP's curl function implementation Get and Post requests, as detailed below.

$headers = [ "Content-type: application/json;charset='utf-8'", "Accept: application/json", "Cache-Control: no-cache", "Pragma: no-cache" ];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);//当请求https的数据时,会要求证书,这时候,加上以上这两个参数,规避ssl的证书检查
curl_setopt($ch, CURLOPT_TIMEOUT, 60);//设置超时时间
curl_setopt($ch, CURLOPT_POST, TRUE);//设置post方式提交
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post)); //post提交数据,数组格式,键名是name,键值是value
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//CURLOPT_RETURNTRANSFER 不设置 curl_exec返回TRUE 设置 curl_exec返回json(此处) 失败都返回FALSE
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  
$data = curl_exec($ch); 
curl_close($ch);

Guess you like

Origin blog.csdn.net/jeesr/article/details/91445369