PHP SoapClient-具有相同密钥的多个属性

PHP SoapClient-具有相同密钥的多个属性,php,soap-client,Php,Soap Client,我正在使用SoapClient,试图为该规范生成一些内容: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

我正在使用SoapClient,试图为该规范生成一些内容:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <WSUser xmlns="http://webservices.listrak.com/v31/">
      <UserName>string</UserName>
      <Password>string</Password>
    </WSUser>
  </soap:Header>
  <soap:Body>
    <SetContact xmlns="http://webservices.listrak.com/v31/">
      <WSContact>
        <EmailAddress>string</EmailAddress>
        <ListID>int</ListID>
        <ContactProfileAttribute>
          <AttributeID>int</AttributeID>
          <Value>string</Value>
        </ContactProfileAttribute>
        <ContactProfileAttribute>
          <AttributeID>int</AttributeID>
          <Value>string</Value>
        </ContactProfileAttribute>
      </WSContact>
      <ProfileUpdateType>NotDefined or Update or Append or Overwrite</ProfileUpdateType>
      <ExternalEventIDs>string</ExternalEventIDs>
      <OverrideUnsubscribe>boolean</OverrideUnsubscribe>
    </SetContact>
  </soap:Body>
</soap:Envelope>
当我打印出数组时,我得到以下结果:

Array
(
    [WSContact] => Array
        (
        [EmailAddress] => xxx@example.com
        [ListID] => 26444
        [0] => Array
            (
                [ContactProfileAttribute] =&gt; Array
                    (
                        [0] => Array
                            (
                                [AttributeID] => 1548948
                                [Value] => 1
                            )

                        [1] => Array
                            (
                                [AttributeID] => 1548953
                                [Value] => John
                            )

                        [2] => Array
                            (
                                [AttributeID] => 1548954
                                [Value] => Doe
                            )

                        [3] => Array
                            (
                                [AttributeID] => 1550052
                                [Value] => 1
                            )

                    )

            )

    )

[ProfileUpdateType] => Overwrite
[ExternalEventIDs] => 
[OverrideUnsubscribe] => 1
)
但是,这最终不会产生预期的结果,而是:

Request = <?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://webservices.listrak.com/v31/">
    <env:Header>
        <ns1:WSUser>
            <ns1:UserName>user</ns1:UserName>
            <ns1:Password>pw</ns1:Password>
        </ns1:WSUser>
    </env:Header>
    <env:Body>
        <ns1:SetContact>
            <ns1:WSContact>
                <ns1:EmailAddress>xxx@example.com</ns1:EmailAddress>
                <ns1:ListID>26444</ns1:ListID>
            </ns1:WSContact>
            <ns1:ProfileUpdateType>Overwrite</ns1:ProfileUpdateType>
            <ns1:ExternalEventIDs></ns1:ExternalEventIDs>
            <ns1:OverrideUnsubscribe>true</ns1:OverrideUnsubscribe>
        </ns1:SetContact>
    </env:Body>
</env:Envelope>
请求=
用户
嗯
xxx@example.com
26444
覆盖
真的
(注意:没有ContactProfile属性)

参考:


ContactProfileAttribute元素太深了一级。尝试:

$params = array(
    'WSContact' => array(
        'EmailAddress' => $email,
        'ListID' => $listId,
        'ContactProfileAttribute' => $attrs
    ),
    'ProfileUpdateType' => 'Overwrite',
    'ExternalEventIDs' => "",
    'OverrideUnsubscribe' => TRUE,
);

该解决方案在我的情况下不起作用:它没有通过WSDL验证,并出现一个错误,表示“ContactProfileAttribute”中缺少某个字段。
$params = array(
    'WSContact' => array(
        'EmailAddress' => $email,
        'ListID' => $listId,
        'ContactProfileAttribute' => $attrs
    ),
    'ProfileUpdateType' => 'Overwrite',
    'ExternalEventIDs' => "",
    'OverrideUnsubscribe' => TRUE,
);