PHP post调接口代码
/**
* $url:接口地址
* $data:数组参数
**/
function postData($url, $data) {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
$file_contents = curl_exec ( $ch );
if (curl_errno ( $ch )) {
return 'Errno' . curl_error ( $ch );
}
// echo $file_contents;
curl_close ( $ch );
return $file_contents;
}