PHP+MySqli EP.17 PHP & line notify สำหรับการแจ้งเตือนผ่าน Line
PHP+MySqli EP.17 PHP & line notify สำหรับการแจ้งเตือนผ่าน Line ขั้นตอนการทำ กำ ลงทะเบียนและผูกบัญชี Line กับอีเมลที่ต้องการใช้งาน ลงทะเบียนเพื่อรับ Token ได้ที่ https://notify-bot.line.me/en/ โดย login จากบัญชีที่เราได้ลงทะเบียนไว้ สร้าง Token key โค๊ดการใช้งานตัวอย่าง
|
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
|
//แจ้งเตือนผ่านไลน์
define('LINE_API',"https://notify-api.line.me/api/notify");
$token = "ใส่Token ที่copy เอาไว้"; //ใส่Token ที่copy เอาไว้
$str = "\r\n".'username = '.$username.
"\r\n".' password = '.$password;
//ข้อความที่ต้องการส่ง สูงสุด 1000 ตัวอักษร
$res = notify_message($str,$token);
//print_r($res);
function notify_message($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;
}
//exit();
|
ระบบ ตระกร้าสินค้า
