SOAP在PHP

问题描述:

XML转换我需要生成以下XML与SOAP:SOAP在PHP

    ... 
       <InternationalShippingServiceOption> 
         <ShippingService>StandardInternational</ShippingService> 
         <ShippingServiceCost currencyID="USD">39.99</ShippingServiceCost> 
         <ShippingServicePriority>1</ShippingServicePriority> 
         <ShipToLocation>CA</ShipToLocation> 
        </InternationalShippingServiceOption> 
        ... 

所以我在PHP以下SOAP数组做到这一点:

$params = array(
     'InternationalShippingServiceOption' => array(
      'ShippingService'=>'StandardInternational', 
      'ShippingServiceCost'=>39.99, 
      'ShippingServicePriority'=>1, 
      'ShipToLocation'=>'CA', 
     ) 
    ) 
$client = new eBaySOAP($session); //eBaySOAP extends SoapClient 
$results = $client->AddItem($params); 

一切都很正常,除非我不在XML中的ShippingServiceCost标记中生成currencyID =“USD”属性。我该怎么做呢?

+0

是不是想直,增加更多信息 – Jonah 2010-01-02 19:53:32

您不需要使用SoapVar。这个工程(至少对我来说):

$params = array(
     'InternationalShippingServiceOption' => array(
      'ShippingService'=>'StandardInternational', 
      'ShippingServiceCost' => array('_' => 39.99, 'currencyID' => 'USD') 
      'ShippingServicePriority'=>1, 
      'ShipToLocation'=>'CA', 
     ) 
    ) 

我在PayPal SOAP API中使用了这种技术。

+0

如果你不介意,我有一个关于PayPal SOAP API的问题。你如何设置'版本'?当我设置它时,标记变为'xsd:string'而不是'Version'。更多信息在这里http://stackoverflow.com/questions/3105577/simple-php-soapclient-example-for-paypal-needed 谢谢! – Jonah 2010-06-24 18:19:40

为什么,我很高兴你问。我今天就解决了这个问题。

$shippingsvccostwithid = new SoapVar(array('currencyID' => $whatever),SOAP_ENC_OBJECT, 'ShippingServiceCost', 'https://your.namespace.here.com/'); 
$params = array("InternationalShippingServiceOption" => array(
    "ShippingService" => "StandardInternational", 
    "ShippingServiceCost" => $shippingsvccostwithid, 
    "ShippingServicePriority" => 1, 
    "ShipToLocation" => "CA" 
); 

然后继续照常。

如果您需要任何帮助,请让我知道。