ratiw/line-messaging 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ratiw/line-messaging

Composer 安装命令:

composer require ratiw/line-messaging

包简介

Simplify sending LINE messages using Messaging API.

README 文档

README

Simplify sending LINE messages using Messaging API for Laravel

Latest Version on Packagist Total Downloads

This package was developed to replace the use LINE Notify as it will be discontinued on March 31, 2025.

Basic Usage

use Ratiw\LineMessaging\LineMessaging;
use Illuminate\Http\Client\Response;

// simple text message to a user
$response = LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->text('Hi, this is a test message.');

// sticker message to a group chat
$response = LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->sticker('6359', '11069851');

// text with emojis
$response = LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->text('Hey, $ LINE emoji $', [
        ['productId' => '5ac2213e040ab15980c9b447', 'emojiId' => '009'],
        ['productId' => '5ac21d59031a6752fb806d5d', 'emojiId' => '004'],
    ]);

Understanding LINE Messaging API

In order to send LINE messages via LINE Messaging API, you need the following:

  • Channel access token
  • User ID, Group ID, or Room ID
  • what type of message you want to send

Getting those information can be tricky, but you usually do it once and then you can reuse it.

If you do not know how to get those information, please refer to the LINE Messaging API documentation, Or search for video tutorials on YouTube.

Getting User ID, Group ID, or Room ID

You can definitely use a free webhook.site to gather user IDs with the LINE Messaging API, but there's a key point to remember: The user ID will only be included in the webhook data if the user has consented to share their profile information with your LINE Official Account.

That means the user has to add your LINE Official Account as a friend (and, you'll get the user ID from the webhook), or invite your LINE Official Account to a group chat (and, you'll get the group ID from the webhook).

Message Types

This package currently supports the following message types:

  • Text
  • Sticker
  • Image
  • Video
  • Audio
  • Location

More might be added in the future, but no promises here. 😃

Installation

You can install the package via composer:

composer require ratiw/line-messaging

Usage

Use the LineMessaging::channel() to specify the channel access token and chain one of the following methods to specify the target user, group, or room.

  • toUser("USER_ID")
  • toGroup("GROUP_ID")
  • toRoom("ROOM_ID")

Then, chain one of the available message types to send the message.

  • text(message, emojis, quoteToken)
  • sticker(packageId, stickerId)
  • image(imageUrl, previewUrl)
  • video(videoUrl, previewImageUrl, trackingId)
  • audio(audioUrl, duration)
  • location(title, address, latitude, longitude)

Sending text message

text(string $message, $emojis = [], string $quoteToken = null)

// send a text message to a user
LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->text('Hello, world!');

// send a text message to a group chat
LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->text('Hello, world!');

Sending text message with emojis

To include emojis in the text message, you have to specify the emoji placeholders in the text message.

The placeholder is the $ character in the message.

Then, you have to includes an array of emoji objects in the second argument.

Each emoji object must have the following keys:

  • productId: The product ID of the emoji.
  • emojiId: The emoji ID of the emoji.
LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->text('$ Happy birthday! $', [
        ['productId' => '5ac2213e040ab15980c9b447', 'emojiId' => '007'],
        ['productId' => '5ac2213e040ab15980c9b447', 'emojiId' => '009'],
    ]);

See

  • LINE emojis here.
  • LINE text message type here.
  • LINE text message reference here.

Sending sticker

sticker($packageId, $stickerId)

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->sticker('6359', '11069851');

See

  • LINE stickers list here.
  • LINE sticker message type here.
  • LINE sticker message reference here.

Sending image

image(string $imageUrl, string $previewUrl = null)

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toGroup('GROUP_ID')
    ->image('https://example.com/image.jpg', 'https://example.com/image_preview.jpg');

Note

  • previewUrl is optional.
  • given URL must be https scheme

See

  • LINE images message type here.
  • LINE image message reference here.

Sending video

video(string $videoUrl, string $previewImageUrl = null, string $trackingId = null)

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->video('https://example.com/video.mp4', 'https://example.com/video_preview.jpg', 'TRACKING_ID');

Note

  • previewImageUrl and trackingId are optional.
  • given URL must be https scheme

Sending audio

audio(string $audioUrl, int $duration)

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->audio('https://example.com/video.m4a', 50000);

Note

  • given URL must be https scheme
  • duration is in milliseconds

Sending location

location(string $title, string $address, float $latitude, float $longitude)

LineMessaging::channel('YOUR_CHANNEL_ACCESS_TOKEN')
    ->toUser('USER_ID')
    ->location('MOCA Bangkok', '499 Kamphaeng Phet 6 Rd, Lat Yao, Chatuchak, Bangkok 10900', 13.853197788942376, 100.56302862528158);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

ratiw/line-messaging 适用场景与选型建议

ratiw/line-messaging 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 86 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「laravel」 「line-notify」 「ratiw」 「line-」 「line-messaging」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ratiw/line-messaging 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ratiw/line-messaging 我们能提供哪些服务?
定制开发 / 二次开发

基于 ratiw/line-messaging 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 86
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-09