/** * 发送手机 * * @param mobile * @return json; */ public function actionSend() { $request = Yii::$app->request; $moblie = trim($request->post("mobile")); if (!$moblie) { throw new \yii\web\NotFoundHttpException(404); } // 防止重复发送 $session = Yii::$app->session; /* * $session['send_tmp'] = [ * "code", * "send_time" * ]; */ // 检测是否存在该手机已经注册 if (!Rz_user::Usermobile_can_use($moblie)) { return json_encode($this->makeRes('false', "该号码已经注册!")); } if ($session['send_tmp'] == null || @$session['send_tmp']['send_time'] < time() - 50) { $code = Sms::init()->rands(6); $session->set('send_tmp', ['code' => $code, 'send_time' => time()]); $res = Sms::init()->send($moblie, $code); $res = $this->makeRes($res['statu'], "发送验证码过于频繁!"); } else { $res = $this->makeRes('false', "短信发送次数太频繁,请稍后再试!"); } return json_encode($res); }
public function actionFindbyemail() { if (!Yii::$app->request->isPost) { throw new \yii\web\NotFoundHttpException(404); } $code = strtolower(Yii::$app->request->post("code")); $email = trim(Yii::$app->request->post("values")); if (!$code || !$email) { throw new \yii\web\NotFoundHttpException(404); } // 验证码检查 if ($code != Yii::$app->session['passwordstepcode']) { return json_encode($this->makeRes("fail", "请输入正确的验证码!")); } // 清除验证码 Yii::$app->session['passwordstepcode'] = ""; // 用户检查 if (Rz_user::Useremail_can_use($email)) { return json_encode($this->makeRes("fail", "该邮箱未注册!")); } // 发送验证码并跳转 $code = Sms::init()->rands(6); $mail = \Yii::$app->mailer->compose()->setFrom(['*****@*****.**' => "润泽普惠一生随行"])->setTo($email)->setSubject('您的验证码')->setHtmlBody("<br>尊敬的用户,你的验证码为:【" . $code . "】")->send(); if (!$mail) { return json_encode($this->makeRes("fail", "邮件发送失败!")); } else { $session = Yii::$app->session; $session->set("passwordstep", ["code" => $code, "type" => "email", "values" => $email]); return json_encode($this->makeRes("success", \yii\helpers\Url::toRoute('passwordstep/checkuser'))); } }