Package Data | |
---|---|
Maintainer Username: | zuoee |
Maintainer Contact: | 18622745166@163.com (zz) |
Package Create Date: | 2017-08-10 |
Package Last Update: | 2017-08-15 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-06 03:04:54 |
Package Statistics | |
---|---|
Total Downloads: | 29 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 0 |
Total Forks: | 1 |
Total Open Issues: | 0 |
使用laravel 通知, EasyWechat 来发送通知。
laravel 5.3+ 请移步excitedcat/laravel-notification-wechat
个人需要所以本项目是根据excitedcat/laravel-notification-wechat 改写,适用Laravel 5.2。
composer require zztj/laravel_notifications_wechat
编辑config/app.php文件在providers数组中增加:
ExcitedCat\WechatNotification\WechatServiceProvider::class
创建Notification
php artisan make:notification NewWarning
<?php
namespace App\Notifications;
use ExcitedCat\WechatNotification\WechatChannel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
class NewWarning extends Notification implements ShouldQueue
{
use Queueable;
public $data;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database',WechatChannel::class];
}
public function toWechat($notifiable)
{
$notice = [
'templateId' => '3dUrtgoyZOoX0w_VkbEwD9r_****',
'url' => 'http://demo.com',
'data' => [
'first' => '你负责的系统出现预警,请关注处理!',
'system' => $this->data['systemName'],
'time' => $this->data['created_at'],
'account' => $this->data['continue_number'],
'remark' => '更多详情,请登录系统查看。'
]
];
return $notice;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return $this->data;
}
}
调用方式可参考Laravel官方文档
$user = User::find(1);
$wechat = [
'systemName'=>'***系统',
'created_at'=>'2017-08-10 09:57:02',
'continue_number'=>2
];
$user->notify(new NewWarning($wechat));
//定义微信通知收件人
public function routeNotificationForWechat(){
return $this->wechat_open_id;
}