我正在尝试将 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
但我想要数组值而不是消息列中的数组对象。谁能帮帮我吗。