Esempio n. 1
0
  /**
   * 注册
   *
   * @param headers
   * @param request
   * @param content
   * @return
   */
  @Path("/regist")
  @POST
  @Produces("application/json;charset=utf-8")
  public String mobileRegist(
      @Context HttpHeaders headers, @Context HttpServletRequest request, String content) {
    if (StringUtils.isBlank(content)) {
      return OpenResult.parameterError("无参数").buildJson();
    }
    JSONObject json = JSONObject.parseObject(content);
    String mobileno = json.getString("mobileno");
    String passwd = json.getString("passwd");
    String validcode = json.getString("validcode");
    // 以上参数是必传参数
    if (StringUtils.isEmpty(mobileno)
        || StringUtils.isEmpty(passwd)
        || StringUtils.isEmpty(validcode)) {
      return OpenResult.parameterError("参数错误").buildJson();
    }
    // 以下参数为非必传参数
    // String clientinfo = json.getString("clientinfo");
    // String ip = IPUtils.getRemoteIpAdress(request);
    // int usedefaulttemplate = 1;
    // String smstemplate = "";
    // String cccode = json.getString("cccode");
    try {
      // 验证手机号格式是否正确
      boolean flag = ValidateUtil.isMobile(mobileno);
      if (!flag) {
        return OpenResult.serviceError(10119, "手机号码有误").buildJson();
      }
      // 检验手机号是否被注册
      JSONObject result = registService.mobileUnique(mobileno);

      if (result != null) {
        if (result.getIntValue("retcode") != 0) {
          return OpenResult.parameterError(result.getIntValue("retcode"), result.getString("msg"))
              .buildJson();
        }
      } else {
        return OpenResult.unknown("服务异常").buildJson();
      }

      // 检验验证码
      JSONObject codeJson =
          registService.checkIdentifyingCode(mobileno, CodeType.REGISTER.type, validcode);

      if (codeJson != null) {
        Integer retcode = codeJson.getInteger("retcode");
        String msg = codeJson.getString("msg");
        if (retcode != 0) {
          return OpenResult.parameterError(retcode, msg).buildJson();
        }
      } else {
        return OpenResult.unknown("服务异常").buildJson();
      }
      // JSONObject re = registService.mobileRegistParamAll(mobileno,
      // passwd, validcode, ip, clientinfo,cccode);
      JSONObject re = registService.mobileRegist(mobileno, passwd, validcode);
      if (re != null) {
        if (re.getInteger("retcode") != 0) {
          return OpenResult.parameterError(re.getIntValue("retcode"), re.getString("msg"))
              .buildJson();
        }
        String userId = re.getString("userid");
        LoginResult loginResult = new LoginResult();
        loginResult.setUserid(userId);
        loginResult.setMobileno(mobileno);
        loginResult.setUserstatus(re.getInteger("userstatus"));
        loginResult.setRegtime(re.getString("regtime"));

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

        UserRegInfoResult infoResult = new UserRegInfoResult();
        infoResult.setMobileno(mobileno);
        infoResult.setRegtime(re.getString("regtime"));
        infoResult.setSessionId(sessionId);
        infoResult.setUserid(userId);
        infoResult.setUserstatus(re.getInteger("userstatus"));

        // 将中信证券所需的 mobileno devid 存入session中
        String devId = getDevId(headers);
        JSONObject securitiesInfo = setSecuritiesInfoJson(devId, mobileno);
        ;
        boolean securitiesFlag = setSecuritiesInfo(sessionId, securitiesInfo.toJSONString());
        if (!securitiesFlag) {
          log.debug("注册时SecuritiesInfo放入缓存结果--" + securitiesFlag);
        }

        // 将userId放入缓存中
        boolean sign = setMemcacheUserId(sessionId, userId);
        if (!sign) {
          log.debug("注册时userId放入缓存结果--" + sign);
        }

        return OpenResult.ok().add("data", infoResult).buildJson();
      } else {
        return OpenResult.unknown("服务异常").buildJson();
      }
    } catch (StockServiceException e) {
      log.error("注册异常:" + e);
      return OpenResult.serviceError(e.getRetcode(), e.getMsg()).buildJson();
    } catch (Exception e) {
      log.error("注册异常:" + e);
      return OpenResult.unknown(e.getMessage()).buildJson();
    }
  }