สร้างการแจ้งเตือนผ่าน Line ด้วย Line Notify Api
- ส่งข้อความ
- ส่งสติกเกอร์
- แนบรูปภาพ
sticker ประกอบด้วย stickerPackageId และ stickerId ดูได้จาก https://devdocs.line.me/files/sticker_list.pdffd
PHP Function
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 | $token = "token code" ; //ใส่Token ที่copy เอาไว้ $params = array ( "message" => "ทดสอบการใช้งานLine Notify API" , //ข้อความที่ต้องการส่ง สูงสุด 1000 ตัวอักษร "stickerPkg" => 2, //stickerPackageId "stickerId" => 34, //stickerId "imageThumbnail" => "https://c1.staticflickr.com/9/8220/8292155879_bd917986b4_m.jpg" , // max size 240x240px JPEG "imageFullsize" => "https://c1.staticflickr.com/9/8220/8292155879_bd917986b4_m.jpg" , //max size 1024x1024px JPEG ); $res = notify_message( $params , $token ); // print_r($res); function notify_message( $params , $token ) { $queryData = array ( 'message' => $params [ "message" ], 'stickerPackageId' => $params [ "stickerPkg" ], 'stickerId' => $params [ "stickerId" ], 'imageThumbnail' => $params [ "imageThumbnail" ], 'imageFullsize' => $params [ "imageFullsize" ], ); $queryData = http_build_query( $queryData , '' , '&' ); $headerOptions = array ( 'http' => array ( 'method' => 'POST' , 'header' => "Content-Type: application/x-www-form-urlencoded\r\n" . "Authorization: Bearer " . $token . "\r\n" . "Content-Length: " . strlen ( $queryData ) . "\r\n" , 'content' => $queryData , ), ); $context = stream_context_create( $headerOptions ); $result = file_get_contents (LINE_API, FALSE, $context ); $res = json_decode( $result ); return $res ; } |