xiaohuilam/laravel-wxapp-notification-channel
Composer 安装命令:
composer require xiaohuilam/laravel-wxapp-notification-channel
包简介
Laravel package to enable wechat mini program template message notification as a channel
README 文档
README
安装
composer require xiaohuilam/laravel-wxapp-notification-channel -vvv
发布
执行以下命令创建 formids 数据表
php artisan migrate
模型改动
打开 app\User.php (如果你修改过模型位置,请以自己项目实际位置为准)
namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; use Xiaohuilam\Laravel\WxappNotificationChannel\Traits\UserTrait; use Xiaohuilam\Laravel\WxappNotificationChannel\Interfaces\Formidable; class User extends Authenticatable implements Formidable // 实现 Formidable { use UserTrait; // 使用 UserTrait
配置
WECHAT_MINI_PROGRAM_APPID=#小程序的appid WECHAT_MINI_PROGRAM_SECRET=#小程序的secret
使用
定义消息模板
新建 app/Notifications/WechatTemplateTestNotification.php
根据不通类型走不同 notification 类
- 公众号模板通知
- 小程序模板通知
公众号模板通知
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use Xiaohuilam\Laravel\WxappNotificationChannel\Types\MiniprogramType; use Xiaohuilam\Laravel\WxappNotificationChannel\Interfaces\WechatOfficialNotificationable; class WechatTemplateTestNotification extends Notification implements WechatOfficialNotificationable { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['wechat-official']; } /** * 获取模板id * * @return string */ public function getTemplateId() { return 'iL4c0FHJFIIUIDfNH-gMXgkGHRwlP-lvh1Emfl4d3pg'; } /** * 获取模板消息跳转链接 * * @return string */ public function getTemplateMessageUrl() { return 'https://www.baidu.com/'; } /** * 跳转到小程序, 与getTemplateMessageUrl二选一 * * @return \Xiaohuilam\Laravel\WxappNotificationChannel\Types\MiniprogramType */ public function miniprogram() { return new MiniprogramType('APPID...', 'PATH路径...'); } /** * 获取模板消息数据 * * @return array */ public function getTemplateMessageData() { return [ 'keyword1' => '审核通过', 'keyword2' => 'ORDER-9112212', 'keyword3' => '点击查看订单详情', ]; } }
小程序模板通知
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use Xiaohuilam\Laravel\WxappNotificationChannel\Interfaces\WechatAppNotificationable; class WechatTemplateTestNotification extends Notification implements WechatAppNotificationable { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['wechat-app']; } /** * 获取模板id * * @return string */ public function getTemplateId() { return 'iL4c0FHJFIIUIDfNH-gMXgkGHRwlP-lvh1Emfl4d3pg'; } /** * 获取模板消息跳转链接 * * @return string */ public function getTemplateMessagePath() { return '/app/order/detail?id=11'; } /** * 获取模板消息数据 * * @return array */ public function getTemplateMessageData() { return [ 'keyword1' => '审核通过', 'keyword2' => 'ORDER-9112212', 'keyword3' => '点击查看订单详情', ]; } /** * 需要放大的词 * * @return string */ public function getTemplateMessageEmphasisKeyword() { return 'keyword1.DATA'; } }
如果是小程序,还需要开API来记录 FormId
use Xiaohuilam\Laravel\WxappNotificationChannel\Models\Formid; // ... $formid = request()->input('formid'); // 小程序前端post 过来的 formid $user = User::find(1); $user->formids()->saveMany([new FormId(['formid' => $formid])]);
发送模板消息
use App\Notifications\FriendshipRequestNotification; $user = User::find(1); $user->notify(new WechatTemplateTestNotification());
授权
MIT
鸣谢
- Overtrue's laravel-easywechat
xiaohuilam/laravel-wxapp-notification-channel 适用场景与选型建议
xiaohuilam/laravel-wxapp-notification-channel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 133 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 xiaohuilam/laravel-wxapp-notification-channel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xiaohuilam/laravel-wxapp-notification-channel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 133
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-01