Der*_*rek 1 php laravel laravel-5 onesignal laravel-5.3
我正在尝试使用laravel-notifications-channel/onesignal,但我的 laravel 应用程序中的用户设置为接收通知时遇到了一些问题。在GitHub的页面文件并没有真正涵盖了用户如何认证他们自收到通知。
即使阅读OneSignal 文档以将用户发送到 OneSignal 也不适合我。
我如何设置当用户使用我们的网络应用程序时,他们会收到通知以接收通知,然后我可以使用laravel 通知向他们发送通知?
这是我的 AssignedToTask 通知文件:
<?php
namespace App\Notifications;
use App\Task;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\OneSignal\OneSignalChannel;
use NotificationChannels\OneSignal\OneSignalMessage;
use NotificationChannels\OneSignal\OneSignalWebButton;
class AssignedToTask extends Notification
{
use Queueable;
protected $task;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Task $task)
{
//
$this->task = $task;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail', OneSignalChannel::class];
}
public function toOneSignal($notifiable)
{
return OneSignalMessage::create()
->subject("Your {$notifiable->service} account was approved!")
->body("Click here to see details.")
->url('http://onesignal.com')
->webButton(
OneSignalWebButton::create('link-1')
->text('Click here')
->icon('https://upload.wikimedia.org/wikipedia/commons/4/4f/Laravel_logo.png')
->url('http://laravel.com')
);
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('You have been assigned a new task')
->line('You have a new task: ' . $this->task->title)
->action('View Task', url('tasks/' . $this->task->id));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
Run Code Online (Sandbox Code Playgroud)
在我的用户模型中:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
use HipsterJazzbo\Landlord\BelongsToTenants;
use Cmgmyr\Messenger\Traits\Messagable;
class User extends Authenticatable
{
use Notifiable;
use EntrustUserTrait;
use BelongsToTenants;
use Messagable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'company_id'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'company_id'
];
....
public function routeNotificationForOneSignal()
{
return 'ONE_SIGNAL_PLAYER_ID';
}
public function routeNotificationForMail()
{
return $this->email_address;
}
}
Run Code Online (Sandbox Code Playgroud)
如何在用户模型中设置和获取 ONE_SIGNAL_PLAYER_ID 以便用户接受通知并且我可以向他们发送通知?
编辑 - 2
由于您不知道发生了什么,让我尝试解释您如何使用OneSignal.
这是一个推送消息系统,就像任何其他推送通知系统一样。(FCM(谷歌),PubNub)。
这个怎么运作
OneSignal.Com创建您的帐户,然后为您创建一个应用程序。一旦您创建了一个应用程序,它就会为您提供适用于移动设备的 SDK,您的消费者所在的位置。OneSignal并将向该移动应用程序发送推送通知。编辑 - 1
我想现在我明白你对通知的困惑 OneSignalChannel
流动
好吧,你从字面上理解了这个意思。这导致了问题
public function routeNotificationForOneSignal()
{
return 'ONE_SIGNAL_PLAYER_ID';
}
Run Code Online (Sandbox Code Playgroud)
根据错误消息,该函数应该返回一个唯一的 id (UUID)。
将返回值更改为实际玩家 ID OneSignalChannel
这就是我的朋友。
| 归档时间: |
|
| 查看次数: |
2969 次 |
| 最近记录: |