PHP code example of if1024 / laravel-wechat-notification
1. Go to this page and download the library: Download if1024/laravel-wechat-notification 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/ */
if1024 / laravel-wechat-notification example snippets
namespace App\Notifications;
use If1024\LaravelWechatNotification\Messages\OfficialAccountTemplateMessage;
use If1024\LaravelWechatNotification\WechatMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
class TestNotify 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(mixed $notifiable): array
{
return ['official_account'];
}
public function toOfficialAccount(): OfficialAccountTemplateMessage
{
$data = [
'first' => 'first',
'keyword1' => 'keyword1',
'keyword2' => 'keyword2',
'keyword3' => 'keyword3',
'remark' => 'remark',
];
return WechatMessage::officialAccount()->template('template_id')
->url('https://github.com/')
->data($data);
}
}
public function routeNotificationForOfficialAccount($notification)
{
return $this->openid;//返回当前model内的公众号openid字段
}
use App\Notifications\TestNotify;
$user->notify(new TestNotify());
use Illuminate\Support\Facades\Notification;
use App\Notifications\TestNotify;
$users = \App\Models\User::all();
Notification::send($users, new TestNotify());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.