/    Sign up×
Community /Pin to ProfileBookmark

Problem with Amazon signature

I’m spending many hours to try to solve this problem. I must create a ListOrders, but I always get this error:

[B]Sender SignatureDoesNotMatch The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.[/B]

I think that either signature and other fields arrive to Amazon server, because I tested all here:
[URL=”https://mws-eu.amazonservices.com/scratchpad/index.html”]https://mws-eu.amazonservices.com/scratchpad/index.html[/URL] and inserting the parameters, the same that I put in the code, the response is correct. This is the code:

[code=php]function call_amazon(){
$campi[“AWSAccessKeyId”] = rawurlencode($this->AWSAccessKeyId);
$campi[“Action”] = ‘ListOrders’;
$campi[“MarketplaceId.Id.1”] = rawurlencode($this->marketplaceid);
$campi[“SellerId”] = rawurlencode($this->Merchant);
$campi[“SignatureVersion”] = rawurlencode($this->SignatureVersion);
$campi[“SignatureMethod”] = rawurlencode($this->SignatureMethod);
$campi[“LastUpdatedAfter”] = $this->LastUpdatedAfter;
$campi[“Timestamp”] = gmdate(‘Y-m-d’).”T”.gmdate(‘H:i:s’).”Z”;
$campi[“Version”] = rawurlencode(“2013-09-01”);
$signature = $this->crea_signature($campi,$campi[“Timestamp”]);
$campi[‘Signature’] = urlencode($signature);
ksort($campi);
$fields_string = ”;
foreach($campi as $key=>$value) {
$fields_string .= $key.’=’.$value.’&’;
}
rtrim($fields_string, ‘&’);

// Elimina la & in fondo alla query string
$lung = strlen($fields_string) – 1;
$fields_string = substr($fields_string, 0,$lung);
$ch = curl_init($this->endpoint);

curl_setopt($ch,CURLOPT_POST, count($campi));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$output = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);
return simplexml_load_string($output);
}

function crea_signature($campi,$ts){
$stringa = ‘POST’;
$stringa .= “n”;
$stringa .= “mws-eu.amazonservices.com”;
$stringa .= “n”;
$stringa .= urlencode(“/Orders/2013-09-01”);
$stringa .= “n”;

$stringa .= “AWSAccessKeyId=”.$campi[“AWSAccessKeyId”];
$stringa .= “&Action=”.$campi[“Action”];
$stringa .= “&LastUpdatedAfter=”.$campi[“LastUpdatedAfter”];

$stringa .= “&MarketplaceId.Id.1=”.$campi[“MarketplaceId.Id.1”];
$stringa .= “&SellerId=”.$campi[“SellerId”];
$stringa .= “&SignatureMethod=”.$campi[“SignatureMethod”];
$stringa .= “&SignatureVersion=”.$campi[“SignatureVersion”];

$stringa .= “&Timestamp=”.$ts;
$stringa .= “&Version=”.$campi[“Version”];

$s = hash_hmac(‘sha256’, str_replace(‘ ‘, ”, $stringa), $this->secret, true);
$sig = base64_encode($s);

return $sig;
} [/code]

All the values of the given fields are correct. Could anyone help me, please? Thanks.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @claudiog74 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...