我正在使用 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)
引用:
最佳答案
ContactProfileAttribute 元素太深一层。尝试:
$params = array(
'WSContact' => array(
'EmailAddress' => $email,
'ListID' => $listId,
'ContactProfileAttribute' => $attrs
),
'ProfileUpdateType' => 'Overwrite',
'ExternalEventIDs' => "",
'OverrideUnsubscribe' => TRUE,
);
关于PHP SoapClient - 具有相同键的多个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10352499/
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我有这个html标记:我想得到这个:我如何使用Nokogiri做到这一点? 最佳答案 require'nokogiri'doc=Nokogiri::HTML('')您可以通过xpath删除所有属性:doc.xpath('//@*').remove或者,如果您需要做一些更复杂的事情,有时使用以下方法遍历所有元素会更容易:doc.traversedo|node|node.keys.eachdo|attribute|node.deleteattributeendend 关于ruby-Nokog