Laravel Nexmo,使用通知时证书不好
我试图使用Nexmo和Laravel发送一些文本消息。 当我直接在路由中发送消息时,它工作正常:
Route::get('/sms/send/{to}', function(NexmoClient $nexmo, $to){
$message = $nexmo->message()->send([
'to' => $to,
'from' => '@me',
'text' => 'Sending SMS from Laravel. yay!!!'
]);
Log::info('sent message: ' . $message['message-id']);
});
但是,当我尝试使用Notification-Class发送短信时,我收到错误“Bad credentials”。 我一直在关注以下官方文档:https://laravel.com/docs/5.5/notifications#sms-notifications
以下是扩展通知的类:
<?php
namespace AppNotifications;
use IlluminateBusQueueable;
use IlluminateNotificationsNotification;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsMessagesMailMessage;
use IlluminateNotificationsMessagesNexmoMessage;
class KeepGoing 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($notifiable)
{
return ['nexmo'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return IlluminateNotificationsMessagesMailMessage
*/
public function toNexmo($notifiable)
{
return (new NexmoMessage)
->content('Your SMS message content');
}
我无法弄清楚为什么我会在尝试使用Notification-Class的同时在路由文件中完成其工作时出现“Bad credentials”错误 - 是否会出现错误?
谢谢!
编辑:调用notify()的控制器:
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppUser;
use AppNotificationsKeepGoing;
class NotificationController extends Controller
{
public function index()
{
$user = User::first();
$user->notify(new KeepGoing());
}
}
我还应该补充toNexmo()
会被调用:
public function toNexmo($notifiable)
{
// If i dump($notifiable) I can see the user.
// The $notifiable has the attribute phone_number which is
// what the notificationsystem looks for...
return (new NexmoMessage)
->content('Your SMS message content');
}
您没有提到在发生错误时您如何发送通知,但如果您使用队列,则应确保运行
php artisan queue:restart
使进程在队列中运行查看您的更改(例如修改.env或config)
原来这个错误是由一个愚蠢的错误引起的,我弄乱了config / services.php中的nexmo-config:
'nexmo' => [
'key' => env('NEXMO_KEY'),
'secret' => env('NEXMO_SECRET'),
'sms_from' => '15556666666',
],
我在上面提到了实际的关键和秘密......
链接地址: http://www.djcxy.com/p/33099.html上一篇: Laravel Nexmo, bad credentials when using notifications