forked from muzaahaking/iot-netpie-line-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
line.php
87 lines (70 loc) · 3.59 KB
/
line.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
$API_URL = 'https://api.line.me/v2/bot/message/reply';
$ACCESS_TOKEN = 'nFI5LTsLqzdDLQZpvCRrAP/ltvQbaku30q2WEpSJPXwEtN9CeDjSd4wYAG++alAPB/VpMIu+29aQs18g/ak+7BDIq1vvEwBZsSeXUmW/KTbiDqPFnHJ5y1hcrWrvqRmBYt7FCBUNHywTfN8kHBlePgdB04t89/1O/w1cDnyilFU='; // Access Token ค่าที่เราสร้างขึ้น
$POST_HEADER = array('Content-Type: application/json', 'Authorization: Bearer ' . $ACCESS_TOKEN);
$request = file_get_contents('php://input'); // Get request content
$request_array = json_decode($request, true); // Decode JSON to Array
if ( sizeof($request_array['events']) > 0 )
{
foreach ($request_array['events'] as $event)
{
$reply_message = '';
$reply_token = $event['replyToken'];
if ( $event['type'] == 'message' )
{
if( $event['message']['type'] == 'text' )
{
$text = $event['message']['text'];
if(($text == "อุณหภูมิตอนนี้")||($text == "อุณหภูมิวันนี้")||($text == "อุณหภูมิ")){
$temp = 27;
$reply_message = 'ขณะนี้อุณหภูมิที่ '.$temp.'°C องศาเซลเซียส';
}
else if(($text== "ตอนนี้อยู่ที่ไหน")||($text== "ตอนนี้อยู่ไหน")||($text== "อยู่ที่ไหน")||($text== "อยู่ไหน")){
$reply_message = 'ขณะนี้อยู่ที่ห้องเรียน IF-5T05 ...!!!';
}
if(($text == "อยากทราบยอด COVID-19 ครับ")||($text == "COVID-19")||($text == "ยอด COVID-19")){
$clear = 50;
$admit = 700;
$dead = 5;
$reply_message = '"รายงานสถานการณ์ ยอดผู้ติดเชื้อไวรัสโคโรนา 2019 (COVID-19) ในประเทศไทย"
ผู้ป่วยสะสม จำนวน'. $admit .' ราย
ผู้เสียชีวิต จำนวน'. $dead .' ราย
รักษาหาย จำนวน '.$clear.' ราย
ผู้รายงานข้อมูล: นายเจษฎา นัดไธสง';
}
if(($text == "ข้อมูลส่วนตัวของผู้พัฒนาระบบ")||($text == "ข้อมูลส่วนตัว")){
$reply_message = 'ชื่อนายเจษฎา นัดไธสง อายุ 22 ปี น้ำหนัก 100kg. สูง 178cm. ขนาดรองเท้าเบอร์ 9 ใช้หน่วย US';
}
}
else
$reply_message = 'ระบบได้รับ '.ucfirst($event['message']['type']).' ของคุณแล้ว';
}
else
$reply_message = 'ระบบได้รับ Event '.ucfirst($event['type']).' ของคุณแล้ว';
if( strlen($reply_message) > 0 )
{
//$reply_message = iconv("tis-620","utf-8",$reply_message);
$data = [
'replyToken' => $reply_token,
'messages' => [['type' => 'text', 'text' => $reply_message]]
];
$post_body = json_encode($data, JSON_UNESCAPED_UNICODE);
$send_result = send_reply_message($API_URL, $POST_HEADER, $post_body);
echo "Result: ".$send_result."\r\n";
}
}
}
echo "OK";
function send_reply_message($url, $post_header, $post_body)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $post_header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>