最近在做跟华为esdk服务通信的项目,esdk提供了两种方法,一种是soap,一种是native,关于native,因为是跟java语言通信交互,php需要安装一个phpjavabriage的扩展,我倒是安装成功了,但是不知道怎么用,只能遗憾的放弃了
最后只好选择了soap的这钟通信方式,我用的是php 5新带的扩展,soapcelient,关于怎么使用我就不多说了网上有很多例子,我就直接把代码贴出来了
<?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>标签的
感觉快要崩溃的时候,终于找到了,一个方法就是下面的方法:
$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>