【问题标题】:Try To store webhook response into my database尝试将 webhook 响应存储到我的数据库中
【发布时间】:2020-03-04 15:32:37
【问题描述】:

我正在尝试将 webhook 响应存储到我的数据库表中,但它存储在数组对象上,而不是值上。

<?php
const WEBHOOK_SECRET = 'Secre_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
} else {
// verification success
$servername = "localhost";
$username = "name";
$password = "password";
$db = "twakdata";

// Create connection
$conn = new mysqli($servername, $username, $password, $db);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$json_string = file_get_contents('php://input');
$stringLen = strlen($json_string);
$array_data = json_decode($json_string, true);
    $sql = 'INSERT INTO twak (message,len) VALUES ("'.$array_data.'","'.strlen($json_string).'")';
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

}
?>

输出是:

标识 |留言 |伦
1 | |数组      | 0
2 | |数组      | 0
2 | |数组      | 0

但我想要数组值而不是消息列中的数组对象。谁能帮帮我。

【问题讨论】:

    标签: php laravel webhooks tawk.to


    【解决方案1】:

    查看tawk webhook documentation,您应该需要在下面的行中更改$array_data

    $sql = 'INSERT INTO twak (message,len) VALUES ("'.$array_data.'","'.strlen($json_string).'")';
    

    到

    $array_data['message']['text']
    

    这使用 webhook 数据中 message 对象上的 text 属性来获取消息文本。

    【讨论】:

      【解决方案2】:
      $array_data['message']['text']
      

      这成立: 姓名:未知
      电话:88776654322
      电子邮件:y@gmail.com
      问题:你好问题

      这些属性,我如何从中获取电话号码??

      【讨论】:

      • $array_data['message']['text']['phone'] 可能有用吗?
      猜你喜欢
      • 2015-02-05
      • 2019-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 1970-01-01
      相关资源
      最近更新 更多