1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LINE メッセージ送信(Laravel)

Posted at

初めに

Laravelを用いてLINEにてメッセージ送信を実装しました。
備忘録として残します。

環境

開発環境 バージョン
Laravel 10.1.5
PHP 8.2.3

環境構築

SDKをインストールします。

composer require linecorp/line-bot-sdk

実装

LineController.php
use LINE\LINEBot;
use LINE\LINEBot\Constant\HTTPHeader;
use LINE\LINEBot\Event\MessageEvent\TextMessage;
use LINE\LINEBot\HTTPClient\CurlHTTPClient;
use LINE\LINEBot\MessageBuilder\TextMessageBuilder;

// ... 略

/**
* LINE送信する
*/
public function LineSend()
{
    Log::debug(__FUNCTION__);

    $http_client = new CurlHTTPClient('channel_access_token'));
    $line_bot    = new LINEBot($http_client, 'channel_secret');
    $line_id     = 'line_id'; // またはchannel_id
    $message     = ''; 

    // メッセージを作成する
    $message = new TextMessageBuilder('LINE通知成功しました');

    // メッセージを送信する
    $line_bot->pushMessage($line_id, $message);

}

最後に

最後まで閲覧いただきありがとうございました。
ご意見、ご指摘ありましたら、コメントお願いいたします。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?