PHP类封装发送POST请求

<?php
/**
* 功能:Curl外部资源请求函数封装
*/

function postUrl($url,$data=[]){
/*
$url - 指向URL连接
$data - 提交POST数据
*/
$ch=curl_init();
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($data));
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$response=curl_exec($ch);
curl_close($ch);
$result = json_decode($response,true);

return $result;
} #发送POST请求