-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathbot.php
More file actions
56 lines (36 loc) · 1.63 KB
/
Copy pathbot.php
File metadata and controls
56 lines (36 loc) · 1.63 KB
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
<?php
$API_URL = 'https://api.line.me/v2/bot/message';
$ACCESS_TOKEN = 'ouhqskdRP/sUP8uwpjAadPDJz6rj1Y3IR0/ZznmHBgsPmYq6Q+hzdEJ4OXgyw/8NaLy6GLAZYYbLhF/7S6i8K07k3yxT0sWcMEa6ixgJ2c0XIOEKRfUEQAsHVi4PbQU4HEk9GOq/cmdR3iRkQE9e5gdB04t89/1O/w1cDnyilFU=';
$channelSecret = 'ba6e01c3eb0671a32e7d9fb3dbabd67d';
$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'];
$text = $event['message']['text'];
$data = [
'replyToken' => $reply_token,
// 'messages' => [['type' => 'text', 'text' => json_encode($request_array) ]] Debug Detail message
'messages' => [['type' => 'text', 'text' => $text ]]
];
$post_body = json_encode($data, JSON_UNESCAPED_UNICODE);
$send_result = send_reply_message($API_URL.'/reply', $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;
}
?>