/**
* @param $uri //webservice 地址
* @param $xml //xml主体
* @param $fuc //方法
* @param $data //请求参数
* @return false
*
*/
public function sendSoap($uri, $xml,$fuc,$data)
{
ini_set("soap.wsdl_cache_enabled", 0);
libxml_disable_entity_loader(false);
$class_name = __CLASS__;
try
{
$soap = new \SoapClient($uri, ['soap_version' => SOAP_1_2, "trace" => 1,'cache_wsdl' => 0, 'connection_timeout' => 10]);
$soap->__setLocation($uri);
logMessage('【SOAP请求:】' . $xml , $class_name);
switch ($fuc)
{
case 'GetClinicItem':
// 调用函数
$result_xml = $soap->__soapCall($fuc, []);//调用方式2
logMessage('【SOAP返回:】' . $result_xml->GetClinicItemResult, $class_name);
return $result_xml->GetClinicItemResult;
break;
case 'GetClinicItemDetail':
// 调用函数
$result_xml = $soap->__soapCall($fuc, $data);//调用方式2
logMessage('【SOAP返回:】' . $result_xml->GetClinicItemDetailResult, $class_name);
return $result_xml->GetClinicItemDetailResult;
break;
}
}
catch (\SoapFault $fault)
{
logMessage('【SoapFault:】' . $fault->getMessage(), $class_name);
return false;
}
catch (\Exception $exception)
{
logMessage('【SOAP报错:】' . $exception->getMessage(), $class_name);
return false;
}
}
$xml =<<<XML <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/"> <soapenv:Header/>
<soapenv:Body>
<tem:GetClinicItem/> </soapenv:Body> </soapenv:Envelope> XML;
$result_xml = $this->sendSoap([webservice地址],
$xml,[方法名],[传参]);
传参是个二位数组 例如:
$data=[['节点名称'=>'val']];
有莫名其秒的报错时,可以加一下这两个配置在请求前
ini_set("soap.wsdl_cache_enabled", 0);
libxml_disable_entity_loader(false);