php 如何计算从GetReport操作接收的Amazon报告文件的md5散列

2cmtqfgy  于 2023-02-18  发布在  PHP
关注(0)|答案(1)|浏览(74)

我需要在php中计算从Amazon GetReport调用接收到的GetReport文件的Md5哈希值,并与GetReport响应头中接收到的Content-md5哈希字符串进行匹配,以检查文件的完整性。问题是我不知道如何计算通过Amazon GetReport调用接收到的报告文件的md5哈希值。
我正在为这个GetReport API调用使用Guzzle
谢谢

dwthyt8l

dwthyt8l1#

不确定这是否可行,让我们假设$responseGuzzle\Http\Message\Response对象:

$expectedContentMd5 = $response->getHeader('Content-MD5');
$calculatedContentMd5 = base64_encode(md5($response->getBody(), true));

if($expectedContentMd5 === $calculatedContentMd5) {
    //verified, do your tasks here
} else {
    echo 'MD5 not matched';
    exit;
}

进样来源:https://github.com/iFixit/php-amazon-mws-reports/blob/8aef4aede236b36ca57432f82e493f0d6e4f6200/src/MarketplaceWebService/Client.php#L964
注意,在AWS中,Content-MD5字段是数据的二进制md5散列的base64编码值。

相关问题