重要 2025年3月31日をもって、LINE Notify (opens new window)のサービスを終了します。**
まずLINEに登録しているメールアドレスとパスワードでLINE Notifyのページ(https://notify-bot.line.me/ja/)にログインします。
登録メールアドレスは、LINEアプリの『設定>アカウント』から確認することが出来ます。
LINE Notifyにログインしてマイページを開きます。「トークンを発行する」と書かれたボタンがあるので、クリックしてアクセストークンを発行します。
<?php
// LINE送信テスト
define('LINE_API_URL' ,"https://notify-api.line.me/api/notify");
define('LINE_API_TOKEN','ACCESS_TOKEN'); // 「ACCESS_TOKEN」を取得したアクセストークンに置き換える
function post_message($message){
$data = array(
"message" => $message
);
$data = http_build_query($data, "", "&");
$options = array(
'http'=>array(
'method'=>'POST',
'header'=>"Authorization: Bearer " . LINE_API_TOKEN . "\r\n"
. "Content-Type: application/x-www-form-urlencoded\r\n"
. "Content-Length: ".strlen($data) . "\r\n" ,
'content' => $data
)
);
$context = stream_context_create($options);
$resultJson = file_get_contents(LINE_API_URL,FALSE,$context );
$resutlArray = json_decode($resultJson,TRUE);
if( $resutlArray['status'] != 200) {
return false;
}
return true;
}
// 引数取得
$mess = "";
if(isset($_GET['mess'])) {
$mess = $_GET['mess'];
}
header("Content-type: text/html; charset=utf-8");
echo urldecode($mess);
echo '<br>';
post_message($message);