ไม่ต้องส่ง reply จาก Line
Test Run ผ่านหน้า Web
หรือ ผ่าน Terminal command php
- <?php
- $ACCESS_TOKEN = "XXX";
- $content = file_get_contents('php://input');
- $arrayJson = json_decode($content, true);
- $arrayHeader = array();
- $arrayHeader[] = "Content-Type: application/json";
- $arrayHeader[] = "Authorization: Bearer {$ACCESS_TOKEN}";
- //รับข้อความจากผู้ใช้
- // $message = $arrayJson['events'][0]['message']['text'];
- //รับ id ของผู้ใช้
- // $id = $arrayJson['events'][0]['source']['userId'];
- // #ตัวอย่าง Message Type "Text + Sticker"
- // if($message == "สวัสดี"){
- $arrayPostData['to'] = 'UID XXXXX'; //Test Suwit
- $arrayPostData['messages'][0]['type'] = "text";
- $arrayPostData['messages'][0]['text'] = "สวัสดีจ้าาา";
- $arrayPostData['messages'][1]['type'] = "sticker";
- $arrayPostData['messages'][1]['packageId'] = "2";
- $arrayPostData['messages'][1]['stickerId'] = "34";
- pushMsg($arrayHeader, $arrayPostData);
- // }
- function pushMsg($arrayHeader,$arrayPostData){
- $strUrl = "https://api.line.me/v2/bot/message/push";
- $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);
- }
- ?>
No comments:
Post a Comment