基于 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 协议》,转载必须注明作者和本文链接
小程序模板通知文档快要改版了 以后要用订阅的方式了