Skip to content

Wechat template message use laravel notification based on Easywechat

Notifications You must be signed in to change notification settings

Yw-melo/wechat-template-message

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EasyWechat template message notification for Laravel

使用 EasyWechat 的模板消息功能发送 Laravel 消息通知。

安装

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 toWechatTemplateMessage($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));

About

Wechat template message use laravel notification based on Easywechat

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages