soapclient調用webservice接口

1.開啓soap支持,在php.ini中去除extension=php_soap.dll之前的‘;’
2.掉用頁面
<?php
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;
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章