LoginSignup
3
1

More than 1 year has passed since last update.

そのまま、コピペーでできます!LineNotify api でlineグループにメッセージを送信する(PHP)

Posted at

①Lineグループを作る。
・Line Notifyのユーザーを友たちに追加します。
・Lineグループを作成します。
・Line Notifyのユーザーをグループに招待します。

②下記Urlにログインしてトークンを発行する。

こちらの画面から発行してください。
notigy.png

③下記コードをそのまま使えば送信できます。

lineNoftify.php
function send($lineNotifyToken, $lineMessage)
{

    $query = http_build_query(['message' => $lineMessage]);
    $header = [
            'Content-Type: application/x-www-form-urlencoded',
            'Authorization: Bearer ' . $lineNotifyToken,
            'Content-Length: ' . strlen($query)
    ];
    $ch = curl_init('https://notify-api.line.me/api/notify');
    $options = [
        CURLOPT_RETURNTRANSFER  => true,
        CURLOPT_POST            => true,
        CURLOPT_HTTPHEADER      => $header,
        CURLOPT_POSTFIELDS      => $query
    ];
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt_array($ch, $options);
    // APIリクエスト
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);

    // リクエスト結果取得
    $errno = curl_errno($ch);
    $error = curl_error($ch);
    curl_close($ch);
    if (CURLE_OK !== $errno) {
        Log::error();
    }
    return $result;
} 

$lineNotifyToken = '〇〇〇〇〇〇〇〇';//こちらトークンを入れます。
$lineMessage = 'テスト'
sendLineNotify($lineNotifyToken, $lineMessage);

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1