| Server IP : 103.233.193.20 / Your IP : 216.73.216.169 Web Server : Apache/2 System : Linux host1.itclever.com 4.18.0-553.16.1.el8_10.x86_64 #1 SMP Thu Aug 8 17:47:08 UTC 2024 x86_64 User : oriscomadm ( 1120) PHP Version : 5.6.40 Disable Function : exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/oriscomadm/domains/oriscom.com/private_html/lineoriscom/ |
Upload File : |
<?php
// รับข้อมูลจาก Webhook
$input = file_get_contents('php://input');
//file_put_contents('line_event_log.txt', $input.PHP_EOL, FILE_APPEND);
file_put_contents('line_webhook_log.txt', $input.PHP_EOL, FILE_APPEND); // บันทึกข้อมูลที่ได้รับลงในไฟล์
$events = json_decode($input, true);
date_default_timezone_set('Asia/Bangkok');
if ($events['events'][0]['type'] == 'follow')
{
// ทำการตอบกลับหรือบันทึกข้อมูลการติดตามใหม่
//file_put_contents('follow_event_log.txt', $input.PHP_EOL, FILE_APPEND);
}
// ตรวจสอบว่ามีข้อมูลเหตุการณ์หรือไม่
if (!empty($events['events']))
{
foreach ($events['events'] as $event)
{
// ตรวจสอบว่าเป็นเหตุการณ์ "follow" ซึ่งเกิดขึ้นเมื่อมีคนเพิ่มเพื่อน
if ($event['type'] == 'follow')
{
$replyToken = $event['replyToken'];
// สร้าง Flex Message สำหรับทักทาย
$flexMessage = [
'type' => 'flex',
'altText' => 'บริษัทออริสคอม ยินดีต้อนรับสู่ LINE Official ',
'contents' => [
'type' => 'bubble',
'hero' => [
'type' => 'image',
'url' => 'https://www.oriscom.com/images/oriscom_office.jpg', // URL รูปภาพทักทาย
'size' => 'full',
'aspectRatio' => '20:13',
'aspectMode' => 'cover'
],
'body' => [
'type' => 'box',
'layout' => 'vertical',
'contents' => [
[
'type' => 'text',
'text' => 'สวัสดีค่ะ',
'weight' => 'bold',
'size' => 'xl'
],
[
'type' => 'text',
'text' => 'บริษัท ออริสคอม ยินดีต้อนรับ',
'weight' => 'bold',
'size' => 'xl'
],
[
'type' => 'text',
'text' => 'กรุณาเลือกเมนูที่ต้องการด้านล่าง',
'size' => 'sm',
'color' => '#999999'
]
]
],
'footer' => [
'type' => 'box',
'layout' => 'vertical',
'spacing' => 'sm',
'contents' => [
[
'type' => 'button',
'style' => 'primary',
'action' => [
'type' => 'message',
'label' => 'สนใจสั่งสินค้า',
'text' => 'สินค้า'
]
],
[
'type' => 'button',
'style' => 'primary',
'action' => [
'type' => 'message',
'label' => 'สอบถามข้อมูลสินค้า',
'text' => 'ติดต่อเจ้าหน้าที่'
]
],
[
'type' => 'button',
'style' => 'primary',
'action' => [
'type' => 'message',
'label' => 'บริการหลังการขาย',
'text' => 'บริการ'
]
],
[
'type' => 'button',
'style' => 'primary',
'action' => [
'type' => 'message',
'label' => 'สอบถามค่าใช้จ่าย',
'text' => 'ชำระเงิน'
]
],
[
'type' => 'button',
'style' => 'primary',
'action' => [
'type' => 'message',
'label' => 'โปรโมชั่น',
'text' => 'โปรโมชั่น'
]
],
[
'type' => 'button',
'style' => 'primary',
'action' => [
'type' => 'message',
'label' => 'ตำแหน่งที่อยู่บริษัทฯ',
'text' => 'ที่อยู่'
]
]
]
]
]
];
// เรียกฟังก์ชันส่งข้อความ Flex Message
replyFlexMessage($replyToken, $flexMessage);
}
}
}
// ฟังก์ชันสำหรับส่ง Flex Message
function replyFlexMessage($replyToken, $flexMessage)
{
$accessToken = 'bdByNR2wPV/lpUT0Kl8yXqySyWi1WxmBlNxL/7lv1v5YYHTRKVXlEAB3GUotOjg1g76IVToKLJL93vMyrpv/HjTJ3FPPVaRbc+gVt6MzxFfMNglKo3b4TPF3ldZD+Dq8b74TlCyEtz3m/542MCRABQdB04t89/1O/w1cDnyilFU='; // Channel access token จาก Line Developers
// สร้างข้อมูลสำหรับตอบกลับในรูปแบบ JSON
$data = [
'replyToken' => $replyToken,
'messages' => [$flexMessage]
];
// ตั้งค่า HTTP request headers
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $accessToken
];
// ใช้ cURL ส่ง POST request ไปยัง Line API
$ch = curl_init('https://api.line.me/v2/bot/message/reply');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// ส่งข้อมูลและรับผลลัพธ์จาก API
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
http_response_code(200);
echo 'OK';
//===================================================================
/* */
$hostname = "s1.oriscom.com";
$ip = gethostbyname($hostname);
//echo "IP for $hostname is $ip";
$ch = curl_init("https://s1.oriscom.com/php/sub/update_line_message_api_webhook.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
//curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($input));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($input, JSON_UNESCAPED_UNICODE));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
} else {
echo 'Response: ' . $response;
echo 'Info: ' . print_r(curl_getinfo($ch), true);
}
curl_close($ch);
/*
$ch = curl_init("https://s1.oriscom.com/php/sub/update_line_message_api_webhook.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
if ($response === false) {
echo curl_error($ch);
}
curl_close($ch);
*/
?>