0
<?php
    const WEBHOOK_SECRET='secret key';
    function verifySignature ($body, $signature) {
        $digest = hash_hmac('sha1', $rawPost, WEBHOOK_SECRET);
        return $signature !== $digest ;
    }
    if (!verifySignature(file_get_contents('php://input'), $_SERVER['HTTP_X_TAWK_SIGNATURE'])) {
        // verification failed
    }
    // verification success
    else{
        $servername = "*******";
        $username = "*******";
        $password = "******";
        $db = "*******";
        $conn = new mysqli($servername, $username, $password, $db);
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }
        $json_string = file_get_contents('php://input');
        $array_data = json_decode($json_string, true);
        $sql = 'INSERT INTO twak (message) VALUES ("'.$array_data.'")';
        if ($conn->query($sql) === TRUE) {
            echo "New record created successfully";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }

        $conn->close();
    }


    ?>

我正在尝试将 tawk 到 webhook 响应存储到我的数据库中,但是这段代码没有给出 webhook 钩子响应。谁能告诉我有什么问题?

4

1 回答 1

0

文档中有一个错误,即使我花了一段时间才找出我的脚本不起作用的原因。内部函数verifySignature$rawPost应该是$body

function verifySignature ($body, $signature) {
    $digest = hash_hmac('sha1', $body, WEBHOOK_SECRET);
    return $signature !== $digest ;
}
于 2020-11-20T10:07:47.540 回答