Search HP

Line Notify 自動提醒功能開發

開發環境:

[主機]: 遠振資訊虛擬主機

[語言]: PHP

[資料庫]: MYSQL

 

執行步驟:

1.必要條件 : 可以接收到Line 官方驗證的網址(網站) 參考網址 : https://www.evanlin.com/go-line-notify/

   記得要讓需要被通知的人員加入你申請的Line Notify權杖裡面。

 

2.申請完網域以及網址後另外在自己的主機上加入工作排程,讓工作排成定期/週期打開網址去呼叫Line Notify的動作

 

使用javascript程式開啟

<!DOCTYPE html>
<html lang="tw">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>

 

function jumpurl() {


    var URL = '你的網址';

    window.location.href = URL;
}
</script>
</head>
<body onload="jumpurl();">

</body>
</html>


  

3. 主機上加上一段程式代碼把需要提醒的 Line Notify 授權碼 = 被通知的人員 加入到資料庫中(應用於公司人員群組的概念),開啟後自動關閉該瀏覽視窗(作法很多種~請自行運用)。

 

<?php

/* 寫入一段呼叫授權碼資料庫清單入陣列 $row */
$access_token = array();
$access_token[] = $row['access_token'];

$message="工作辛苦了\r\n\rHello World!\r\n\r\n現在時刻: ".date('Y-m-d H:i:s');
$TargetCount = count($access_token);
   $Push_Content['message'] = $message;
  // $Push_Content['imageThumbnail'] = "https://i.imgur.com/ZxuJGHG.png";
  // $Push_Content['imageFullsize'] = "https://i.imgur.com/ZxuJGHG.png";
  // $Push_Content['stickerPackageId'] = "3";
  // $Push_Content['stickerId'] = "180";
  for ($i=0;$i<$TargetCount;$i++) {
   $ch = curl_init("https://notify-api.line.me/api/notify");
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Push_Content));
   curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded',
    'Authorization: Bearer '.$access_token[$i]
   ));
   $response_json_str = curl_exec($ch);
   curl_close($ch);
   echo $response_json_str."<br>\r\n";
   // {"status":400,"message":"LINE Notify account doesn't join group which you want to send."}
   // {"status":401,"message":"Invalid access token"}
   // {"status":400,"message":"message: must not be empty"}
   $response = json_decode($response_json_str, true);
   print_r($response);
   echo "<hr>";
   if ( (!isset($response['status'])) || (!isset($response['message'])) ) {
    echo "Request failed";
    exit;
   };
   if ( ($response['status'] != 200) || ($response['message'] != 'ok') ) {
    echo "Request failed";
    exit;
   };
   if (!isset($response['access_token'])) {
    $ch = curl_init("https://notify-api.line.me/api/status");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     'Authorization: Bearer '.$access_token[$i]
    ));
    $response_json_str = curl_exec($ch);
    curl_close($ch);
        echo $response_json_str."<hr>";
   } else if (preg_match('/[^a-zA-Z0-9]/u', $response['access_token'])) {
    echo 'Got wired access_token: '.$response['access_token']."<br>";
    echo 'http_response_header'.$http_response_header."<br>";
    echo 'response_json'.$response_json_str."<br>";
   } else {
    echo 'access_token: '.$response['access_token'];
   }
   usleep(6000); // microseconds * 1000 = miliseconds
  };
  
  
  
?>
 
<script type="text/javascript">

var i=10

function closewin()
{
	self.opener=null;
	self.close();
}

function clock()
{
	i=i-1
	document.title = "本視窗將在"+i+"秒後自動關閉!";
	if(i>0)setTimeout(clock(),1000);
	else closewin();
}

clock();

</script>

 

4. 就會得到第一張圖 Line Notify 自動通知到群組成員的效果了。

 

 

技術分享

  • eazyui開發EIP平台
    Written by

    這幾年因工作需求使用eazyui自組開發了EIP平台,其功能包含簽核表單、數據分析、系統設定...等相關功能,歡迎有興趣的朋友一起交流

    Written on 週三, 26 八月 2020 01:25 in News Read 425 times

帳號申請

熱門問題


templates/jsn_educare_pro/niches/school/images/white-logo.png
 
辦公地點:台灣台中市大里區
聯絡信箱:admin@lsdesign.com.tw
 

 

 

 Copyright@ 2017 LSDesign  |  DESIGN BY LSDesign

Go to top