<?php

namespace App\Listeners;

use App\Events\SendSmsEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use Overtrue\EasySms\EasySms;
use App\Models\SendSms as SendS;

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

    /**
     * Handle the event.
     *
     * @param  SendSms  $event
     * @return void
     */
    public function handle()
    {
        $config=config('easysms');
        $easySms = new EasySms($config);
        $content="【大卫博士】常来微聊已经发布，请及时查看并发送给代理。";
        $sms=SendS::all();
        try{
            foreach($sms as $key=>$val){
                $easySms->send($val->phone, ['content' =>$content ]);
            }
        } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
            $message = $exception->getException('qcloud')->getMessage();
            Log::info($message == null ? '短信发送异常' : $message);
        }
        Log::info('短信发送成功');
    }
}
