PHP 中的 SOAP 到 XML 转换

发布于 2024-08-16 12:06:38 字数 1120 浏览 10 评论 0原文

我需要使用 SOAP 生成以下 XML:

                    ...
                <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);

一切都很好,除了我没有在 ShippingServiceCost 标记中生成 currencyID="USD" 属性在 XML 中。我该怎么做?

I need to generate the following XML with SOAP:

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

So I have the following SOAP array in PHP to do this:

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

Everything works great, except I am not generating the currencyID="USD" attribute in the ShippingServiceCost tag in the XML. How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无可置疑 2024-08-23 12:06:38

您不需要使用 SoapVar。这有效(至少对我来说):

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

我正在将这种技术与 PayPal SOAP API 一起使用。

You don't need to use SoapVar. This works (for me at least):

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

I'm using this technique with the PayPal SOAP API.

与往事干杯 2024-08-23 12:06:38

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

$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"
);

然后继续正常。

如果您需要更多帮助,请告诉我。

Why, I am glad you asked. I just solved this today.

$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"
);

And then continue as normal.

Please let me know if you need any more help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文