-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
48 lines (37 loc) · 1.38 KB
/
index.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
43
44
45
46
47
48
<?php
header('Content-Type: text/html; charset=utf-8');
if(isset($_GET['hub_verify_token'])){
if($_GET['hub_verify_token'] === '123456789'){
echo $_GET['hub_challenge'];
return true;
}
else{
echo 'Invalid Verify Token';
return false;
}
}
$input = json_decode(file_get_contents('php://input'), true);
if(isset($input['entry'][0]['messaging'][0]['sender']['id'])){
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
$message = $input['entry'][0]['messaging'][0]['message']['text'];
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token=EAAX3lZAeXEgMBAGDyxHismZAP1U4EhI9ec9NtmP5q1FUJPwIkjboui2vrnZBZA5ezooc7sFDV7twve7hKG2BCv6T4pUvZBIalzZBrKoTWPqwnWs6fgdODWOQhTUPjAza9HZCPgUOtnI6HPffioQZA3ZCZAHUvqKDxGYyDo93trn8sGx9YQjqXLV4ot';
$ch = curl_init($url);
$jsonData = '{
"recipient":{
"id":"' . $sender . '"
},';
$message_chuan_hoa = mb_strtolower($message);
if(strpos($message_chuan_hoa, 'xin chào') !== false || strpos($message_chuan_hoa, 'chào') !== false ){
$jsonData.= '"message":{
"text":"Chào anh!"
}
}';
}
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
if(!empty($message)){
$result = curl_exec($ch);
}
}
?>