public function mobilenumregAction()
 {
     $logger = $this->get("logger");
     $request = $this->getRequest();
     $txtmobile = trim($request->get('mobile_num'));
     $response = $this->getResponse(ReturnCode::$SUCCESS, "");
     //验证手机号是否合法
     if (!Utils::validateMobile($txtmobile)) {
         $logger->err("请输入正确的手机号[" . $txtmobile . "]");
         return $this->getResponse(ReturnCode::$OTHERERROR, "请输入正确的手机号!");
     }
     $login_account = $txtmobile;
     $domain = $this->container->getParameter('edomain');
     if (!strpos($login_account, "@")) {
         $login_account .= "@" . $domain;
     }
     try {
         //手机号是否已经被使用
         $da = $this->get('we_data_access');
         $sql = "select count(1) as cnt from we_staff where mobile_bind=? and state_id!='3'";
         $ds = $da->GetData("we_staff", $sql, array($txtmobile));
         if ($ds && $ds['we_staff']['rows'][0]['cnt'] > 0) {
             $this->get("logger")->err("手机号已被使用");
             return $this->getResponse(ReturnCode::$OTHERERROR, "该手机号已注册,继续使用请先找回密码");
         }
         $active_code = rand(100000, 999999);
         $sql = "select submit_num,state_id,last_reg_date,timestampdiff(second,last_reg_date,now()) as dif" . " from we_register where login_account=?";
         $ds = $da->GetData("we_register", $sql, array($login_account));
         //$logger->err("记录数:".$ds["we_register"]["recordcount"]);
         if ($ds && $ds['we_register']['recordcount'] > 0) {
             if ($ds['we_register']['rows'][0]['state_id'] == '3') {
                 return $this->getResponse(ReturnCode::$OTHERERROR, "该手机号已注册,继续使用请先找回密码");
             }
             if ($ds['we_register']['rows'][0]['dif'] <= 60) {
                 return $this->getResponse(ReturnCode::$OTHERERROR, "你获取验证码的次数太频繁!一分钟只能取一次!");
             }
             if ($ds['we_register']['rows'][0]['submit_num'] > 5 && $ds['we_register']['rows'][0]['dif'] <= 60 * 60 * 24) {
                 return $this->getResponse(ReturnCode::$OTHERERROR, "抱歉,验证码请求次数过多,如果获取不到验证码请根据下方提示与我们联系");
             } else {
                 if ($ds['we_register']['rows'][0]['dif'] > 60 * 60 * 24) {
                     //一天以后重置
                     $sql = "update we_register set submit_num=0 where login_account=?";
                     $da->ExecSQL($sql, array($login_account));
                 }
             }
             $sql = "update we_register set active_code=?,last_reg_date=now(),submit_num=ifnull(submit_num,0)+1," . "state_id='0',review_note='0' where login_account=?";
         } else {
             $sql = "insert into we_register (active_code,login_account,submit_num,state_id,first_reg_date,last_reg_date," . "register_date,review_note) values (?,?,1,'0',now(),now(),now(),'0')";
         }
         $para = array($active_code, $login_account);
         $da->ExecSQL($sql, $para);
         $content = "验证码:" . $active_code . ",2分钟内有效,仅用于注册。【企业】";
         $ec = new \Justsy\BaseBundle\Controller\SendSMSController();
         $ec->setContainer($this->container);
         $ret = $ec->sendSMSAction($txtmobile, $content);
         if ($ret['returncode'] != '0000') {
             $response = $this->getResponse(ReturnCode::$OTHERERROR, json_encode($ret));
             $this->get('logger')->err($ret);
         }
     } catch (\Exception $e) {
         $response = $this->getResponse(ReturnCode::$OTHERERROR, "获取验证码失败!请重试");
         $this->get('logger')->err($e);
     }
     return $response;
 }
Beispiel #2
0
 public function validcodeAction()
 {
     $request = $this->getRequest();
     $account = $request->get("account");
     $type = $request->get("type");
     if (empty($type)) {
         $type = "FP";
         //未指定验证码类型时,默认为找回密码类型
     }
     $da = $this->get("we_data_access");
     $re = array("returncode" => ReturnCode::$SUCCESS);
     if (empty($account)) {
         return $this->responseJson(Utils::WrapResultError("帐号不能为空"), $request->get('jsoncallback'));
     }
     try {
         $isEmail = Utils::validateEmail($account);
         $isMobile = Utils::validateMobile($account);
         if (!$isEmail && !$isMobile) {
             return $this->responseJson(Utils::WrapResultError("帐号格式不正确,仅支持邮箱或手机帐号"), $request->get('jsoncallback'));
         }
         $u_staff = new \Justsy\BaseBundle\Management\Staff($da, $this->get("we_data_access_im"), $account, $this->get('logger'));
         $staffinfo = $u_staff->getInfo();
         if (empty($staffinfo)) {
             return $this->responseJson(Utils::WrapResultError("帐号不正确,请您重新输入"), $request->get('jsoncallback'));
         }
         if ($isEmail) {
             $mobile = $staffinfo["mobile_bind"];
             if (empty($mobile)) {
                 return $this->responseJson(Utils::WrapResultOK("该帐号未绑定手机号,你可以通过网页版找回密码"), $request->get('jsoncallback'));
             }
         } else {
             $mobile = $account;
         }
         //验证码获取检查
         $sql = "select (select unix_timestamp( now())-unix_timestamp(req_date) maxlong from we_mobilebind_validcode where login_account=? and actiontype='" . $type . "' and req_date>=SUBDATE(now(),INTERVAL 8 HOUR) order by req_date desc limit 0,1) maxlong,(select count(1) cnt FROM we_mobilebind_validcode where login_account=? and actiontype='" . $type . "' and date(req_date)=date(now())) num";
         $ds = $da->Getdata('wnvc', $sql, array((string) $account, (string) $account));
         $lastgetmobilevaildcodetime = $ds["wnvc"]["rows"][0]["maxlong"];
         $getmobilevaildcodenums = $ds["wnvc"]["rows"][0]["num"];
         if (!empty($lastgetmobilevaildcodetime) && $lastgetmobilevaildcodetime < 60) {
             return $this->responseJson(Utils::WrapResultError("你获取验证码的次数太频繁!每分钟内只能取一次!"), $request->get('jsoncallback'));
         }
         if ($getmobilevaildcodenums >= 5) {
             return $this->responseJson(Utils::WrapResultError("你获取验证码的次数太多!每天最多只能取5次!"), $request->get('jsoncallback'));
         }
         $mobilevaildcode = rand(100000, 999999);
         //根据邮箱找回且没有绑定手机时,发送邮件
         $id = SysSeq::GetSeqNextValue($da, "we_mobilebind_validcode", "id");
         $req_date = getdate();
         if (!empty($mobile)) {
             $content = "验证码:" . $mobilevaildcode . ",2分钟内有效,仅用于" . ($type == "FP" ? "找回密码" : "绑定手机号") . "。 【Wefafa】";
             $ec = new \Justsy\BaseBundle\Controller\SendSMSController();
             $ec->setContainer($this->container);
             $ret = $ec->sendSMSAction($mobile, $content);
             if (strpos($ret, "<errorcode>0</errorcode>") > 0) {
                 $da->ExecSQLs(array("delete from we_mobilebind_validcode where login_account=? and actiontype='" . $type . "' and req_date<date(now())", "insert into we_mobilebind_validcode (id,login_account,req_date,valid_date,validcode,actiontype,mobileno) values\n              (?,?,now(),date_add(now(),interval 2 minute),?,?,?)"), array(array((string) $account), array((string) $id, (string) $account, (string) $mobilevaildcode, (string) $type, (string) $mobile)));
                 return $this->responseJson(Utils::WrapResultOK("验证码已发送到您的手机,收到验证码后进行" . ($type == "FP" ? "重置密码" : "绑定手机号") . "操作"), $request->get('jsoncallback'));
             } else {
                 return $this->responseJson(Utils::WrapResultError("验证码短信发送失败!请稍后重试"), $request->get('jsoncallback'));
             }
         }
     } catch (Exception $e) {
         $this->get('logger')->err($e);
         return $this->responseJson(Utils::WrapResultError("获取验证码错误!请稍后重试"), $request->get('jsoncallback'));
     }
 }
 private function getMobileCode($login_account)
 {
     $da = $this->get('we_data_access');
     $sql = "select login_account,mobile_bind from we_staff where login_account=? or mobile_bind=? or ldap_uid=?;";
     $para = array((string) $login_account, (string) $login_account, (string) $login_account);
     $ds = $da->GetData('we_staff', $sql, $para);
     $result = array();
     if (!$ds || $ds['we_staff']['recordcount'] == 0) {
         $result = array("succeed" => false, "content" => "未存在的Wefafa账号!");
     } else {
         $mobilenumber = $ds["we_staff"]["rows"][0]["mobile_bind"];
         $login_account = $ds["we_staff"]["rows"][0]["login_account"];
         //验证手机号是否合法
         if (!Utils::validateMobile($mobilenumber)) {
             $result = array("succeed" => false, "content" => "绑定的手机号不正确!");
         } else {
             try {
                 $active_code = rand(100000, 999999);
                 //发送短信前选判断
                 $sql = "select submit_num,state_id,last_reg_date,timestampdiff(second,last_reg_date,now()) as dif" . " from we_register where login_account=?";
                 $ds = $da->GetData("we_register", $sql, array($txtmobile));
                 $issend = true;
                 if ($ds && $ds['we_register']['recordcount'] > 0) {
                     if ($ds['we_register']['rows'][0]['dif'] <= 60) {
                         $result = array("succeed" => false, "content" => "你获取验证码的次数太频繁!一分钟只能取一次!!");
                         $issend = false;
                     }
                     if ($ds['we_register']['rows'][0]['submit_num'] >= 3 && $ds['we_register']['rows'][0]['dif'] <= 60 * 60 * 24) {
                         $result = array("succeed" => false, "content" => "你获取验证码的次数太多!每天最多只能取三次!!");
                         $issend = false;
                     } else {
                         if ($ds['we_register']['rows'][0]['dif'] > 60 * 60 * 24) {
                             //一天以后重置
                             $sql = "update we_register set submit_num=0 where login_account=?";
                             $da->ExecSQL($sql, array($login_account));
                         }
                     }
                 }
                 if ($issend) {
                     $content = "您正在使用Wefafa手机密码找回功能,请您在收到本条短信后尽快进行密码修改。本次获得验证码:" . $active_code . "。【发发时代】";
                     $ec = new \Justsy\BaseBundle\Controller\SendSMSController();
                     $ec->setContainer($this->container);
                     $ret = $ec->sendSMSAction($mobilenumber, $content);
                     if (strpos($ret->getContent(), "<errorcode>0</errorcode>") === false) {
                         $result = array("succeed" => false, "content" => "获取并发送短信验证码失败,请重试!");
                     } else {
                         $sql = "insert into we_retrieve_password (id,login_account,req_date,valid_date,valid) values (?,?,now(),adddate(now(),1),'1')";
                         $da->ExecSQL($sql, array($active_code, $login_account));
                         //发送成功后存active_code码
                         $sql = "update we_register set active_code=?,last_reg_date=now(),submit_num=ifnull(submit_num,0)+1," . "state_id='0',review_note='0' where login_account=?";
                         $para = array($active_code, $login_account);
                         $da->ExecSQL($sql, $para);
                         $result = array("succeed" => true, "content" => "短信验证码已成功发送,请注意查收");
                     }
                 }
             } catch (\Exception $e) {
                 $result = array("succeed" => false, "content" => "获取并发送短信验证码失败,请重试!");
             }
         }
     }
     return $result;
 }