我目前正在使用Laravel作为后端编写iOS推送通知。
我向iOS应用程序发送了一份通知,但是原来用日语写的文字被弄错了。
·Laravel 5.7
app/控制台/命令/SendPushNotification.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Notifications\PushNotification;
use App\User;
class SendApnsNotLogin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'push:apns';
/**
* The console command description.
*
* @var string
*/
protected $description = 'send notification';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//get the people who receive notifications
$users = User::all();
foreach($users as $user) {
$user->notify(new PushNotification);
}
}
}
APP/Notificationphp/PushNotificationphp
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\Apn\ApnChannel;
use NotificationChannels\Apn\ApnMessage;
mb_language("Japanese");
mb_internal_encoding("UTF-8");
********omitted*******
public function via($notifiable)
{
return [ApnChannel::class];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toApn($notifiable)
{
return ApnMessage::create()
->badge(1)
->title("タイトル部分")
->body("ボディ部分");
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
如果有人给我一些如何避免文字混乱和如何发送日文推送通知的建议,我将不胜感激。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。