2017 © Pedro Peláez
 

library laravel_notifications_wechat

Use Wechat to send notification.

image

zztj/laravel_notifications_wechat

Use Wechat to send notification.

  • Sunday, August 13, 2017
  • by zztj
  • Repository
  • 0 Watchers
  • 0 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 33 % Grown

The README.md

laravel_notifications_wechat

使用laravel 通知, EasyWechat 来发送通知。, (*1)

laravel 5.3+ 请移步excitedcat/laravel-notification-wechat, (*2)

个人需要所以本项目是根据excitedcat/laravel-notification-wechat 改写,适用Laravel 5.2。, (*3)

安装方法

composer require zztj/laravel_notifications_wechat

使用方法

编辑config/app.php文件在providers数组中增加:, (*4)

ExcitedCat\WechatNotification\WechatServiceProvider::class

创建Notification, (*5)

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官方文档 * 控制器调用例子, (*6)

$user = User::find(1);
$wechat = [
    'systemName'=>'***系统',
    'created_at'=>'2017-08-10 09:57:02',
    'continue_number'=>2
];
$user->notify(new NewWarning($wechat));
  • 更改用户模型在app/Models/User.php中填下如下代码
//定义微信通知收件人
public function routeNotificationForWechat(){
    return $this->wechat_open_id;
}

The Versions

13/08 2017

dev-master

9999999-dev https://github.com/zztj/laravel_notifications_wechat

Use Wechat to send notification.

  Sources   Download

MIT

The Requires

 

by zz

13/08 2017
10/08 2017