首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel:使用TextLocal事务性帐户在8月注册后不发送SMS

Laravel:使用TextLocal事务性帐户在8月注册后不发送SMS
EN

Stack Overflow用户
提问于 2019-05-08 11:32:40
回答 1查看 1.2K关注 0票数 0

我试图使用以下代码发送SMS OTP消息,但该消息没有发送。下面我添加了我的完整代码。我试图发送消息和电子邮件的同时,消息已经发送到注册用户,但Otp短信是不发送。我的TextLocal帐户是事务性的,我也用这个模板创建了短信模板。

我的TextLocal Otp模板:

代码语言:javascript
复制
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

代码语言:javascript
复制
  <?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 [
            //
        ];
    }

}

My RegisterController.php

代码语言:javascript
复制
 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

代码语言:javascript
复制
<?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));


    }


}

这里是我的Config/services.php

代码语言:javascript
复制
'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文件

代码语言:javascript
复制
TEXTLOCAL_TRANSACTIONAL_KEY= My Api Key
TEXTLOCAL_TRANSACTIONAL_FROM=TXTLCL

My Composer.json

代码语言:javascript
复制
 "require": {
 "thinkstudeo/textlocal-notification-channel": "^1.0"

 },

请帮帮我,我试过很多事情,但我的问题还没有解决。

EN

回答 1

Stack Overflow用户

发布于 2019-07-25 08:09:06

你试过使用Laravel插件吗?它还内置了通知通道支持。下面是TextLocal的一个示例配置,您可以在插件中使用它。

代码语言:javascript
复制
'textlocal' => [
    'method' => 'POST',
    'url' => 'https://api.textlocal.in/send/?',
    'params' => [
        'send_to_param_name' => 'numbers',
        'msg_param_name' => 'message',
        'others' => [
            'apikey' => 'YOUR_API_KEY',
            'sender' => 'YOUR_SENDER_NAME',
        ],
    ],
    'json' => true,
    'add_code' => false, //(If the numbers saved in DB do not have country code, change to true)
]

希望能帮上忙!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56039826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档