基于 EasyWechat 和 Laravel notification 发送微信小程序模板消息

EasyWechat 自带了小程序的模板消息功能,我在这个得基础上开发了一个适用于消息通知 的扩展,喜欢用Laravel notification的可以关注下~ 仓库地址

安装

composer require ywmelo/template-message

使用

新建通知

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Ywmelo\TemplateMessage\Message\WechatTemplateMessage;
use Ywmelo\TemplateMessage\Channels\WechatTemplateMessageChannel;

class WechatTemplateMessageNotification extends Notification
{
    use Queueable;

    public function __construct($formId)
    {
        $this->formId = $formId;
    }

    public function via($notifiable)
    {
        return [WechatTemplateMessageChannel::class];
    }

    public function toEasySms($notifiable)
    {
        return (new WechatTemplateMessage)
            ->setTemplateId('template_id')
            ->setPage('page')
            ->setFormId($this->formId)
            ->setData([
                'keyword1' => 'keyword1',
                'keyword2' => 'keyword2',
                'keyword3' => 'keyword3',
                'keyword4' => 'keyword4',
            ]);
    }
}

发送

$user->notify(new WechatTemplateMessageNotification($formId));
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

小程序模板通知文档快要改版了 以后要用订阅的方式了

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!