简体   繁体   English

尝试将 webhook 响应存储到我的数据库中

[英]Try To store webhook response into my database

I'm trying to store a webhook response into my database table but it stores on array object, not value.我正在尝试将 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();

}
?>

And the output is :输出是:

id |身份证 | Message |留言 | len
1 | 1 | Array |数组 | 0 0
2 | 2 | Array |数组 | 0 0
2 | 2 | Array |数组 | 0 0

but I want the array value instead of the array object in the message column.但我想要数组值而不是消息列中的数组对象。 Can anyone please help me.谁能帮帮我吗。

Looking at the tawk webhook documentation you should need to change $array_data in the below line查看tawk webhook 文档,您应该需要在下面的行中更改$array_data

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

to

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

This uses the text property on the message object in the webhook data to get the message text.这使用 webhook 数据中message对象的text属性来获取消息文本。

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

this holds : Name : unknown这持有:名称:未知
Phone : 88776654322电话:88776654322
Email : y@gmail.com电子邮件:y@gmail.com
Question : Hello Question问题:你好问题

these attributes, how can I grab phone number from this??这些属性,我怎么能从中获取电话号码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM