PHP SoapClient – 具有相同密钥的多个属性
发布时间:2020-12-13 16:44:59 所属栏目:PHP教程 来源:网络整理
导读:我正在使用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/soa
我正在使用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> 我已经研究过一堆,包括下面的内容,并且认为我有一个答案.但是,它不起作用.这就是我正在做的事情: foreach ($attributes as $key => $value) { $obj = array('AttributeID' => $key,'Value' => $value); $attrs[] = $obj; } $final_attrs = array('ContactProfileAttribute' => $attrs); $params = array( 'WSContact' => array( 'EmailAddress' => $email,'ListID' => $listId,array('ContactProfileAttribute' => $attrs) ),'ProfileUpdateType' => 'Overwrite','ExternalEventIDs' => "",'OverrideUnsubscribe' => TRUE,); try { $rest = $soapClient->SetContact($params); ... 当我打印出阵列时,我明白了: Array ( [WSContact] => Array ( [EmailAddress] => xxx@example.com [ListID] => 26444 [0] => Array ( [ContactProfileAttribute] => 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> (注意:没有ContactProfileAttribute) 参考: > SoapClient: how to pass multiple elements with same name? 解决方法
ContactProfileAttribute元素是一个太深的级别.尝试:
$params = array( 'WSContact' => array( 'EmailAddress' => $email,'ContactProfileAttribute' => $attrs ),); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- WampServer搭建php环境时遇到的问题汇总
- php教程 插件机制在PHP中实现方案
- php – 这个代码示例中的$loop做了什么?
- php – 如何将TWIG输出渲染为变量供以后使用(sym
- PHP实现的英文名字全拼随机排号脚本
- func_num_args,func_get_arg和func_get_args从ph
- php – Zend Form Edit和Zend_Validate_Db_NoRec
- Codeforces Round #295 (Div. 1) C. Pluses ever
- php – 使用cURL请求instagram api acces令牌
- php – 在Websocket握手上使用会话数据
热点阅读