Line Notify 串接方式

將 LINE Notify 邀請進要通知的群組(邀請後會自動加入),再至 LINE notify的個人頁面 ,使用<發行權杖>取得token(取得token時即已決定要發送的對象)

將token填入下方欄位,並輸入要發送的訊息,按下發送按鈕即可發送

※ token為重要參數,實際使用時勿置於前端頁面

詳細API文件,可見 LINE Notify API Document

程式碼:
function send_line_notify($token, $message)
{   
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://notify-api.line.me/api/notify");
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "message=" . $message);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $headers = array("Content-type: application/x-www-form-urlencoded", "Authorization: Bearer " . $token);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}