soap header身份認證 不帶ns標籤

最近在作跟華爲esdk服務通訊的項目,esdk提供了兩種方法,一種是soap,一種是native,關於native,由於是跟java語言通訊交互,php須要安裝一個phpjavabriage的擴展,我卻是安裝成功了,可是不知道怎麼用,只能遺憾的放棄了 php

最後只好選擇了soap的這鐘通訊方式,我用的是php 5新帶的擴展,soapcelient,關於怎麼使用我就很少說了網上有不少例子,我就直接把代碼貼出來了 java

<?php
 $client = new SoapClient("http://127.0.0.1:8086/esdk/services/ucProfessionalUserProfilePersonList?wsdl");
 //$client = new SoapClient(null, array('uri' => 'http://127.0.0.1:8086', 'location' => 'http://127.0.0.1:8086/esdk/services/ucProfessionalUserProfilePersonList', 'trace' => true));
  $auth = array(
        'appId'=>'001280254192',
        'password'=>'BF2CB58A68F684D95A3B78EF8F661C9A4E5B09E82CC8F9CC88CCE90528CAEB27'
		);
  $header = new SoapHeader('http://localhost/soap.php','esdk',$auth,false,SOAP_ACTOR_NEXT);
  $client->__setSoapHeaders($header);
  echo'<pre>';
    print_r($header);
 print_r($client->__getFunctions());
  echo'</pre>';
$param = array('ucAccount' =>'144002');
//$result = $client->__soapCall('getPersonAllAddressBook', array('ucAccount' => $param));
$result = $client->getPersonAllAddressBook($param);

由於esdk必須通過身份驗證,在header裏,一開始的時候 不知道爲何老是驗證失敗,我看帳號和密碼都是正確的,查遍了緣由都找不出問題,後來返回了一下xml代碼($result = $client->getPersonAllAddressBook($param); ),發現,header裏多了一個<ns1>的標籤,找到緣由,新的問題又來了,<ns1>這個標籤該怎麼刪除呢,直接用 __setSoapHeaders()函數確定會是有<ns1>標籤的
感受快要崩潰的時候,終於找到了,一個方法就是下面的方法: app

$h1="<appId>001280254192</appId>";
 $h2="<password>BF2CB58A68F684D95A3B78EF8F661C9A4E5B09E82CC8F9CC88CCE90528CAEB27</password>";
 $var = new SoapVar($h1, XSD_ANYXML); 
 $soapHeader = new SoapHeader("NAME_SPACE", "appId", $var); 
 // second soap header. 
 $var2 = new SoapVar($h2, XSD_ANYXML); 
 $soapHeader2 = new SoapHeader("DIFF_NAME_SPACE", "password", $var2); 
 $client = new SoapClient("http://127.0.0.1:8086/esdk/services/ucProfessionalUserProfileCorpList?wsdl",array('exceptions' => 0,"trace"=>true));
 $headers = array(); 
 $headers[] = $soapHeader; 
 $headers[] = $soapHeader2; 
 // Here my code was just terminating. 
 $client->__setSoapHeaders($headers);
這樣的返回的xml就沒有了那個多餘的<ns1>標籤,認證也終於經過了
不過在這裏,只解決了header裏的標籤問題,那麼xml裏的<body>裏怎麼也是有多餘的標籤的,如今還影響,可是想改仍是很困難,若是有同窗知道怎麼去掉或者修改<body>裏的標籤,請告訴我,能夠直接加我qq 或者個人qq郵箱均可以,在xia無限感謝
固然也能夠直接在評論中回覆  個人qq274480298
 最後我把我返回的xml數據貼出來給你們 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="esdk_uc_professional_server" xmlns:ns2="NAME_SPACE" xmlns:ns3="DIFF_NAME_SPACE"><SOAP-ENV:Header><appId>001280254192</appId><password>BF2CB58A68F684D95A3B78EF8F661C9A4E5B09E82CC8F9CC88CCE90528CAEB27</password></SOAP-ENV:Header><SOAP-ENV:Body><ns1:queryStaffInfo><ucAccount>144002</ucAccount></ns1:queryStaffInfo></SOAP-ENV:Body></SOAP-ENV:Envelope>
相關文章
相關標籤/搜索