-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.php
42 lines (37 loc) · 1.34 KB
/
send.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php include("database/db.php") ?>
<?php
if (isset($_POST["send"])){
$phone = $_POST['phone'];
$body = $_POST['body'];
$data = [
'phone' => $phone , // Receptores telefonicos
'body' => $body, // Mensaje
];
$json = json_encode($data); // Codificar datos a JSON
// URL for request POST /message
$token = 'nrw9lz930jg91s4b';
$instanceId = '226800';
//$url = 'https://eu219.chat-api.com/instance226800/sendMessage?token=nrw9lz930jg91s4b';
$url = 'https://api.chat-api.com/instance'.$instanceId.'/message?token='.$token;
// Hacer una solicitud POST
$options = stream_context_create(['http' => [
'method' => 'POST',
'header' => 'Content-type: application/json',
'content' => $json
]
]);
// Enviar una solicitud
$result = file_get_contents($url, false, $options);
$post_info = $result;
$query = "INSERT INTO chats(id, phone, body, post_info) VALUES ('$id', '$phone','$body', '$post_info')";
$result = mysqli_query($conn, $query);
if (!$result) {
die("Query failed");
}
$_SESSION['message'] = 'Message sent to the customer';
$_SESSION['message_type'] = 'success';
header("Location:create_customer.php");
}
//$_SESSION['message'] = 'Message could not be sent to the customer';
//$_SESSION['message_type'] = 'warning';
?>