Path : /var/www/html/smart_kpp2_bk17 มีค 69/linebot/
File Upload :
Current File : /var/www/html/smart_kpp2_bk17 มีค 69/linebot/index_bk.php

<?php

//exit();
$accessToken = 'uaxVj5dbj19gRkYGPdJ0ZNraQh5y2bdndHY3hLXM5qwd3d625n+mBlZzQ+x73sp+uHv0ROby9Wr2ySS76NuGxBPT4yH7kLVIid4Sex3zTVSPOPZbimNuKXxnmE3lCZBsA+iP1X7UaOOewOUG6+u0dAdB04t89/1O/w1cDnyilFU=' ;
        $content = file_get_contents('php://input');
        $arrJson = json_decode($content, true);
        $arrayHeader = array();
        $arrayHeader[] = "Content-Type: application/json";
        $arrayHeader[] = "Authorization: Bearer {$accessToken}";

        $userId = $arrJson['events'][0]['source']['userId'];
        //$content_type = $arrJson['events'][0]['message']['type']; //['text','sticker','location','image','audio','video']
       $user_profile = json_decode(LineGetUserProfile($userId,$arrayHeader)) ;
        
        $arrayPostData = array();
        $arrayPostData['replyToken'] = $arrJson['events'][0]['replyToken'];

         if($arrJson['events'][0]['message']['text'] == "ผู้บริหาร") {
            $arrayPostData['messages'][0]['type'] = "text";
            $arrayPostData['messages'][0]['text'] = "https://www.yst1.go.th/2022/?page_id=110";
        } else if ($arrJson['events'][0]['message']['text'] == "ติดต่อเรา") {
            $arrayPostData['messages'][0]['type'] = "text";
            $arrayPostData['messages'][0]['text'] = "https://www.yst1.go.th/2022/?page_id=14";
        } else if ($arrJson['events'][0]['message']['text'] == "e-Service") {
            $arrayPostData['messages'][0]['type'] = "text";
            $arrayPostData['messages'][0]['text'] = "https://www.yst1.go.th/2022/?page_id=7626";
        } else if ($arrJson['events'][0]['message']['text'] == "FB สพป.ยส.1") {
            $arrayPostData['messages'][0]['type'] = "text";
            $arrayPostData['messages'][0]['text'] = "https://web.facebook.com/www.yst1.go.th";
        } else {
        $arrayPostData['messages'][0] = replyNonUser($user_profile->displayName);
        }
      

        LineReplyMsg($arrayHeader,$arrayPostData);


//function
function LineReplyMsg($arrayHeader,$arrayPostData){
    $strUrl = "https://api.line.me/v2/bot/message/reply";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$strUrl);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $arrayHeader);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arrayPostData));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($ch);
    curl_close ($ch);
}
function LineGetUserProfile($userId,$arrayHeader){
    $url = 'https://api.line.me/v2/bot/profile/'.$userId;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $arrayHeader);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
        #$displayName = $someArray->displayName;
        #userId: ID ของผู้ใช้(สำหรับระบบหลังบ้าน)
        #displayName: ชื่อของผู้ใช้
        #statusMessage: ข้อความของผู้ใช้
        #pictureUrl: รูปของผู้ใช้
        #email: อีเมลของผู้ใช้(เฉพาะ LIFF v2 และ LINE Login)
}
function replyNonUser($displayName)
    {
        $json = '
        {
            "type": "flex",
            "altText": "ยินดีต้อนรับเข้าสู่ สพป.ยส.1 Service",
            "contents": {
            "type": "bubble",
            "direction": "ltr",
            "header": {
                "type": "box",
                "layout": "vertical",
                "contents": [
                {
                    "type": "text",
                    "text": "สวัสดี คุณ '.$displayName.' ",
                    "align": "center",
                    "size": "lg",
                    "weight": "bold",
                    "color": "#009813"
                },
                {
                    "type": "text",
                    "text": "ยินดีต้อนรับสู่การใช้งาน", 
                    "weight": "bold",
                    "align": "center"
                },
                {
                    "type": "text",
                    "text": "Line Bot yst1", 
                    "weight": "bold",
                    "align": "center"
                }
                ]
            },
            "hero": {
                "type": "image",
                "url": "https://office.yst1.go.th/linebot/logo_line.jpg",
                "size": "full",
                "aspectRatio": "1.51:1",
                "aspectMode": "fit"
            },
            
            "footer": {
                "type": "box",
                "layout": "horizontal",
                "contents": [
                {
                    "type": "button",
                    "style": "primary",
                    "color": "#805500",
                    "action": {
                    "type": "uri",
                    "label": "เข้าใช้งานระบบ",
                    "uri": "https://liff.line.me/1660827893-Yvv0Da6d"
                    }
                }
                ]
            }
            },
            "quickReply": {
            "items": [
            
                {
                "type": "action",
                "action": {
                    "type": "message",
                    "label": "ผู้บริหาร",
                    "text": "ผู้บริหาร"
                }
                },
                {
                    "type": "action",
                    "action": {
                    "type": "message",
                    "label": "ติดต่อ สพป.ยส.1",
                    "text": "ติดต่อเรา"
                    }
                },
               {
                    "type": "action",
                    "action": {
                    "type": "message",
                    "label": "e-Service",
                    "text": "e-Service"
                    }
                },
               {
                    "type": "action",
                    "action": {
                    "type": "message",
                    "label": "FB สพป.ยโสธร.1",
                    "text": "FB สพป.ยส.1"
                    }
                }
               



            ]
            }
        }
        ' ;
        $jsonFlex = json_decode($json, true);
        return $jsonFlex;
    }
?>