PHP - Setup Webhook Receiver with signature verification

三世轮回 提交于 2019-12-05 12:31:53

To match the sent-in data with the validation hash in the header, you need to do the following things:

  1. Get the payload:
    $payload = file_get_contents("php://input");
  2. Generate a hash using the payload and your webhook key:
    $yourHash = base64_encode(hash_hmac('sha256', $payload, $yourWebhookKey));
  3. Check your hash against the one provided in the header:
    if ($yourHash === $_SERVER['x-xero-signature']) {}

You will have to check the $_SERVER array for the correct key if this does not work directly; it is probably all upper-case to begin with.

Edit: As noted by the OP, the correct variable is $_SERVER['HTTP_X_XERO_SIGNATURE']

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!