php 调用java 接口

时间:2022-09-30 13:19:23
//请求 Java 接口
$url = "http://192.168.1.105:8081/credit/udun/udunInfo.do";
$post_data = array ("ydOrderId" => $data['ydOrderId']);
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen(json_encode($post_data))
));

$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
var_dump($output);die;