0
votes

I'm having issue in repricing the product with php curl in amazon mws API, having error SenderContentMD5DoesNotMatch the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed4bad39e1-7479-4ebb-ae94-76e2eed742cb

here is the complete code

fwrite($write, "sku\tprice");

while($row = mysql_fetch_assoc($rsSql))
{
    fwrite($write,"\n".$row['seller_sku']."\t".$row['current_price']);
}

fclose($write);

$file = 'prices.tsv';
$fo = fopen($file,'r');

$httpHeader=array();
$httpHeader[]='Transfer-Encoding: chunked';
$httpHeader[]='Content-Type: text/tab-separated-values';
$httpHeader[]='Content-MD5: ' . base64_encode(md5(trim($file)));
$httpHeader[]='Expect:';
$httpHeader[]='Accept:';

$curl_options=array(
CURLOPT_UPLOAD=>true,
CURLOPT_INFILE=>$fo,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_POST=>true,
// CURLOPT_PORT=>443,
// CURLOPT_SSLVERSION=>3,
CURLOPT_SSL_VERIFYHOST=>false,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_FOLLOWLOCATION=>1,
CURLOPT_PROTOCOLS=>CURLPROTO_HTTPS,
CURLINFO_HEADER_OUT=>TRUE,
CURLOPT_HTTPHEADER=>$httpHeader,
CURLOPT_CUSTOMREQUEST=>'POST',
CURLOPT_VERBOSE=>true,
// CURLOPT_HEADER=>true,
);


$param = array();
$param['AWSAccessKeyId']   = AWSKEY; 
$param['Action']           = 'SubmitFeed'; //CHANGE THIS
$param['SellerId']         = SELLERID; 
$param['SignatureMethod']  = 'HmacSHA256';  
$param['SignatureVersion'] = '2'; 
$param['ContentMD5Value']  = base64_encode(md5(trim($file)));
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version']          = '2009-01-01'; 
$param['MarketplaceId']    = MARKETPLACE; 
$param['FeedType']    = "_POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_";
$param['PurgeAndReplace']    = 'true';


$secret = SECRETKEY;

$url = array();
foreach ($param as $key => $val) {

    $key = str_replace("%7E", "~", rawurlencode($key));
    $val = str_replace("%7E", "~", rawurlencode($val));
    $url[] = "{$key}={$val}";

}

sort($url);
$arr = implode('&', $url);

$sign = 'POST' . "\n";
$sign .= 'mws.amazonservices.com' . "\n";
$sign .= '/Feeds/2009-01-01' . "\n";
$sign .= $arr;

$signature = hash_hmac("sha256", $sign, $secret, true);
$signature = urlencode(base64_encode($signature));
$link = "https://mws.amazonservices.com/Feeds/2009-01-01?";
$link .= $arr . "&Signature=" . $signature;

$ch = curl_init($link);
curl_setopt_array($ch,$curl_options);
$response=curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

$xml = simplexml_load_string("$response");
echo $response;
1

1 Answers

0
votes

Your code will calculate the MD5 of the file's name, not its contents.

 base64_encode(md5(trim($file))); <-- $file is actually the filename!

Also, you shouldn't trim anything from the file's contents, and you need to pass the binary MD5 to the encoder:

 base64_encode(md5($filecontents,true));

or

 base64_encode(md5_file($filename,true));