Exemple #1
0
  @Path("/get/userInfo")
  @POST
  @Produces("application/json;charset=utf-8")
  public String getUserInfo(@Context HttpServletRequest request, String content) {
    if (StringUtils.isEmpty(content)) {
      return OpenResult.parameterError("无参数").buildJson();
    }
    JSONObject json = JSONObject.parseObject(content);
    String idNumber = json.getString("idNumber");
    String captcha = json.getString("captcha");
    String uuId = json.getString("uuId");
    if (StringUtils.isEmpty(idNumber)
        || StringUtils.isEmpty(captcha)
        || StringUtils.isEmpty(uuId)) {
      return OpenResult.parameterError("参数错误").buildJson();
    }
    try {
      if (!ValidateUtil.isIdNumber(idNumber)) {
        return OpenResult.parameterError(10103, "身份证号有误,请正确填写您的18位身份证号").buildJson();
      }
      if (!ImageCaptchaValidator.validateResponse(uuId, captcha)) {
        return OpenResult.parameterError(10203, "验证码不正确").buildJson();
      }
      JSONObject result = personalService.queryUserInfo(idNumber);
      if (result != null) {
        int retcode = result.getIntValue("retcode");
        if (retcode != 0) {
          return result.toJSONString();
        }
        NoPwdResult pwdResult = new NoPwdResult();
        String mobileNo = result.getString("mobileno");
        mobileNo = InfoMasker.masker(mobileNo, 3, 4, "*", 1);
        pwdResult.setMobileno(mobileNo);

        JSONObject userInfo = new JSONObject();
        userInfo.put("mobileno", result.getString("mobileno"));
        userInfo.put("userid", result.getString("userid"));
        userInfo.put("email", result.getString("email"));
        setMemcacheJSON(idNumber, userInfo);

        return OpenResult.ok().add("data", pwdResult).buildJson();
      } else {
        return OpenResult.unknown("服务异常").buildJson();
      }

    } catch (StockRestException e) {
      log.error("找回密码时获取用户信息异常:" + e);
      return OpenResult.serviceError(e.getRetcode(), e.getMsg()).buildJson();
    } catch (StockServiceException e) {
      log.error("找回密码时获取用户信息异常:" + e);
      return OpenResult.serviceError(e.getRetcode(), e.getMsg()).buildJson();
    }
  }
Exemple #2
0
  /**
   * 登陆
   *
   * @param headers
   * @param content
   * @return
   */
  @Path("/login")
  @POST
  @Produces("application/json;charset=utf-8")
  public String login(
      @Context HttpHeaders headers, @Context HttpServletRequest request, String content) {
    if (StringUtils.isBlank(content)) {
      OpenResult.parameterError("无参数").buildJson();
    }
    JSONObject json = JSONObject.parseObject(content);
    String loginName = json.getString("loginname");
    String passwd = json.getString("passwd");
    // 在header中新增 调用应用名称标识(以header 参数传输,名字有用户中心统一分配)app必传参数
    // 登录名类型 1:身份证,2:用户名,3:手机,4:邮箱
    // int nametype = json.getIntValue("nametype");
    String ip = IPUtils.getRemoteIpAdress(request);
    String clientinfo = json.getString("clientinfo");
    String cccode = json.getString("cccode");

    if (StringUtils.isBlank(loginName) || StringUtils.isBlank(passwd)) {
      return OpenResult.parameterError("参数不正确").buildJson();
    }
    // 校验登录名是否符合 手机号 用户名 身份证号 邮箱正确格式
    LoginResult loginResult = null;
    JSONObject result = null;
    try {
      // result = loginOutService.userLogin(loginName, passwd);
      result = loginOutService.userLoginParamAll(loginName, passwd, ip, clientinfo, cccode);
      if (result != null) {
        int retcode = result.getIntValue("retcode");
        String msg = result.getString("msg");

        if (retcode != 0) {
          return OpenResult.parameterError(retcode, msg).buildJson();
        }
        int failtimes = result.getIntValue("failtimes");
        String userId = result.getString("userid");
        // 输入错误次数大于13次 账户友好提示信息
        if ((failtimes == 0 && StringUtils.isEmpty(userId))) {
          return OpenResult.commonError(OpenResult.NOACCESS_ERROR, UserHelp.LOGIN_TIMES_L_13)
              .buildJson();
        } else if (failtimes > 0) {
          if (failtimes < 13) {
            return OpenResult.commonError(OpenResult.NOACCESS_ERROR, UserHelp.LOGIN_TIMES_L_13)
                .buildJson();
          } else {
            return OpenResult.commonError(OpenResult.NOACCESS_ERROR, UserHelp.LOGIN_TIMES_13)
                .buildJson();
          }
        } else {
          loginResult = new LoginResult();
          loginResult.setUserid(userId);
          loginResult.setUniquecode(result.getString("uniquecode"));
          loginResult.setCompanyuser(result.getIntValue("companyuser"));
          loginResult.setRegtime(result.getString("regtime"));
          loginResult.setUserstatus(result.getIntValue("userstatus"));
          loginResult.setFailtimes(result.getIntValue("failtimes"));
          loginResult.setFrozenremainseconds(result.getIntValue("frozenremainseconds"));
          loginResult.setLastsuccesstime(result.getString("lastsuccesstime"));

          JSONObject userContrInfo = personalService.getUserInfo(userId);
          String mobileNo = null;
          String idnumber = null;
          String realname = null;
          if (userContrInfo != null) {
            retcode = userContrInfo.getIntValue("retcode");
            msg = userContrInfo.getString("msg");
            if (retcode != 0) {
              return OpenResult.parameterError(retcode, msg).buildJson();
            }
            mobileNo = userContrInfo.getJSONObject("user").getString("mobileno");

            idnumber = userContrInfo.getJSONObject("user").getString("idnumber");
            realname = userContrInfo.getJSONObject("user").getString("realname");
          } else {
            return OpenResult.unknown("服务异常").buildJson();
          }

          String sessionId = generateSessionId(loginResult);
          loginResult.setSessionId(sessionId);

          // 将中信证券所需的 mobileno devid 存入session中
          String devId = getDevId(headers);
          JSONObject securitiesInfo = setSecuritiesInfoJson(devId, mobileNo);
          boolean securitiesFlag = setSecuritiesInfo(sessionId, securitiesInfo.toJSONString());
          if (!securitiesFlag) {
            log.debug("登陆时SecuritiesInfo放入缓存结果--" + securitiesFlag);
          }
          mobileNo = InfoMasker.masker(mobileNo, 3, 4, "*", 1);
          loginResult.setMobileno(mobileNo);

          // 将userId放入缓存中
          boolean sign = setMemcacheUserId(sessionId, userId);
          if (!sign) {
            log.debug("登陆时userId放入缓存结果--" + sign);
          }
          String deafultBroker = "ZXZQ";
          // 是否绑定券商
          List<Broker> brokers = accountService.queryBindedBrokers(userId);
          int bindStatus = 0;
          if (CollectionUtils.isEmpty(brokers)) {
            bindStatus = 1;
          } else {
            bindStatus = 2;
          }
          // 资金账号
          String fundAccount = "";
          BindInfo bindInfo = accountService.getBindInfo(userId, deafultBroker);
          if (bindInfo != null) {
            fundAccount = bindInfo.getFundAccount();
          }

          // 是否填写 身份证 真实姓名 1未绑定
          int bindId = 0;
          if (StringUtils.isEmpty(idnumber) || StringUtils.isEmpty(realname)) {
            bindId = 1;
          } else {
            bindId = 2;
          }
          loginResult.setBindStatus(bindStatus);
          loginResult.setBindId(bindId);
          loginResult.setFundAccount(fundAccount);
          loginResult.setDeafultBroker(deafultBroker);
          String str = OpenResult.ok().add("data", loginResult).buildJson();
          return str;
        }

      } else {
        return OpenResult.unknown("服务异常").buildJson();
      }
    } catch (StockServiceException e) {
      log.error("登录异常:" + e);
      return OpenResult.parameterError(result.getIntValue("retcode"), result.getString("msg"))
          .buildJson();
    } catch (ServiceException e) {
      log.error("登录异常:" + e);
      return OpenResult.serviceError(e.getErrorNo(), e.getErrorInfo()).buildJson();
    } catch (Exception e) {
      log.error("登录异常:" + e);
      return OpenResult.unknown(e.getMessage()).buildJson();
    }
  }