//客户端代码
$url = '接口地址';
$post_data = array(
'key'=> 'value',
'key2'=>'value',
'key3'=>'value',
);
$post_data= json_encode($post_data);//转Json
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); //设置超时
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length:' . strlen($post_data))); //设置http传json数据的header
curl_setopt($ch, CURLOPT_POSTFIELDS , $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
//服务器端
$phpInput = file_get_contents('php://input'); //$input是传过来的json字符串
$data = json_decode($phpInput,true); //将json字符串转为php数组
http://www.php.cn/php-weizijiaocheng-393305.html