gcreate/line_notify

使用laravel的line notify插件

dev-main 2023-06-15 02:00 UTC

This package is auto-updated.

Last update: 2024-09-14 05:59:42 UTC


README

使用Line notify插件为laravel

安装包

composer require gcreate/line_notify

注册包服务提供者

// config/app.php
'providers' => [
  ...
  Gcreate\LineNotify\LineNotifyServiceProvider::class,
  ...
],

创建配置

php artisan vendor:publish --tag=line-notify-config

创建用户表迁移

php artisan vendor:publish --tag=line-notify-migration

php artisan migrate

添加line_notify_access_token列和line_notify_state列

添加.env参数

LineNotifyClientID=Your Line Service ClientID
LineNotifyClientSecret=Your Line Service ClientSecret

用法

绑定用户Line

use Gcreate\LineNotify\Controllers\LineNotify;

$lineNotify = new LineNotify();

$redirectUrl = $lineNotify->bindLineUrl($userModel)

return redirect($redirectUrl);    // go binding line page

如果绑定用户成功,您需要从回调中保存用户Line notify令牌

接收用户Line回调

将以下内容添加到您的routes/web.php中

Route::post( 'your/callback/url', [yourController::class, 'callback'])->name('line-notify.callback');

前往您的Middleware/VerifyCsrfToken.php并添加以下内容

protected $except = [
    'your/callback/url',
];
use Gcreate\LineNotify\Controllers\LineNotify;

$lineNotify = new LineNotify();

$callbackStatus = $lineNotify->callback($request, $user);

撤销用户Line

use Gcreate\LineNotify\Controllers\LineNotify;

$lineNotify = new LineNotify();

$result = $lineNotify->revoke($user);    // true | error
if($result){
    // ...do something
}

发送消息

use Gcreate\LineNotify\Controllers\LineNotify;

$lineNotify = new LineNotify();

$lineNotify->send($user,$text);