public function actionSendcode() { if (!isset($_POST['CellPhone'])) { echo '请输入手机号。'; exit; } $phone = $_POST['CellPhone']; //60秒发送一次验证码 $time = time() - 60; $count = VerifyCode::find()->andWhere(['type' => 1, 'field' => $phone, 'status' => -1])->orderBy('b_time desc')->one(); if ($time < $count['b_time']) { echo '请勿重复点击'; exit; } try { $result = Port::ValidatePhone($phone); if ($result) { echo '验证码已发送,请注意查收。'; exit; } } catch (ErrorException $ex) { echo $ex->getMessage(); exit; } }
/** * 验证手机验证码 */ public function validateCode($attribute, $params) { try { $result = Port::checkPhnoe($this->username, $this->validate_code); } catch (ErrorException $ex) { $this->addError($attribute, Yii::t('app', '验证码无效,请重新获取。')); } }
/** *发送手机验证码 * @param $phone 手机号 * @param $templateid 短信模板编码 * @param $money 钱数 ---提现时发送提醒--模板2 * @return array */ public static function ValidatePhone2($phone, $templateid, $money = '') { //有效时间 $exptime = 2; //20秒发送一次验证码 $time = time() - 20; $count = VerifyCode::find()->andWhere(['type' => 1, 'field' => $phone, 'status' => self::CONFIRM])->orderBy('b_time desc')->one(); if ($time > $count['b_time']) { //生成验证码 $code = self::verification(6); if ($money != "" && $templateid == '2') { $code = $money; } $b_time = time(); $sms = new VerifyCode(); $sms->code = $code; $sms->field = $phone; $sms->type = '1'; $sms->b_time = $b_time; $sms->e_time = $b_time + $exptime * 60; $sms->status = Port::CONFIRM; $flag = $sms->save(); if ($flag) { $res = \frontend\actions\Port::sendSms2($phone, $code, $exptime, $templateid); //发送成功 if (!$res['errorNum']) { $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null); return $return; } elseif ($res['errorNum'] == '2') { $errmsg = $res['errorMsg']; self::phongLog($phone, $code, Port::ERROR, $errmsg); $return = array('errorNum' => '1', 'errorMsg' => $errmsg, 'data' => null); return $return; } else { $errmsg = $res['errorMsg']; self::phongLog($phone, $code, Port::ERROR, $errmsg); $return = array('errorNum' => '1', 'errorMsg' => '短信发送失败', 'data' => null); return $return; } } else { self::phongLog($phone, $code, Port::ERROR, '数据写入失败'); $return = array('errorNum' => '1', 'errorMsg' => '数据写入失败', 'data' => null); return $return; } } else { $return = array('errorNum' => '1', 'errorMsg' => '发送验证码频率过快', 'data' => null); return $return; } }
public function actionSendcode_() { if (!$_POST['CellPhone']) { echo '请输入手机号。'; exit; } try { $phone = $_POST['CellPhone']; $result = Port::ValidatePhone($phone); if ($result) { echo '验证码已发送,请注意查收。'; exit; } } catch (ErrorException $ex) { echo $ex->getMessage(); exit; } }
public function actionSetting() { if (\yii::$app->user->isGuest) { $this->redirect(['site/login']); } $uid = yii::$app->user->id; $is_Authentic = member::isAuthentic($uid); $model = UcenterMember::find()->where("id=" . $uid)->one(); //修改密码 if (isset($_POST['prepassword']) && isset($_POST['newpassword']) && isset($_POST['repeatpassword'])) { $_model = UcenterMember::findIdentity($uid); if (!yii::$app->security->validatePassword($_POST['prepassword'], $_model->password_hash)) { echo '原始密码错误'; exit; } elseif ($_POST['newpassword'] == $_POST['repeatpassword']) { $_model->password_hash = Yii::$app->security->generatePasswordHash($_POST['newpassword']); $app_pwd = md5(sha1($_POST['newpassword']) . time()); $_model->app_pwd = $app_pwd; $_model->save(false); echo '密码修改成功'; exit; } else { echo '两次密码不一致'; exit; } } //实名验证 if (isset($_POST['realname']) && isset($_POST['idcard'])) { $realname = $_POST['realname']; $idcard = $_POST['idcard']; try { $idcard_result = Port::baiduIdentity($idcard); if (!$idcard) { echo '身份认号不匹配,请核对后重新输入'; exit; } } catch (ErrorException $e) { echo '认证失败'; exit; } try { $result = member::authentication($uid, $realname, $idcard); if (is_bool($result)) { echo '身份认证成功'; exit; } } catch (ErrorException $e) { echo $e->getMessage(); exit; } } //设置头像 if (isset($_POST['UcenterMember']['person_face'])) { $model->person_face = UploadedFile::getInstance($model, 'person_face'); if ($model->person_face) { if ($model->validate()) { $Name = mt_rand(1100, 9900) . time() . '.' . $model->person_face->extension; $model->person_face->saveAs('../web/upload/' . $Name); //保存头像名到数据表 $model->person_face = $Name; if ($model->save(false)) { echo '<script>alert("头像修改完成~");</script>'; } } } } $infos_rar = $this->Ucenter(); //用户数据包 return $this->render('setting', compact("infos_rar", "model", "model_password", "is_Authentic")); }
public function actionRepass() { $uid = yii::$app->user->id; //判断验证码正确性 if (isset($_POST['CellPhone']) && isset($_POST['validate_code'])) { $phone = $_POST['CellPhone']; $code = $_POST['validate_code']; try { $result = Port::checkPhnoe($phone, $code); if (is_bool($result)) { $session = yii::$app->session; $session->open(); $session['phone'] = $phone; echo '验证通过0001'; exit; } else { echo '验证失败0002'; exit; } } catch (ErrorException $e) { echo $e->getMessage(); exit; } } return $this->render('repass', compact("infos_rar", "model")); }