我正在尝试解码MWS Fulfillment Inbound API返回的PDF数据 - GetPackageLabels请求。文档在这里:http://docs.developer.amazonservices.com/en_UK/fba_inbound/FBAInbound_GetPackageLabels.html
我已成功拨打电话并得到了回复,但是在php中使用直接的base64_decode会导致pdf损坏。因为我也无法得到匹配的校验和,这表明我在解码过程中错过了一步。我尝试从多个测试货件下载,因此不会出现单个请求在传输过程中损坏的情况。我已经概述了我在下面使用的步骤,任何帮助都将不胜感激。
XML响应:
<GetPackageLabelsResponse xmlns="http://mws.amazonaws.com/FulfillmentInboundShipment/2010-10-01/">
<GetPackageLabelsResult>
<TransportDocument>
<PdfDocument>UEsDBBQACAAIAFlZUUMAAAAAAAAAAAAAAAARAAAAUGFja2FnZUxhYmVscy5wZGbtVmtUE2ca1m7xEkWRcogX8EyruESWzCW3CWI0ECKXQGIChQJBJ8kEx01mMBkEvNS7uOUiiwpYrbWg4lG3iFarsAVF3S1WEEUpmlq3glKgYKtoi2C7k6CGJWf9sftrz9n8mXzv5fue93ue9z2fn0omD4S5fJbfvbarzSwYgABKt5wVHAwqcDKVXgbAMArKCRONW0C5CaNxGa6nDLhEYqUtOGZmZe6NzoNZmyGPMOXxjBJEeHZ9QtboW24D0jm31v9NafwsIfiv4xNM/d8GzBzNV3ntibwsXPFdtPZrDXp0zOCJVEHjIckxn9SUydf2JRLHaPf2us4noz44nF8YzdL2dXxbXVnf1rWtbM11ZdfFmoj5t1tH71oi6u1FPFk4aXgBgPlnB4w4gWvASGwlptFbiDQajNQA9prUEsnLSIFLiSI+/PoSv9hlU9sgj60Pn3utHs+eUthSaOp9A/Uzh4+a99mVtLa35zTNiVlRB/V1Bvxe+GX5Qs/bP+VuH3j46TrfmkXd/sdRt2zkHd9xcu8tRYX9m9gJ7Jay94tn1rfemzTF84C+/O7ZHk/63IbZJ3ovw3Vxmx+pFR/mXIj3HQhb8vFJld9e/p0bujfGs/sfX3xULL30uSYnICzZllsVvm5jYDdPldsaVD6rqBY6NSlIUTyZ3iRT329V1XQV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z9V68HnMp0Go7Q==</Checksum>
</TransportDocument>
</GetPackageLabelsResult>
<ResponseMetadata>
<RequestId>87a9d81a-6ec4-4d45-b2fc-8d0e6dfbe0a8</RequestId>
</ResponseMetadata>
</GetPackageLabelsResponse>
在PHP中,我已成功将PdfDocument字符串提取到$ data中,与上述内容相匹配。然后我使用以下内容输出数据:
$pdf_document = base64_decode($data);
header("Content-type: application/pdf");
header("Content-Length: " . strlen($pdf_document));
header("Content-Disposition: inline; filename=PackageLabels.pdf");
echo $pdf_document;
exit();
我已经检查过,在回显pdf数据之前,脚本没有输出任何数据。我还使用file_put_contents($filename, $pdf_document)
将数据保存到文件中,该文件也已损坏。
我也无法让md5校验和匹配:
echo base64_encode(md5($pdf_document, true)); // outputs: Pn0C06ZOgzDBfYwWXBvvow==
// from response: n0Cdtwupz9V68HnMp0Go7Q==
答案 0 :(得分:3)
PdfDocument
的内容是ZIP文件 - 前三个字母(“UE”)解码为“PK”,这是ZIP文件的魔术标识符。出于测试目的,您可以使用this website下载该ZIP的副本。 PHP具有允许您执行相同操作的功能,您必须检查编译到PHP版本中的内容。
所述ZIP存档的内容是标有PackageLabels.pdf
的单个文件,这是您正在寻找的PDF。
Checksum
也是base64编码的,示例中的代码解码为9f409db70ba9cfd57af079cca741a8ed
。这是supposed作为文档数据的MD5哈希值。但是,我还没有找出它是如何计算的。它 NOT 匹配以下任何一项的MD5: