Amazon MWS orders Signature Does Not Match

When I run this code, I get a SignatureDoesNotMatch error 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.

<?php 
    $param = array();
    $param['AWSAccessKeyId'] = 'AWSAccessKeyId';
    $param['Action'] = 'ListOrders';
    $param['MWSAuthToken'] = 'MWSAuthToken';
    $param['MarketplaceId'] = 'A21TJRUUN4KGV';
    $param['FulfillmentChannel.Channel.1'] = 'MFN';
    $param['PaymentMethod.Method.1'] = 'COD';
    $param['OrderStatus.Status.1'] = 'Pending';
    $param['OrderStatus.Status.2'] = 'PendingAvailability';
    $param['SellerId'] = 'AGNFZGZRZBUP1';
    $param['SignatureMethod'] = 'HmacSHA256';
    $param['SignatureVersion'] = '2';
    $param['CreatedAfter'] = "2017-09-01T13:41:49Z";
    $param['Timestamp'] = gmdate("Y-m-dTH:i:s.Z", time());
    $param['Version'] = '2013-09-01';
    $secret = 'secret key';

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

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

    sort($url);

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

    $sign = 'POST' . "n";
    $sign .= 'mws.amazonservices.in' . "n";
    $sign .= '/Orders/2013-09-01' . "n";
    $sign .= $arr;


    $signature = hash_hmac("sha256", $sign, $secret, true);
    $signature = urlencode(base64_encode($signature));

    $link = "https://mws.amazonservices.in/Orders/2013-09-01?";
    $link .= $arr;
    $link .= "&Signature=" . $signature;
    echo($link); //for debugging - you can paste this into a browser and see if it loads.



    $ch = curl_init($link);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    echo "<pre>";
    print_r($response);
    print_r($info); 
?>

Your signature calculation seems fine. However, you're calculating a signature based on a "POST", but then you're actually doing a GET. I'd guess that's what's throwing off the signature calculation on the other side.

链接地址: http://www.djcxy.com/p/39004.html

上一篇: AWS SQS SendMessage身份验证签名版本2

下一篇: 亚马逊MWS订单签名不匹配