2

Amazon Login と Pay Express を使用して支払いを成功させました (こちらのデモに基づく: https://github.com/amzn/pay-with-amazon-express-demo/tree/master/php )。

ただし、ユーザーが購入に成功すると、サイトにリダイレクトされ、購入したものを説明する一連のパラメーターと Amazon から提供されたリクエストの署名を含む成功 URL が返されます。

Amazon から返された署名を検証するための元の署名を計算するために、以下のコードを試しましたが、このコードは、Amazon がリターン URL で送信するものと一致する署名を生成しません。

ExpressSuccess.php

<?php
echo ("<pre>");
print_r($_GET);
echo ("</pre>");

/* begin signature validation */
$merchantId  = "************"; // SellerID
$accessKey   = "*****************"; // MWS Access Key
$secretKey   = "***********************"; // MWS Secret Key
$lwaClientId = "***********************"; // Login With Amazon Client ID

/* Add http:// or https:// before your Return URL
 * The webpage of your site where the buyer should be redirected to after the payment is made
 * In this example you can link it to the Result.php, which checks for the success or failure of the payment
 * and routes it to the appropriate URL defined
 */
$returnURL   = "http://localhost/demo/pay-with-amazon/ExpressSuccess.php";
$cancelReturnURL = "http://localhost/demo/pay-with-amazon/ExpressCancel.php";

$signatureReturned = $_GET['signature'];
$parameters = $_GET;
unset($parameters['signature']);

if(isset($parameters['sellerOrderId'])) {
    $parameters['sellerOrderId'] = rawurlencode($parameters['sellerOrderId']);
}
uksort($parameters, 'strcmp');

$parseUrl = parse_url($returnURL);    
$stringToSign = "GET\n" . $parseUrl['host'] . "\n" . $parseUrl['path'] . "\n";

foreach ($parameters as $key => $value) {
    $queryParameters[] = $key . '=' . str_replace('%7E', '~', rawurlencode($value));
}
$stringToSign .= implode('&', $queryParameters);

$signatureCalculated = base64_encode(hash_hmac("sha256", $stringToSign, $secretKey, true));
$signatureCalculated = str_replace('%7E', '~', rawurlencode($signatureCalculated));

if ($signatureReturned == $signatureCalculated) {
    echo "Signature was successfully validated.";
} else {
    echo "Signature does not match.";
}
?>

誰かが私が間違っている場所を知っているなら、私に知らせてください。

ありがとう !!

4

0 に答える 0