1

基本上有一个错误的阅读触发了一个名为“AbnormalReadingWasTaken”的事件,我在“EventServiceProviders”中的“AbnormalReadingWasTaken”下注册了两个监听器,其中第一个监听器“AddReadingsToAlertsTable”工作正常,但另一个监听器“SendAlertSMS”似乎没有去工作。我错过了什么,有人可以帮我解决这个问题吗?我相信这与nexmo sms的curl脚本有关吗?

<?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);
    }
} 
4

1 回答 1

1

抱歉给您带来的麻烦,代码没有问题,错误是因为错误的api_key,我的错误不敢相信我实际上复制了错误的api_key。-_-

于 2015-11-09T17:56:36.137 回答