使用 Python、PHP 和 Postman 實現 Line Notify 推播通知
- 文章目錄
Line Notify 介紹
LINE Notify 是一個強大的 API,可以讓你輕鬆地將訊息發送到 LINE。透過使用你的 「個人存取權杖」,你能夠發送 HTTP POST 請求到 API 端點。本文將引導你如何使用 Python、PHP 和 Postman 等工具來完成訊息發送,讓你的應用程式能夠透過 LINE 進行即時通知。
簡單來說,這個過程可以大幅簡化行銷和訊息傳達的流程,並且透過 Line Bot 進行客製化的功能串接,讓使用者獲得更佳的體驗。例如,使用 Ptt Alertor 就能輕鬆實現 Line Bot 與 Line Notify 的連動。
Line Bot 設置
Line Notify 推播
更多 Ptt Alertor 詳細介紹可點擊下方連結:
Ptt Alertor 在 LINE、臉書接收批踢踢新文章通知,可追蹤主題、作者和推文
簡單設置 Line Bot 的相關教學可參考這篇文章:
[教學] Line Bot 機器人不求人 – 範例 (Python)
Line Notify 權限申請步驟
1. 登入 Line Notify 官網
前往 Line Notify 官方網站並登入你的帳號。
2. 發行 Line Notify 權杖
點擊網頁底部的 “發行權杖” 按鈕以創建新的權杖。
3. 選擇要連動的 Line 群組
選擇你想要讓 Line Notify 連動的群組,並可以修改 Line Notify 的名稱。
4. 取得 Line Notify Token
發行後會顯示你的 Line Notify token
,請務必記住這個 Token,因為它只會顯示一次。
5. 驗證推播成功
當你成功設置後,Line Notify 會推播一條成功的訊息到你的 LINE 群組。
6. 控制 Line Notify 權限
你可以隨時管理和控制已發行的 Line Notify 權限。
Line Notify 程式範例
Json 格式解析
- message: 訊息內容
- imageThumbnail: 縮圖 URL
- imageFullsize: 大圖 URL
- imageFile: 圖片檔案
- stickerPackageId: 內建貼圖包編號
- stickerId: 內建貼圖 ID
Python 範例
import requests
def send_notify(token, msg, filepath=None, stickerPackageId=None, stickerId=None):
payload = {'message': msg}
headers = {
"Authorization": "Bearer " + token
}
if stickerPackageId and stickerId:
payload['stickerPackageId'] = stickerPackageId
payload['stickerId'] = stickerId
if filepath:
attachment = {'imageFile': open(filepath, 'rb')}
r = requests.post("https://notify-api.line.me/api/notify", headers=headers, params=payload, files=attachment)
else:
r = requests.post("https://notify-api.line.me/api/notify", headers=headers, params=payload)
return r.status_code, r.text
# 測試 Line Notify
token = "你的金鑰放這裡"
send_notify(token=token, msg='測試訊息', filepath='')
PHP 範例
<?php
headers = array(
'Content-Type: multipart/form-data',
'Authorization: Bearer 你的金鑰放這裡'
);message = array(
'message' => '這是一條測試訊息',
"imageThumbnail" => "https://www.iloveimg.com/img/iloveimg/social/zh-Hant/compressimage.jpg",
"imageFullsize" => "https://www.iloveimg.com/img/iloveimg/social/zh-Hant/compressimage.jpg",
"imageFile" => "image/index.png",
"stickerPackageId" => 1,
"stickerId" => 2
);
ch = curl_init();
curl_setopt(ch , CURLOPT_URL , "https://notify-api.line.me/api/notify");
curl_setopt(ch, CURLOPT_HTTPHEADER,headers);
curl_setopt(ch, CURLOPT_POST, true);
curl_setopt(ch, CURLOPT_POSTFIELDS, message);result = curl_exec(ch);
curl_close(ch);
?>
Postman 範例
LINE Notify 是一個簡單而有效的 API,可以輕鬆地將訊息推送到 LINE。本文提供了使用 Python、PHP 和 Postman 的完整範例,讓你能夠快速上手並實現即時通知。若想深入了解 LINE Notify 的更多功能,請參考完整的教學文章。
[完整指南] 如何使用 Python、PHP 和 Postman 快速實現 Line Notify 推播通知
Line Bot 連動 Line Notify (Mac 安裝)
[教學] Line Bot 機器人不求人 – 範例 (Python)
buy cheap generic phenergan order stromectol 3mg for sale ivermectin 1%
prescription for peptic ulcer best drug to treat hypertension antibiotics that affect gram positive