php : ใช้งาน Line Notify กับ php

  • 1 ตอบ
  • 4122 อ่าน
*

อั๋น ทรงวุฒิ

  • Sr. Member
  • ****
  • 326
  • 3
  • แพร่ เวียงโกศัย
    • ดูรายละเอียด
    • songwut.biz
php : ใช้งาน Line Notify กับ php
« เมื่อ: 08 มีนาคม 2018, 06:11:39 AM »
อ้างถึง
https://notify-bot.line.me/th

1) เข้าเว็บจัดการ line notify แล้วทำการ Login ด้วย Line account

2) เมนูด้านบนขวา กดที่ลูกศรชี้ลงด้านข้างชื่อบัญชีแล้วเลือก “หน้าของฉัน”

3) กดปุ่ม “ออก Token”

4) พิมพ์ชื่อของ bot line notify ประจำห้อง และ เลือกห้องที่จะส่งข้อความ

5) กดปุ่ม “ออก Token” ให้คัดลอกเก็บไว้ กดจะกดปิด (มันจะแสดงรอบเดียว ถ้าเผลอปิดก่อน ต้องออกใหม่)

6) เชิญเพื่อน Line Notify เข้าห้อง

7) เขียนโค้ดควบคุมได้เลย

*

อั๋น ทรงวุฒิ

  • Sr. Member
  • ****
  • 326
  • 3
  • แพร่ เวียงโกศัย
    • ดูรายละเอียด
    • songwut.biz
Re: php : ใช้งาน Line Notify กับ php
« ตอบกลับ #1 เมื่อ: 08 มีนาคม 2018, 06:24:41 AM »
โค๊ด: [Select]

define('LINE_API',"https://notify-api.line.me/api/notify");
$token = "l7Wazf4Fu7V5cbkFR7FNBZd1zjrfroAgZzqZPx8mEXR"; // Token ที่ได้จากเว็บ LINE Notify

// ======== ฟังก์ชันเตรียมส่งข้อความ =============
function send_msg($message,$token){

$queryData = array('message' => $message);
$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;
}
// ======== จบ : ฟังก์ชันเตรียมส่งข้อความ =============

// ========= ส่งข้อความ =============

$msg= "เย็นนี้ 17:00 น. ขอให้ทุกท่านเข้าประชุมออนไลน์โดยพร้อมเพรียงกัน"; //ข้อความที่ต้องการส่ง สูงสุด 1000 ตัวอักษร
send_msg($msg,$token);