SoapClient使用PHP将多个参数插入到某些字段中

时间:2016-11-10 22:33:53

标签: php soap soap-client

我正在尝试从以下结构中获取SOAP请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:wseasyrent:wseasyrent">
<soapenv:Header/>
 <soapenv:Body>
   <urn:getcustomersv3>
     <accessid></accessid>
     <er_custcode></er_custcode>
     <er_groupcode></er_groupcode>
     <custcard></custcard>
     <custextid></custextid>
     <custextidorigin></custextidorigin>
     <firstname></firstname>
     <lastname></lastname>
     <zip></zip>
     <city></city>
     <dateofbirth></dateofbirth>
     <telephone></telephone>
     <mobile></mobile>
     <email></email>
     <created_after></created_after>
     <changed_after></changed_after>
     <activity_after></activity_after>
     <maxrows></maxrows>
  </urn:getcustomersv3>

我尝试了很多方法,但都没有工作......这是我的代码的第一部分:

$options = array(
    "trace" => 1,
    "cache_wsdl" => WSDL_CACHE_NONE
);
$client = new SoapClient($WebServiceHost, $options);

尝试数组:

$parr = array(
    'accessid' => 'myPassword',
    'er_custcode' => 'custCode'
);

try {
    $ret = $client->getcustomersv3($parr);
} catch (Exception $e) {        
    $ret = $e->faultstring;
}

数组结果:

  <ns1:getcustomersv3>
      <accessid>Array</accessid>
      <er_custcode></er_custcode>

尝试对象:

$obj = new StdClass();
$obj->accessid = 'myPassword';
$obj->er_custcode = 'custCode';
// or with format:
// $obj[] = new SoapVar('custCode', XSD_STRING, null, null, 'er_custcode' );

try {
    $ret = $client->getcustomersv3(new SoapVar($parm, SOAP_ENC_OBJECT));
} catch (Exception $e) {        
    $ret = $e->faultstring;
}

带对象的结果:

<ns1:getcustomersv3>
   <accessid>
      <accessid>custCode</accessid>
      <er_custcode>myPassword</er_custcode>
   </accessid>
   <er_custcode></er_custcode>

我需要它看起来像是:

<ns1:getcustomersv3>
    <accessid>custCode</accessid>
    <er_custcode>myPassword</er_custcode>

非常感谢!

1 个答案:

答案 0 :(得分:0)

解决方案是逐个插入params:

 $ez_soap = new SoapClient($pageURL,array('trace' => 1));
 $response = $ez_soap->getcustomersv3($params[0],$params[1],'','','','','','','','',$params[2],'','','',$params[3],$params[4],$params[5],$params[6]);