https://github.com/zacksleo/laravel-notification-wechat
微信公众号模板消息,微信小程序模板消息
https://github.com/zacksleo/laravel-notification-wechat
Last synced: about 1 year ago
JSON representation
微信公众号模板消息,微信小程序模板消息
- Host: GitHub
- URL: https://github.com/zacksleo/laravel-notification-wechat
- Owner: zacksleo
- License: mit
- Created: 2019-08-01T08:27:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-01T15:42:49.000Z (almost 7 years ago)
- Last Synced: 2025-03-14T00:35:50.327Z (over 1 year ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
laravel-notification-wechat
.
## Installing
```shell
$ composer require zacksleo/laravel-notification-wechat -vvv
```
## Usage
### 创建通知类
```bash
$ php artisan make:notification InvoicePaid
```
```php
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Zacksleo\LaravelNotificationWechat\MiniProgramChannel;
use Zacksleo\LaravelNotificationWechat\OfficialAccountChannel;
use Zacksleo\LaravelNotificationWechat\Messages\MiniProgramTemplateMessage;
use Zacksleo\LaravelNotificationWechat\Messages\OfficialAccountTemplateMessage;
class InvoicePaid extends Notification implements ShouldQueue
{
use Queueable;
// ...
}
```
### 公众号模板消息
```php
public function via($notifiable)
{
return [OfficialAccountChannel::class];
}
public function toWechatOfficialAccount($notifiable): OfficialAccountTemplateMessage
{
return (new OfficialAccountTemplateMessage)
->to('接收用户的 openid')
->template('模板 ID')
->url('网页地址,如 https://demo.com')
->miniprogram('小程序app_id', '小程序页面路径')
->data([
'keyword1' => '关键词1',
'keyword2' => '关键词2',
]);
}
```
### 小程序模板消息
```php
public function via($notifiable)
{
return [MiniProgramChannel::class];
}
public function toWechatMiniProgram($notifiable): MiniProgramTemplateMessage
{
return (new MiniProgramTemplateMessage)
->to('接收用户的 openid')
->template('模板 ID')
->formId('formId 或者 prepay_id')
->page('小程序页面路径')
->data([
'keyword1' => '关键词1',
'keyword2' => '关键词2',
]);
}
```
## License
MIT