我已经获得了几行 JavaScript 代码,我需要将其转换为等效的 PHP 代码。作为一名 JavaScript 开发人员,我正在为此苦苦挣扎。这是我提供的 JavaScript 示例:
const crypto = require('crypto')
const secret_in_hex = Buffer.from(secret, 'hex');
const hash = crypto.createHmac('sha512', secret_in_hex)
.update(body)
.digest('hex')
// Compare hash with the received X-Onfleet-Signature in raw bytes
我正在使用 PHP 设置 Webhook 接收器的 API 文档提到:
Each webhook request contains a signature from Onfleet in X-Onfleet-Signature header. To authenticate the webhook request received on your webhook server, you will need to validate against this header. To validate against X-Onfleet-Signature, you will need to compare its value with an HMAC you have generated using the hexadecimal format of your webhook secrets and the full body of the webhook POST request in raw bytes.
我假设我将使用该hash_hmac函数,并且可能会使用该bin2hex函数,但此时完全被难住了,如果有人可以向我展示与上述 JavaScript 等效的 PHP(假设有一个),我将不胜感激。
湖上湖