PHP - 调用 webservice 接口 - php 5.4 以上
requestWsdl.php
<?php
header('content-type:text/html;charset=utf-8');
$ip = $_RESQUEST['ip'];
$function = $_REQUEST['function'];
$param = $_REQUEST['param'];
$res = new WSDL();
$res->getData($ip, $function, $param);
class WSDL{
public function __construct(){
}
public function getData($ip, $function, $param = array()){
try {
$client = new SoapClient('http://' . $ip . '/xxx/Webservice?wsdl',
array('encoding' => 'UTF-8'));
$result = $client->{$function}($param);
$result = get_object_vars($result);
print_r($result);
} catch (SoapFault $exception) {
print_r($exception);
}
}
public function getFunctions($ip){
$client = new SoapClient('http://' . $ip . '/xxx/Webservice?wsdl',
array('encoding' => 'UTF-8'));
$functions = $client->__getFunctions();
print_r($functions);
}
public function getTypes($ip){
$client = new SoapClient('http://' . $ip . '/xxx/Webservice?wsdl', array('encoding' => 'UTF-8'));
$types = $client->__getTypes();
print_r($types);
}
}
data.php.js
function getWsdl() {
var param = {
'id': 6,
'name': 'xx'
}
$.ajax({
type: 'POST',
url: 'requestWsdl.php',
data: {
ip: '7.7.8.8',
function :'dataList',
param: param
},
success: function(data) {
console.log(data);
}
});
}
需要开启soap扩展