我正在尝试构建订单更新程序,以便将它们设置为已发货。我使用了MarketplaceWebService_Model_SubmitFeedRequest并修改了SubmitFeedSample.php 以下代码不会更新发货的订单,并且输出对修复错误不是很有帮助
<?php
error_reporting(E_ALL); // turn on all errors, warnings and notices for easier debugging
include_once ('config.php');
if(!isset($_GET['carrier']) or !isset($_GET['tracking']) or !isset($_GET['amazon_id']))
die("parameters not present");
$carrier = $_GET['carrier'];
$tracking = $_GET['tracking'];
$amazon_id = $_GET['amazon_id'];
// United States:
$serviceUrl = "https://mws.amazonservices.com";
// United Kingdom
//$serviceUrl = "https://mws.amazonservices.co.uk";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
$config,
APPLICATION_NAME,
APPLICATION_VERSION);
$date = date(DATE_FORMAT);
$feed = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>__removed__</MerchantIdentifier>
</Header>
<MessageType>OrderFulfillment</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<OrderFulfillment>
<AmazonOrderID>$amazon_id</AmazonOrderID>
<FulfillmentDate>$date</FulfillmentDate>
<FulfillmentData>
<CarrierName>$carrier</CarrierName>
<ShippingMethod>Standard</ShippingMethod>
<ShipperTrackingNumber>$tracking</ShipperTrackingNumber>
</FulfillmentData>
</OrderFulfillment>
</Message>
</AmazonEnvelope>
EOD;
echo $feed;
$marketplaceIdArray = array("Id" => array('ATVPDKIKX0DER'));
$feedHandle = @fopen('php://temp', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
$parameters = array (
'Merchant' => MERCHANT_ID,
'MarketplaceIdList' => $marketplaceIdArray,
'FeedType' => '_POST_ORDER_FULFILLMENT_DATA_',
'FeedContent' => $feedHandle,
'PurgeAndReplace' => false,
'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true)),
'MWSAuthToken' => AWS_SECRET_ACCESS_KEY
);
rewind($feedHandle);
$request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);
$feedHandle = @fopen('php://memory', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
$request = new MarketplaceWebService_Model_SubmitFeedRequest();
$request->setMerchant(MERCHANT_ID);
$request->setMarketplaceIdList($marketplaceIdArray);
$request->setFeedType('_POST_PRODUCT_DATA_');
$request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true)));
rewind($feedHandle);
$request->setPurgeAndReplace(false);
$request->setFeedContent($feedHandle);
$request->setMWSAuthToken(AWS_SECRET_ACCESS_KEY);
rewind($feedHandle);
invokeSubmitFeed($service, $request);
@fclose($feedHandle);
function invokeSubmitFeed(MarketplaceWebService_Interface $service, $request)
{
try {
$response = $service->submitFeed($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
echo(" SubmitFeedResponse\n");
if ($response->isSetSubmitFeedResult()) {
echo(" SubmitFeedResult\n");
$submitFeedResult = $response->getSubmitFeedResult();
if ($submitFeedResult->isSetFeedSubmissionInfo()) {
echo(" FeedSubmissionInfo\n");
$feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo();
if ($feedSubmissionInfo->isSetFeedSubmissionId())
{
echo(" FeedSubmissionId\n");
echo(" " . $feedSubmissionInfo->getFeedSubmissionId() . "\n");
}
if ($feedSubmissionInfo->isSetFeedType())
{
echo(" FeedType\n");
echo(" " . $feedSubmissionInfo->getFeedType() . "\n");
}
if ($feedSubmissionInfo->isSetSubmittedDate())
{
echo(" SubmittedDate\n");
echo(" " . $feedSubmissionInfo->getSubmittedDate()->format(DATE_FORMAT) . "\n");
}
if ($feedSubmissionInfo->isSetFeedProcessingStatus())
{
echo(" FeedProcessingStatus\n");
echo(" " . $feedSubmissionInfo->getFeedProcessingStatus() . "\n");
}
if ($feedSubmissionInfo->isSetStartedProcessingDate())
{
echo(" StartedProcessingDate\n");
echo(" " . $feedSubmissionInfo->getStartedProcessingDate()->format(DATE_FORMAT) . "\n");
}
if ($feedSubmissionInfo->isSetCompletedProcessingDate())
{
echo(" CompletedProcessingDate\n");
echo(" " . $feedSubmissionInfo->getCompletedProcessingDate()->format(DATE_FORMAT) . "\n");
}
}
}
if ($response->isSetResponseMetadata()) {
echo(" ResponseMetadata\n");
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
echo(" RequestId\n");
echo(" " . $responseMetadata->getRequestId() . "\n");
}
}
echo(" ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebService_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
输出:
<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>__removed__</MerchantIdentifier>
</Header>
<MessageType>OrderFulfillment</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<OrderFulfillment>
<AmazonOrderID>__removed__</AmazonOrderID>
<FulfillmentDate>2015-10-21T05:31:42Z</FulfillmentDate>
<FulfillmentData>
<CarrierName>USPS</CarrierName>
<ShippingMethod>Standard</ShippingMethod>
<ShipperTrackingNumber>__removed__</ShipperTrackingNumber>
</FulfillmentData>
</OrderFulfillment>
</Message>
</AmazonEnvelope>Service Response
=============================================================================
SubmitFeedResponse
SubmitFeedResult
FeedSubmissionInfo
FeedSubmissionId
50021016729
FeedType
_POST_PRODUCT_DATA_
SubmittedDate
2015-10-21T10:31:43Z
FeedProcessingStatus
_SUBMITTED_
ResponseMetadata
RequestId
eb4319ef-edb4-4cf0-a164-9da01296ce2e
ResponseHeaderMetadata: RequestId: eb4319ef-edb4-4cf0-a164-9da01296ce2e, ResponseContext: bPNioZ3TY8tyIH72RFRXCx3QD/bDztb0+EgK2VXrIYMkqS0Gfr/QIBe/jInWTsxipz84AiRukcII S5iwcdqjcFDPGtZKbFhC,KkCctQH4ZBZdtAAY1kox95v8pbq2e48qbK3WLh364tfY7qkCUIZEZgPgF6GE1VGsYNdMVK+JAIbR L/G1jOETXQ==, Timestamp: 2015-10-21T10:31:42.823Z
答案 0 :(得分:0)
好的,我找到了。 $请求 - &GT; setFeedType( '_ POST_PRODUCT_DATA_'); 错了,必须换成 _POST_ORDER_FULFILLMENT_DATA _
很棒的样品......:D