1. Go to this page and download the library: Download cyaoz94/laravel-huawei-push 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/ */
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class User extends Model
{
use Notifiable;
/**
* 推送路由
*/
public function routeNotificationForHuaweiPush()
{
return $this->huawei_push_token;
}
/**
* 如果不同用户所属的APP包名可能不同,请添加此方法
*/
public function getAppPackage()
{
return 'com.app.bundle_id';
}
}
use Illuminate\Support\Facades\Notification;
use Cyaoz94\LaravelHuaweiPush\HuaweiNotification;
use Cyaoz94\LaravelHuaweiPush\HuaweiMessage;
$msg = (new HuaweiNotification)
->title('通知标题')
->body('通知内容')
->setHandler(function($msg,$notifiable,$cfg,$type = null)
{
if($msg instanceof HuaweiMessage)
{
$msg->ttl(86400);
$msg->channel_id(8888);
}
return $msg;
});
$user->notify($msg);
Notification::send($users,$msg);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.