soapclient调用webservice接口

1.开启soap支持,在php.ini中去除extension=php_soap.dll之前的‘;’
2.掉用页面
header('Content-Type: text/html; charset=UTF-8');
$client = new SoapClient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL');
$parm=array('mobileCode'=>'13782149159','userID'=>'');
$result=$client->getMobileCodeInfo($parm);
$result=get_object_vars($result);   //将stdclass object转换为array,这个比较重要了
echo "你的手机卡信息:".$result['getMobileCodeInfoResult'];
?>

function soapclient($para)
{
global $soap_server;
global $db,$tablepre;
try 
{
$client = new SoapClient($soap_server);
$client->decode_utf8=false;
$client->xml_encoding='utf-8';      
$parameters = array('datacontext' => $para);
$result = $client->Commnuication($parameters);
$response = get_object_vars($result);
$response = $response['CommnuicationResult'];

//$sql = "insert into {$tablepre}soaplogs(soaptype,request,response,dateline,requestip) values('client','".addslashes($para)."','".addslashes($response)."','".time()."','$soap_server')";
//$db->query($sql);
unset($client);
    return $result;

catch (SoapFault $fault)
{
    $array = array("Error"=> $fault->faultcode,"String" => $fault->faultstring);
    return $array;
}
}

你可能感兴趣的:(php)