php 调用 java 接口

php 需要开启 curl模块

/*
* HTTP 请求函数封装
*/
function http_request_cloudzone($url, $data){
//var_dump($url."test");
if(!$url){
return "";
}

$ch = curl_init ();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //禁用证书
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_HEADER, 0); //头文件信息做数据流输出
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt ($ch, CURLOPT_POST, 1); //启用POST提交
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$output = curl_exec ($ch);
curl_close ($ch);

return json_decode($output, true);
}

// 请求获取登陆用户信息
// http://localhost/wiki/test.php?userId=71D68F2D8C780B6D785F392ED024B701359CBF3CCBDB25D5&appId=CNGDLG0200000000000&interfacesURL=http://192.168.102.114/cloudzone/
// {"appId":"CNGDLG0200000000000", "userId":"71D68F2D8C780B6D785F392ED024B701359CBF3CCBDB25D5"}"

// rsp { ["appInfo"]=> array(3) { ["appId"]=> string(19) "CNGDLG0200000000000" ["webUrl"]=> string(36) "http://192.168.113.127/wiki/test.php" ["webUrlWan"]=> string(36) "http://192.168.113.127/wiki/test.php" } ["serverResult"]=> array(2) { ["resultCode"]=> int(0) ["resultMessage"]=> string(6) "成功" } ["teacherClassList"]=> array(0) { } ["token"]=> string(112) "183cfa43aa68d5b3c393753e173e914626b859e14ee40df68ba289324d8706d7679be1e96c2a3a2e333d6972bd521b9b4fb45e0d6dd1e2ee" ["userInfo"]=> array(11) { ["encryptedUserId"]=> string(48) "71D68F2D8C780B6D785F392ED024B701359CBF3CCBDB25D5" ["gender"]=> string(0) "" ["lastModifyTime"]=> string(19) "2016-02-29 09:49:02" ["loginName"]=> string(4) "test" ["schoolId"]=> string(19) "CNGDLG0600000000001" ["schoolName"]=> string(6) "学校" ["schoolSection"]=> string(14) "PRIMARY_SCHOOL" ["staticPassword"]=> string(16) "a83a68c6e9967731" ["userAccount"]=> string(19) "CNGDLG0600000000025" ["userName"]=> string(4) "test" ["userType"]=> string(1) "2" } ["xmppInfo"]=> array(3) { ["xmppHeartbeatPort"]=> string(4) "9090" ["xmppIp"]=> string(22) "http://192.168.102.114" ["xmppServer"]=> string(34) "http://http://192.168.102.114:9090" } }
// 新增TW教育云鉴权同步登陆入口方法
function dotwauthentication(){

if(!$this->get['2'] || !$this->get['3'] || !$this->get['4']){
$this->header("");
}
$url = $this->get['2'];
$data['userId'] = $this->get['3'];
$data['appId'] = $this->get['4'];
$data_json = json_encode($data);
$url = $url."/ClientApi/getAuthenticationInfo";

$output_json = $this->http_request_cloudzone($url, $data_json);

if($output_json){
$rsp_code = $output_json["serverResult"]["resultCode"];

if($rsp_code == 0){
// 请求成功
$twuserid= $output_json["userInfo"]["userAccount"];
$twuserpwd= $output_json["userInfo"]["staticPassword"];
$twusername= $output_json["userInfo"]["userName"];

$des_java_c = new DES_JAVA();
$twuserpwd= $des_java_c->decrypt($twuserpwd);

$this->dotwsysuser($twusername, $twuserid, $twuserpwd);
}else{
//请求失败
$this->header('');
}
}else{
//请求失败
$this->header('');
}
}

原文地址:https://www.cnblogs.com/xiangjune/p/5238299.html