Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试将PDF发票上载到Amazon MWS时出现错误:“;上传发票时请仅提供一个有效的市场“;_Php_Curl_Upload_Amazon Mws_Invoice - Fatal编程技术网

Php 尝试将PDF发票上载到Amazon MWS时出现错误:“;上传发票时请仅提供一个有效的市场“;

Php 尝试将PDF发票上载到Amazon MWS时出现错误:“;上传发票时请仅提供一个有效的市场“;,php,curl,upload,amazon-mws,invoice,Php,Curl,Upload,Amazon Mws,Invoice,我目前正在研究如何使用php/curl将我自己的发票pdf文件上传到Amazon MWS: 1.)使用操作:SubmitFeed和FeedType:Upload_VAT_INVOICE将pdf上载到Amazon MWS 这是对FeedSubmissionId的肯定回应 2.)获取Feed提交结果,FeedSubmissionId报告错误79523“上传发票时,请仅提供一个有效市场。” 因此,我假设我的上传工作不正常,但我找不到错误 错误代码在Amazon的PDF文件第21页中描述: 到目前为止,

我目前正在研究如何使用php/curl将我自己的发票pdf文件上传到Amazon MWS: 1.)使用操作:SubmitFeed和FeedType:Upload_VAT_INVOICE将pdf上载到Amazon MWS 这是对FeedSubmissionId的肯定回应

2.)获取Feed提交结果,FeedSubmissionId报告错误79523“上传发票时,请仅提供一个有效市场。”

因此,我假设我的上传工作不正常,但我找不到错误

错误代码在Amazon的PDF文件第21页中描述:

到目前为止,我已经花了两天时间试图解决这个问题,但我在谷歌上找不到任何关于它的信息。希望这里有人能帮我。谢谢

代码如下:

    <?php 
$param = array();
$param['AWSAccessKeyId']   = 'XXXXX'; 
$param['Action']           = 'SubmitFeed';
$param['Merchant']         = 'XXXXX';
$param['FeedType']         = '_UPLOAD_VAT_INVOICE_';//'_POST_ORDER_FULFILLMENT_DATA_';
$param['FeedOptions']      = 'metadata:OrderId='.$amz_order_id.';metadata:TotalAmount='.$TotalAmount.';metadata:TotalVATAmount='.$TotalVATAmount.';metadata:InvoiceNumber='.$InvoiceNumber.';metadata:documenttype=Invoice';
$param['SignatureMethod']  = 'HmacSHA256';
$param['SignatureVersion'] = '2';
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version']          = '2009-01-01';
$param['MarketplaceIdList.Id.1']    = 'A1PA6795UKMFR9';
$param['PurgeAndReplace']   = 'false'; 

$secret = 'XXXXX';

$url = array();
foreach ($param as $key => $val) {
    $key = str_replace("%7E", "~", rawurlencode($key));
    $val = str_replace("%7E", "~", rawurlencode($val));
    $url[] = "{$key}={$val}";
}
sort($url);

$file = fopen($link_to_pdf_file,"r");
$pdf_feed=fread($file,filesize($FileName));
fclose($file);

$amazon_feed='<?xml version="1.0" encoding="utf-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>'.$param['Merchant'].'</MerchantIdentifier>
</Header>
<MessageType>OrderFulfillment</MessageType>
<Message>
<MessageID>'.getserial().'</MessageID>
<OrderFulfillment>
<AmazonOrderID>'.$amz_order_id.'</AmazonOrderID>
<FulfillmentDate>'.$param['Timestamp'].'</FulfillmentDate>
<FulfillmentData>
<CarrierName>Deutsche Post</CarrierName>
<ShippingMethod>Brief</ShippingMethod>
<ShipperTrackingNumber></ShipperTrackingNumber>
</FulfillmentData>
</OrderFulfillment>
</Message>
</AmazonEnvelope>';

    $arr   = implode('&', $url);
    $sign  = 'POST' . "\n";
    $sign .= 'mws.amazonservices.de' . "\n";
    $sign .= '/Feeds/'.$param['Version'].'' . "\n";
    $sign .= $arr;
    $signature = hash_hmac("sha256", $sign, $secret, true);
    $httpHeader     =   array();
    $httpHeader[]   =   'Transfer-Encoding: chunked';
    $httpHeader[]   =   'Content-Type: application/octet-stream';//application/pdf
    $httpHeader[]   =   'Content-MD5: ' . base64_encode(md5($pdf_feed, true));
    $httpHeader[]   =   'Expect:';
    $httpHeader[]   =   'Accept:';
    $signature = urlencode(base64_encode($signature));
    $link  = "https://mws.amazonservices.de/Feeds/".$param['Version']."?";
    $link .= $arr . "&Signature=" . $signature;
    $ch = curl_init($link);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
    $response['reply'] = curl_exec($ch);
    $response['info'] = curl_getinfo($ch);      
    curl_close($ch);
  ?>


此提要中没有可发布的XML。FeedContent(
CURLOPT\u POSTFIELDS
)是PDF的内容(
$PDF\u feed

您是否发布到正确的端点?您的marketplace ID表示使用mws eu端点的德国:我还希望参数名称应该是单数,
MarketplaceId
,因为
MarketplaceIdList
表示多个端点。我已经尝试了几个端点,“mws.amazonservices.de”正在工作。对于参数“MarketplaceId”,我已经尝试了我可以在网上找到的所有不同格式:
“Marketplace”、“MarketplaceId”、“MarketplaceList.Id”、“MarketplaceId.Id.1”
,这似乎没有任何区别。在端点
mws.amazonservices.de
mws eu.amazonservices.com
之间似乎没有功能上的区别。我已经找到了解决方案并更新了代码。解决方案:Marketplace Id参数名称必须是
MarketplaceIdList.Id.1
您能在回答中编写工作代码吗$amazon\u提要也没有定义