我需要在php中计算从Amazon GetReport调用接收到的GetReport文件的Md5哈希值,并与GetReport响应头中接收到的Content-md5哈希字符串进行匹配,以检查文件的完整性。问题是我不知道如何计算通过Amazon GetReport调用接收到的报告文件的md5哈希值。我正在为这个GetReport API调用使用Guzzle谢谢
dwthyt8l1#
不确定这是否可行,让我们假设$response是Guzzle\Http\Message\Response对象:
$response
Guzzle\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编码值。
Content-MD5
1条答案
按热度按时间dwthyt8l1#
不确定这是否可行,让我们假设
$response
是Guzzle\Http\Message\Response
对象:进样来源:https://github.com/iFixit/php-amazon-mws-reports/blob/8aef4aede236b36ca57432f82e493f0d6e4f6200/src/MarketplaceWebService/Client.php#L964
注意,在AWS中,
Content-MD5
字段是数据的二进制md5散列的base64编码值。