【发布时间】:2014-09-26 05:47:23
【问题描述】:
我正在开发亚马逊 MWS,并尝试使用 GetMatchingProductForId 从 SKU 获取产品详细信息。我得到的回应是:
SimpleXMLElement Object
(
[GetMatchingProductForIdResult] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Id] => VYPL039_$P
[IdType] => SellerSKU
[status] => Success
)
[Products] => SimpleXMLElement Object
(
[Product] => SimpleXMLElement Object
(
[Identifiers] => SimpleXMLElement Object
(
[MarketplaceASIN] => SimpleXMLElement Object
(
[MarketplaceId] => A21TJRUUN4KGV
[ASIN] => B00NA3ZMKM
)
)
[AttributeSets] => SimpleXMLElement Object
(
)
[Relationships] => SimpleXMLElement Object
(
)
[SalesRankings] => SimpleXMLElement Object
(
)
)
)
)
[ResponseMetadata] => SimpleXMLElement Object
(
[RequestId] => 9e893248-adaf-43a1-bcae-70f62b6888c7
)
)
cURL 请求:
$url = "https://mws.amazonservices.in/Products/2011-10-01" . '?' . $url_string . "&Signature=" . $signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
//echo $url;exit;
$responseDoc = new DOMDocument();
$responseDoc->loadXML($response);
$response = simplexml_import_dom($responseDoc);
echo '<pre>';
print_r($response);
echo '</pre>';
exit;
但是为什么响应少了,但是当我在浏览器中运行 url 时,它给了我完整的响应,如下所示:-
<GetMatchingProductForIdResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetMatchingProductForIdResult Id="VYPL039_$P" IdType="SellerSKU" status="Success">
<Products xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Product>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId>
<ASIN>B00NA3ZMKM</ASIN>
</MarketplaceASIN>
</Identifiers>
<AttributeSets>
<ns2:ItemAttributes xml:lang="en-IN">
<ns2:Binding>Apparel</ns2:Binding>
<ns2:Brand>Vivekananda Youth Connect</ns2:Brand>
<ns2:Department>womens</ns2:Department>
<ns2:Feature>Category :Clothing</ns2:Feature>
<ns2:Feature>Sleeves : Half</ns2:Feature>
<ns2:Feature>Trends : Printed</ns2:Feature>
<ns2:Label>Vivekananda Youth Connect</ns2:Label>
<ns2:Manufacturer>Vivekananda Youth Connect</ns2:Manufacturer>
<ns2:MaterialType>Cotton</ns2:MaterialType>
<ns2:PackageDimensions>
<ns2:Height Units="inches">2.00</ns2:Height>
<ns2:Length Units="inches">15.00</ns2:Length>
<ns2:Width Units="inches">12.00</ns2:Width>
<ns2:Weight Units="pounds">0.77</ns2:Weight>
</ns2:PackageDimensions>
<ns2:PartNumber>VYPL039_$P</ns2:PartNumber>
<ns2:ProductGroup>Apparel</ns2:ProductGroup>
<ns2:ProductTypeName>SHIRT</ns2:ProductTypeName>
<ns2:Publisher>Vivekananda Youth Connect</ns2:Publisher>
<ns2:SmallImage>
<ns2:URL>
http://g-ecx.images-amazon.com/images/G/31/x-site/icons/no-img-sm._V138359930_.gif
</ns2:URL>
<ns2:Height Units="pixels">40</ns2:Height>
<ns2:Width Units="pixels">60</ns2:Width>
</ns2:SmallImage>
<ns2:Studio>Vivekananda Youth Connect</ns2:Studio>
<ns2:Title>
Vivekananda Youth Connect Happiness Mantra Womens Tshirt_VYPL039_$P
</ns2:Title>
</ns2:ItemAttributes>
</AttributeSets>
<Relationships>
<ns2:VariationChild>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId>
<ASIN>B00NA4AFN0</ASIN>
</MarketplaceASIN>
</Identifiers>
<ns2:Color>Orange</ns2:Color>
<ns2:Size>36</ns2:Size>
</ns2:VariationChild>
<ns2:VariationChild>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId>
<ASIN>B00NA4AKPI</ASIN>
</MarketplaceASIN>
</Identifiers>
<ns2:Color>Orange</ns2:Color>
<ns2:Size>38</ns2:Size>
</ns2:VariationChild>
<ns2:VariationChild>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A21TJRUUN4KGV</MarketplaceId>
<ASIN>B00NA4AOWC</ASIN>
</MarketplaceASIN>
</Identifiers>
<ns2:Color>Orange</ns2:Color>
<ns2:Size>40</ns2:Size>
</ns2:VariationChild>
</Relationships>
<SalesRankings/>
</Product>
</Products>
</GetMatchingProductForIdResult>
<ResponseMetadata>
<RequestId>161416fd-f047-4b13-93d5-27df3f428c5a</RequestId>
</ResponseMetadata>
</GetMatchingProductForIdResponse>
编辑:-
我现在已将响应格式更改为 SimpleXMLElement::asXML :
$url = "https://mws.amazonservices.in/Products/2011-10-01" . '?' . $url_string . "&Signature=" . $signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
$parsed_xml = simplexml_load_string($response);
$response = $parsed_xml->asXML();
但是$response 什么也没返回。
【问题讨论】:
-
@hardiksolanki 感谢您的回复,但正如那篇文章所暗示的那样,我使用了 SimpleXMLElement::asXML 但它什么也没返回,请参阅我的编辑
-
是的,我知道答案已经存在,但它并没有解决我的问题,所以我在这里提出了一个新问题
标签: php curl amazon amazon-mws