首先php环境需要开启
extension=php_soap.dll
然后看下确保phpinfo中soap是否已连接。
接下来就是最关键的代码要怎么写了?废话不多说直接上代码。
public function sendserve($phone='',$pwd='',$pphone=''){
$xmldata='<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AddCloudUser xmlns="http://tempuri.org/">
<phone>'.$phone.'</phone>
<pwd>'.$pwd.'</pwd>
<pphone>'.$pphone.'</pphone>
</AddCloudUser>
</soap:Body>
</soap:Envelope>';
header("text/xml; charset=utf-8");
$wsdl = 'http://47.***.131.79:8000/WebServiceApp.asmx?wsdl';
$client = new \SoapClient($wsdl);
$result = $client->__doRequest($xmldata,$wsdl,'http://tempuri.org/AddCloudUser',1,0);
$xml=simplexml_load_string($result);//xml格式化
$res = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')->children('http://tempuri.org/');
$result=(self::object_array($res));
if(isset($result['AddCloudUserResponse']['AddCloudUserResult']['string'])){
return $result['AddCloudUserResponse']['AddCloudUserResult']['string'];
} else{
return -1;
}
}
private function object_array($array) {
if(is_object($array)) {
$array = (array)$array;
} if(is_array($array)) {
foreach($array as $key=>$value) {
$array[$key] = self::object_array($value);
}
}
return $array;
}