Laravel: SMS не отправляются после регистрации авторизации через транзакционный аккаунт TextLocal - PullRequest
0 голосов
/ 08 мая 2019

Я пытаюсь отправить SMS-сообщение OTP, используя следующий код, но сообщение не отправляется. Ниже я добавил свой полный код. Я пытаюсь отправить сообщение и электронную почту одновременно, сообщение отправлено для регистрации пользователя, но Otp SMS не отправляются. Моя учетная запись TextLocal является транзакционной, и я также создал шаблон SMS с этим шаблоном и пытаюсь отправить сообщение.

My TextLocal Otp Template:

Use %%|OTP^{"inputtype" : "text", "maxlength" : "8"}%% as your login OTP. 
OTP is confidential, Delish2go never call you for asking OTP. It valid for next 10 mins. Do not disclose OTP to anyone. 

Код страницы уведомлений

Уведомление / verifyEmailNotification.php

  <?php

namespace App\Notifications;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Textlocal\TextlocalChannel;
use NotificationChannels\Textlocal\TextlocalMessage;

class verifyEmailNotification extends Notification
{
    use Queueable;

    public $user;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail', TextlocalChannel::class];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('Please Verify Your account Email')
                    ->action('Verify Account', route('verify', $this->user->token))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */

    public function toTextlocal($notifiable)
    {
        return (new TextlocalMessage())

            //Required
            // To send sms via your Textlocal transactional account
            //or promotional() to sent via Textlocal promotional account
            ->transactional()

            //Required
            //When sending through Textlocal transactional account, the content must conform to one of your approved templates.
            ->content("Use" . $this->user->code . "as your login OTP. OTP is confidential, Delish2go never call you for asking OTP. It valid for next 10 mins. Do not disclose OTP to anyone.");
    }

    public function toArray($notifiable)
    {
        return [
            //
        ];
    }

}

Мой RegisterController.php

 protected function create(array $data)
    {
         $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'token' => str_random(25),
            'phone' => $data['phone'],
            'code' => substr(str_shuffle("0123456789"), 0, 5),
        ]);

        $user->sendVerificationEmail();

        return $user;
    }

My User.php Model

<?php

namespace App;

use App\Notifications\verifyEmailNotification;
use App\Notifications\SendBlackFridaySaleAnnouncement;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Model;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'token', 'id_name', 'email_id', 'phone', 'pass', 'code',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

     public function verified()
    {
      return $this->token === null;
    }

    public function sendVerificationEmail()
    {
        $this->notify(new verifyEmailNotification($this));


    }


}

Вот мой Конфиг / services.php

'textlocal' => [
    'url' => 'https://api/textlocal.in/send'  //or 'https://api.textlocal.in/send/ - for India

    ],
    'transactional' => [
        'apiKey' => env('TEXTLOCAL_TRANSACTIONAL_KEY'),
        'from' => env('TEXTLOCAL_TRANSACTIONAL_FROM', 'TXTLCL')
    ],

Мой файл .env

TEXTLOCAL_TRANSACTIONAL_KEY= My Api Key
TEXTLOCAL_TRANSACTIONAL_FROM=TXTLCL

My Composer.json

 "require": {
 "thinkstudeo/textlocal-notification-channel": "^1.0"

 },

Пожалуйста, помогите мне, я пробовал много вещей, но моя проблема не решена.

...