簡體   English   中英

Shopify 驗證失敗

[英]Shopify verification failed

我正在嘗試在 Shopify 中創建一個公共應用程序。 我可以設置我們的應用程序所需的范圍。 在安裝過程中,它要求 shopify 驗證。 我已經參考了這份文件https://shopify.dev/tutorials/authenticate-with-oauth#verification 我已將消息傳遞為 code=%code-from-shopify%&shop=%shop.myshopify.com%&state=%state-from-shopify%&timestamp=%timestamp-from-shopify% 秘密為 Shopify 應用程序的密鑰,但它從不與 url 中作為參數存在的 hmac 匹配。

我在 3 年前創建了一個應用程序,正如我上面提到的,它運行良好,但是當我 9 天前創建一個應用程序時無法運行,並且這個新應用程序的密鑰以 shpss_ 開頭

我該如何解決?

  • 首先請檢查您的 SHOPIFY_KEY 和 SHOPIFY_SECRET 是否正確,您是否在代碼中使用相同的。
  • 從 shopify 重定向到給定的回調 URL 后,您將從請求中獲得 hmac 和代碼。

這是從 hmac 獲取訪問令牌的代碼

foreach ($_REQUEST as $key => $value) {
    if ($key !== "hmac" && $key != "signature") {
        $hashArray[] = $key . "=" . $value;
    }
}
$hashString   = implode($hashArray, "&");
$hashedString = hash_hmac("sha256", $hashString, 'YOUR_SHOPIFY_SECRET');

/* compare resulting hashed string with hmac parameter */
if ($_REQUEST['hmac'] !== $hashedString) {
    return 403;
}

$shopUrl  = "https://" . $_REQUEST["shop"] . "/admin/oauth/access_token.json";
$postData = http_build_query(
    array(
        "client_id"     => 'YOUR_SHOPIFY_KEY',
        "client_secret" => 'YOUR_SHOPIFY_SECRET',
        "code"          => $_REQUEST["code"],
    )
);

/* Call using curl post you will get Access token in JSON */
$result = shop_auth_curl_request_call($shopUrl, $postData);

$tokenResponse = json_decode($result, true);

$tokenResponse['access_token'] // In JSON you will get access token

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM