piyapongkaewnan/line-notify

用于Line应用程序通知的PHP和Laravel API。

3.0 2024-05-28 08:31 UTC

This package is auto-updated.

Last update: 2024-09-28 09:22:29 UTC


README

Line Notify

用于Laravel和PHP的Line应用程序通知包。

Latest Version Packagist Maintainability

Line Notify是一个用于Laravel和PHP应用程序的包,可以轻松地将通知发送到Line消息应用程序的用户或群组。它基于Line Notify API,该API提供了一种流畅的界面,可以直接从Laravel和PHP发送消息、图片和贴纸到Line服务。

安装Line Notify

您需要使用Composer将Line-Notify安装到您的项目中

composer require piyapongkaewnan/line-notify

Laravel使用方法

LINE_ACCESS_TOKEN变量添加到您的.env文件中。您可以从Line Notify API获取您的应用程序的访问令牌

// .env
LINE_ACCESS_TOKEN=#Token Go here#

通过Line Notify发送消息。

use Phattarachai\LineNotify\Facade\Line;

Line::send('message');

发送带有图片的消息。

Line::imageUrl('https://lorempixel.com/1024/1024/')
    ->send('message');

您还可以指定图片的缩略图

Line::thumbnailUrl('https://lorempixel.com/240/240/')
    ->imageUrl('https://lorempixel.com/1024/1024/')
    ->send('message');

您可以从本地路径上传图片

Line::imagePath('/path/to/your/image.png')
    ->send('message');

您可以将图片上传和图片URL结合起来。上传的图片将优先于图片URL。

Line::thumbnailUrl('https://lorempixel.com/240/240/')
    ->imageUrl('https://lorempixel.com/1024/1024/')
    ->imagePath('/path/to/your/image.png')
    ->send('message');

发送带有贴纸的消息。您可以在以下位置找到贴纸包ID和贴纸ID列表 https://devdocs.line.me/files/sticker_list.pdf

Line::sticker(1, 138)
    ->send('message');

请注意,Line要求每个请求都必须有一个消息,无论您发送的是图片还是贴纸,您仍需为API提供消息。

发布配置文件

除了将变量添加到您的.env文件中之外,您还可以发布config/line-notify.php文件并在其中添加您的令牌。

在您的终端中运行以下Artisan命令

php artisan vendor:publish --provider="Phattarachai\LineNotify\LineNotifyServiceProvider"

您可以在该文件中设置令牌。

// File: /config/line-notify.php
return [
    'access_token' => env('LINE_ACCESS_TOKEN', null),
];

支持开发者

🙋‍♂️ 您好,我是奥芬,是一名Full Stack Web Developer。我创建了这个包,并在自己的项目中频繁使用。如果您有任何关于在PHP / Laravel / NodeJS / Python或其他语言上创建包的建议,请随时告诉我

line: phat-chai

💻 如果您有有趣的项目,需要团队合作,或者需要经验丰富的程序员帮助解决挑战,请随时联系我。我很乐意提供帮助并共同创造出色的作品

📄 您可以在 https://phattarachai.dev 上查看我的历史和作品

https://phattarachai.dev

配置(Laravel)

Laravel 5.5及更高版本

Line Notify将通过Laravel的自动发现来注册自己。

Laravel 5.4及更早版本

您需要在您的config/app.php中包含LineNotifyServiceProvider

'providers' => [
    /*
     * Package Service Providers...
     */
    Phattarachai\LineNotify\LineNotifyServiceProvider::class,
]

PHP使用(Laravel外)

use Phattarachai\LineNotify\Line;

$line = new Line('YOUR-API-TOKEN-HERE');
$line->send('message');

截图

Screenshot

信用

phattarachai.dev 的项目创建

如果我的包使您的生活更轻松,请考虑以下操作

给我买杯咖啡 |

关注我的Twitter

许可证

MIT许可证(MIT)