You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

12 months ago
<?php
/**
* 公众号通知
*/
namespace App\Notifications;
use App\Channels\WechatChannel;
use Illuminate\Bus\Queueable;
use EasyWeChat\Factory;
use Illuminate\Notifications\Notification;
class WechatNotify extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [WechatChannel::class, 'database'];
}
/**
* 发送通知
* @param $notifiable
*/
public function toWechat($notifiable)
{
// template_message格式
// [
// 'touser' => 'user-openid',
// 'template_id' => 'template-id',
// 'url' => 'https://easywechat.com',
// 'miniprogram' => [
// 'appid' => 'xxxxxxx',
// 'pagepath' => 'pages/xxx',
// ],
// 'data' => [
// 'key1' => 'VALUE',
// 'key2' => 'VALUE2',
// ...
// ],
// ]
$config = [
'app_id' => config('app.wechat_appid'),
'secret' => config('app.wechat_secret'),
];
$app = Factory::officialAccount($config);
return $app->template_message->send($notifiable->template_message);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return $notifiable->template_message;
}
}