get['to']; $action = $this->get['action']; $captcha = $this->get['captcha']; if(preg_match($patternEmail,$to)) $toType = 'email'; if(preg_match($patternMobile,$to)) $toType='mobile'; if($to&&$action) { if(empty($toType)) { $msgdata = ['error' => 1,'msg' => '账号类型错误','data'=>array(),'code'=>'200']; return $msgdata; } if($this->smsconfig['open_imgvalid']&&!empty($captcha)) { if(!$this->validateCaptcha($captcha)) { $msgdata = ['error' => 1,'msg' => '校验失败','data'=>array(),'code'=>'200']; return $msgdata; } } //如果是找回密码,判断用户是否存在 if($action=='forgetpwd') { $user = User::find()->where("mobile='".$to."' or email='".$to."'")->one(); if(empty($user)) { $msgdata = ['error' => 1,'msg' => '用户不存在','data'=>array(),'code'=>'200']; return $msgdata; } } if($toType=='email') { $exist = EmailCert::find()->where("email='".$to."' and request_from = ".REQUEST_FROM)->orderBy(['id'=>SORT_DESC])->one(); } else if($toType=='mobile') { $exist = MobileCert::find()->where("mobile='".$to."' and request_from = ".REQUEST_FROM)->orderBy(['id'=>SORT_DESC])->one(); } if($exist&&TIMESTAMP-$exist->sent_time<$this->smsconfig['certTimeOut']) { $msgdata = ['error' => 1,'msg' => '发送失败(两次发送时间间隔太短)','data'=>array(),'code'=>'200']; } else { $code = rand(100000,999999); if($toType=='email') { $mailer = new Emailer(); $result = $mailer->send($action,$to,array('code'=>$code)); } else if($toType=='mobile') { $sms = new Sms(); $sms->init(); $result = $sms->send($action,$to,array('code'=>$code)); } if($result) { $msgdata = ['error' => 0,'msg' => '发送成功','data'=>var_export($result,true),'code'=>'200']; } else { $msgdata = ['error' => 1,'msg' =>'发送失败','data'=>array(),'code'=>'200']; } } } else { $msgdata = ['error' => 1,'msg' => '系统错误','data'=>array(),'code'=>'200']; } return $msgdata; } //校验验证码 public function actionCheckverifycode() { extract($this->post); if($user_name&&$code) { $result = $this->checkCode($user_name,$code); if(!empty($result)) { return $result; } $msgdata = ['error' => 0,'msg' => '校验成功','data'=>array('hash'=>sys_auth($user_name)),'code'=>'200']; } else { $msgdata = ['error' => 1,'msg' => '系统错误','data'=>[],'code'=>'200']; } return $msgdata; } }