PHP code example of zztj / laravel_notifications_wechat

1. Go to this page and download the library: Download zztj/laravel_notifications_wechat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zztj / laravel_notifications_wechat example snippets



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;
	}

}


$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;
}
`bash
php artisan make:notification NewWarning