简体   繁体   中英

Nexmo sms laravel not working

Basically there is a faulty reading which triggers an event called 'AbnormalReadingWasTaken' which I've registered two listeners under 'AbnormalReadingWasTaken' in my 'EventServiceProviders' where the first listener 'AddReadingsToAlertsTable' works fine however the other listener 'SendAlertSMS' doesn't seem to work. What am I missing, can anyone help me with this? I believe this has something to do with the curl script of the nexmo sms?

<?php

namespace App\Listeners;

use App\Events\AbnormalReadingWasTaken;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendAlertSMS
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  AbnormalReadingWasTaken  $event
     * @return void
     */
    public function handle(AbnormalReadingWasTaken $event)
    {
        $url = 'https://rest.nexmo.com/sms/json?' . http_build_query([
        'api_key' => 'xxxxx',
        'api_secret' => 'xxxxx',
        'to' => 'xxxxx',
        'from' => 'xxxxxx',
        'text' => 'Hello from Nexmo'
        ]);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    }
} 

Sorry for the trouble caused, nothing wrong with the code, the error was because of the wrong api_key, my mistake cant believe I actually copied the wrong api_key. -_-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM