【问题标题】:How to receive Shopify Webhook?如何接收 Shopify Webhook?
【发布时间】:2019-01-23 09:25:50
【问题描述】:

下面是我的代码。

define('SHOPIFY_APP_SECRET', 'xxxxxxxxxx');

function verify_webhook($data, $hmac_header)
{
  $calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
  return hash_equals($hmac_header, $calculated_hmac);
}


$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
$verified = verify_webhook($data, $hmac_header);

echo "<pre>";
print_r($data);
exit;   

?>

我已经注册了应用程序/已卸载的 webhook。 所以这是我的代码,但没有收到任何响应

【问题讨论】:

  • 如果您没有收到 webhook 请求(不是响应),那么您的签名验证代码不会提供任何帮助来确定问题所在。有各种各样的问题可能会干扰获取请求。我建议您尝试 Shopify 社区论坛,因为他们非常擅长帮助人们解决 webhook 实施问题。
  • 嘿,@dmulter 现在我收到了我的 webhook 的请求(而不是响应)。问题在于我的“SHOPIFY_APP_SECRET”谢谢您的回复。

标签: webhooks shopify-app


【解决方案1】:

我知道这是一个迟到的答案。但可能对将登陆这里的未来用户有所帮助。您忘记将您从uninstall webhook 获取的response 保存到某个地方。考虑将response 保存到文件中。这是要保存的php代码。保存响应后,您可以阅读或进行处理。

file_put_contents($newFileName, $data);

另外,仅当HMAC hash 匹配您从 api 获得的响应时才保存响应。您可以获得domain name 并为此触发topic api。下面是代码。做必要的工作。

$domain = $_SERVER['X-Shopify-Shop-Domain'];
$topic = $_SERVER['X-Shopify-Topic'];

如果您正在寻找更多详细信息,请告诉我。谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多