• 跨域调用接口代码


       @RequestMapping("/login")
        @ResponseBody
        public void login(HttpServletRequest request, HttpServletResponse response,String params){
            AjaxResult result = new AjaxResult();
            String client_id="";
            response.setHeader("Access-Control-Allow-Origin", "*");  
            response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");  
            response.setHeader("Access-Control-Max-Age", "3600");  
            response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
            response.setHeader("Content-type", "text/html;charset=UTF-8");//解决访问的乱码
            PrintWriter pw = null;
            JSONObject jsonObj=new JSONObject();
            try {
                pw=response.getWriter();
                //用户登录标识 存在且不为空表示 用户已经登录
                String TYSFRZ_TGC = null; 
                //将参数转化成json字符串
                JSONObject paramsJson = JSONObject.fromObject(params);
                //paramsJson 为空,说明传入参数名不对或者参数值不对
                if (paramsJson ==null || paramsJson.isNullObject()) {
                    jsonObj.put("code", JxUiasCodeDefine.CODE_ERROR);
                    jsonObj.put("data", "");
                    jsonObj.put("msg", "请传入参数名为params,值为json格式的字符串的参数!");
                    jsonObj.put("success", false);
                    pw.print(jsonObj.toString());
                    return;
                }
                String data = MCommonUtil.createTicket(TYSFRZ_TGC, authapplicationdo.getLoginout_url());//生成临时票据
                jsonObj.put("code", JxUiasCodeDefine.CODE_SUCCESS);
                jsonObj.put("data", data);
                jsonObj.put("msg", "已经登录,无需再次登录");
                jsonObj.put("success", true);
                AuthAccessLog accessLog = new AuthAccessLog(client_id,new Date(),"login","PC端用户登录",result.getCode());
                saveAccessInfo(accessLog);
                pw.print(jsonObj.toString());
                return;
            } catch (Exception e) {
                log.error(this, e);
                result.setCode(JxUiasCodeDefine.CODE_ERROR);
                result.setData("");
                result.setMsg("操作失败");
                if(StringUtils.isNotBlank(client_id)){
                    AuthAccessLog accessLog = new AuthAccessLog(client_id,new Date(),"login","PC端用户登录",result.getCode());
                    saveAccessInfo(accessLog);
                }
            }
            return;
        }
  • 相关阅读:
    If you want the rainbow, you have to deal with the rain.
    Yesterday is history, tomorrow is a mystery, but today is a gift.
    .bashrc修改环境变量文件后ls之类的不能用了
    Flask项目中使用mysql数据库启动项目是发出警告
    flask 编码问题
    flask 密钥问题
    Flask 数据库连接
    查看cpu核的相关信息
    top命令常用
    gluster设置日志级别
  • 原文地址:https://www.cnblogs.com/jassy/p/10372671.html
Copyright © 2020-2023  润新知