原本在課程中設想的是使用Email來寄送通知內容,但是左思右想了很久,當通知在Email過多,根本就不會想要去看他,所以就還是用現在大家都有的Line平台,首先大家要自行去建立Line Notify的服務。
這個服務主要來寄送執行交易訊息與系統事件通知。
一、申請Line Notify服務
進入Line Notify網頁,並進行登入,登入後就會看到以下畫面,並點擊「登錄服務」。

可以依照以下範例進行輸入,除了服務名稱、我的名字與email外,都可以進行照抄。

確認沒問題後,將會寄送一封確認信至剛剛所指定的電子信箱內,請點擊確認。

確認完電子信箱後,即可看到已登錄的服務。

點擊進入服務的頁面中,可以看到ID與密碼資訊。

點選右上角已經登入的帳號處下的「個人頁面」,並點選發行權杖。
這時候就會看到自己的好友與群組出現在以下畫面中,可選取第一個自己的帳號。

之後將完成權杖的發行,請大家記得將這一串token複製下來,後面要丟入Python去當作參數的。

二、Python撰寫
import requests
#記錄Line Notify服務資訊
Line_Notify_Account = {'Client ID': 'xxxxxxxxxxxxxxxxx',
'Client Secret':'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'token':'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
#將token放進headers裡面
headers = {'Authorization':'Bearer ' + Line_Notify_Account['token'],
"Content-Type" : "application/x-www-form-urlencoded"}
#回傳測試文字
params = {"message":"自動下單測試"}
#執行傳送測試文字
r = requests.post("https://notify-api.line.me/api/notify", headers=headers, params=params)
#如順利輸出200,代表順利執行
print(r.status_code)
趕快拿起手機,應該就會出現以下畫面。
