PHP code example of zacksleo / laravel-notification-wechat
1. Go to this page and download the library: Download zacksleo/laravel-notification-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/ */
zacksleo / laravel-notification-wechat example snippets
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;
// ...
}
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',
]);
}
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',
]);
}
bash
$ php artisan make:notification InvoicePaid
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.