Пример #1
0
  /**
   * 跳转到自主学习中心 教师学生通用接口
   *
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/v1.0/autoLearning")
  public ModelAndView autoLearning(HttpServletRequest request, HttpServletResponse response) {

    /** 默认使用这个 */
    String host = "http://fd.zhihaole.net/";
    String sub = "0101";
    String term = "GZ";

    // 拦截器读取配置文件  写入request
    String currentFDHost = (String) request.getAttribute("currentFdHost");

    // 返回json的结果对象
    ResultJSON result = new ResultJSON();
    // 异常
    CustomException exception = (CustomException) request.getAttribute(CustomException.request_key);
    // 当前登录用户id
    Long currentUserId = (Long) request.getAttribute("currentUserId");
    // 返回
    Object data = null;
    try {
      if (currentUserId != null && exception == null) {
        long userId = currentUserId;
        SRegister record = registerService.getRegister(userId);
        String userName = record.getName();
        Long roleId = record.getRoleid();
        String userPwd = PWDEncrypt.getPWD(record.getPwd());

        HashMap<String, String> map = userService.getUserTermAndSubject(userId);
        if (map != null) {

          sub = map.get("subjectcode");
          term = map.get("termcode");

          if (sub.contains(",")) {
            sub = sub.split(",")[0];
          }
        }

        String params =
            "user="******"&pass="******"&page=1"
                + "&grd="
                + term.toUpperCase()
                + "&sub="
                + sub
                + "&ST="
                + (1 == roleId ? "S" : 2 == roleId ? "T" : 5 == roleId ? "J" : "S");
        String sign = MD5.MD5(params + "&key=9k8i78jug6hd93kjf84h");
        String s = params + "&sign=" + sign;
        byte[] sbytes;
        sbytes = xxtea.encrypt(s.getBytes("utf-8"), "9k8i78jug6hd93kjf84h".getBytes());
        s = Base64.encode(sbytes, 0, sbytes.length);
        s = URLEncoder.encode(s, "utf-8");

        String str =
            ((currentFDHost != null && !"".equals(currentFDHost) && currentFDHost.length() > 0)
                    ? currentFDHost
                    : host)
                + "eblogin.do?s=";
        String url = str + s;
        System.out.println("----autoLearning-----" + url);
        response.sendRedirect(url);

      } else {
        exception = CustomException.INVALIDACCESSTOKEN;
      }
    } catch (Exception e) {
      exception = CustomException.getCustomExceptionByCode(e.getMessage());
      // 如果是普通的异常
      if (exception.getStatus() == 500) {
        e.printStackTrace();
      }
    } finally {

    }
    return null;
  }