request->isPost()){ return $this->fail('请求方式错误'); } //获取参数 $params = $this->request->post(['phone','scene']); if(empty($params['phone']) || empty($params['scene'])){ return $this->fail('缺少必要参数'); } if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA,NoticeEnum::REGISTER_CAPTCHA])){ return $this->fail('短信场景错误'); } //发送短信 try { $result = event('Notice', [ 'scene_id' => $params['scene'], 'params' => [ 'mobile' => $params['phone'], 'code' => mt_rand(1000, 9999), ] ]); return $this->success($result[0]); }catch(\Exception $e){ //记录日志 Log::error($e->getMessage()); return $this->fail($e->getMessage()); } } }