<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xiaohuilam / laravel-wxapp-notification-channel example snippets
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Xiaohuilam\Laravel\WxappNotificationChannel\Traits\UserTrait;
use Xiaohuilam\Laravel\WxappNotificationChannel\Interfaces\Formidable;
class User extends Authenticatable implements Formidable // 实现 Formidable
{
use UserTrait; // 使用 UserTrait
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use Xiaohuilam\Laravel\WxappNotificationChannel\Types\MiniprogramType;
use Xiaohuilam\Laravel\WxappNotificationChannel\Interfaces\WechatOfficialNotificationable;
class WechatTemplateTestNotification extends Notification implements WechatOfficialNotificationable
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['wechat-official'];
}
/**
* 获取模板id
*
* @return string
*/
public function getTemplateId()
{
return 'iL4c0FHJFIIUIDfNH-gMXgkGHRwlP-lvh1Emfl4d3pg';
}
/**
* 获取模板消息跳转链接
*
* @return string
*/
public function getTemplateMessageUrl()
{
return 'https://www.baidu.com/';
}
/**
* 跳转到小程序, 与getTemplateMessageUrl二选一
*
* @return \Xiaohuilam\Laravel\WxappNotificationChannel\Types\MiniprogramType
*/
public function miniprogram()
{
return new MiniprogramType('APPID...', 'PATH路径...');
}
/**
* 获取模板消息数据
*
* @return array
*/
public function getTemplateMessageData()
{
return [
'keyword1' => '审核通过',
'keyword2' => 'ORDER-9112212',
'keyword3' => '点击查看订单详情',
];
}
}
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use Xiaohuilam\Laravel\WxappNotificationChannel\Interfaces\WechatAppNotificationable;
class WechatTemplateTestNotification extends Notification implements WechatAppNotificationable
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['wechat-app'];
}
/**
* 获取模板id
*
* @return string
*/
public function getTemplateId()
{
return 'iL4c0FHJFIIUIDfNH-gMXgkGHRwlP-lvh1Emfl4d3pg';
}
/**
* 获取模板消息跳转链接
*
* @return string
*/
public function getTemplateMessagePath()
{
return '/app/order/detail?id=11';
}
/**
* 获取模板消息数据
*
* @return array
*/
public function getTemplateMessageData()
{
return [
'keyword1' => '审核通过',
'keyword2' => 'ORDER-9112212',
'keyword3' => '点击查看订单详情',
];
}
/**
* 需要放大的词
*
* @return string
*/
public function getTemplateMessageEmphasisKeyword()
{
return 'keyword1.DATA';
}
}