if1024/laravel-wechat-notification
Composer 安装命令:
composer require if1024/laravel-wechat-notification
包简介
Wechat template message for Laravel Notification
关键字:
README 文档
README
Laravel框架下基于 laravel-wechat 使用微信公众号模板消息作为notification通道的composer包。
安装
$ composer require if1024/laravel-wechat-notification -vvv
使用
例子
<?php namespace App\Notifications; use If1024\LaravelWechatNotification\Messages\OfficialAccountTemplateMessage; use If1024\LaravelWechatNotification\WechatMessage; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; class TestNotify extends Notification { use Queueable; /** * Create a new notification instance. * * @return void */ public function __construct() { // } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via(mixed $notifiable): array { return ['official_account']; } public function toOfficialAccount(): OfficialAccountTemplateMessage { $data = [ 'first' => 'first', 'keyword1' => 'keyword1', 'keyword2' => 'keyword2', 'keyword3' => 'keyword3', 'remark' => 'remark', ]; return WechatMessage::officialAccount()->template('template_id') ->url('https://github.com/') ->data($data); } }
支持的 WechatMessage 方法
to(string $openid): 设置模板消息接收人的 openiddata(array $data): 设置模板消息数据template(string $templateID): 设置模板消息的模板 IDminiprogram(string $appid, string $pagepath): 设置点击模板消息后跳转的小程序,选填url(string $url): 设置点击模板消息后跳转 url,选填
在模型里使用Notifiable triat 来快捷发送消息:
public function routeNotificationForOfficialAccount($notification) { return $this->openid;//返回当前model内的公众号openid字段 }
然后这样发送模板消息。可参考官方文档:消息通知->发送通知
use App\Notifications\TestNotify; $user->notify(new TestNotify());
批量发送消息
use Illuminate\Support\Facades\Notification; use App\Notifications\TestNotify; $users = \App\Models\User::all(); Notification::send($users, new TestNotify());
说明
- 如果
miniprogram与url同时存在,则优先使用小程序跳转,详情请参考官方文档 data()方法接收一个数组,其key为模板消息中的关键字,value可以为字符串或数组。如果为字符串,则默认颜色为#173177;如果为数组,则第一个参数为显示的数据,第二个参数为字体颜色 可参考颜色设置
感谢
感谢 github 上的各位大哥给的参考!感谢超哥的easywechat
License
MIT
if1024/laravel-wechat-notification 适用场景与选型建议
if1024/laravel-wechat-notification 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notification」 「laravel」 「wechat」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 if1024/laravel-wechat-notification 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 if1024/laravel-wechat-notification 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 if1024/laravel-wechat-notification 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
微信SDK
This package makes it easy to send notifications via AfricasTalking with Laravel
钉钉、企业微信、飞书 自定义群组机器人。支持链式语法创建发送消息。支持文本、Markdown、图片、文件、图文、卡片等消息。
Apple Push Notification & Feedback Provider
The wechat extension for the Yii framework
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-10