ResponseUtil 请求返回
package com.infosec.sso.common; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import org.openid4java.message.ParameterList;
import org.springframework.util.StringUtils; import com.alibaba.fastjson.JSON;
import com.infosec.sso.authentication.IDInfo;
import com.infosec.sso.ssoprotocol.openid.util.OpenIdProviderService;
import com.netauth.utils.currentuser.LoginUserUtil; /**
*
* <p>
* {输出JSON}
* </p>
*
* @author: jlcui
* @date: 2019年9月21日下午5:17:41
*
*/
public class ResponseUtil { private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ResponseUtil.class); /**
* 使用response输出JSON
* @param response
* @param resultMap
*/
public static void out(HttpServletResponse response, Map<String, Object> resultMap){ ServletOutputStream out = null;
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=UTF-8");
out = response.getOutputStream();
out.write(JSON.toJSON(resultMap).toString().getBytes());
} catch (Exception e) {
e.printStackTrace();
log.error(e + "输出JSON出错");
} finally{
if(out!=null){
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} public static Map<String, Object> resultMap(boolean flag, Integer code, String msg){ return resultMap(flag, code, msg, null,null,false);
} public static Map<String, Object> resultMap(boolean flag, Integer code, String msg, String redirectUrl,Object data,boolean resetpwd){ Map<String, Object> resultMap = new HashMap<String, Object>(16);
resultMap.put("success", flag);
resultMap.put("message", msg);
resultMap.put("code", code);
resultMap.put("timestamp", System.currentTimeMillis());
resultMap.put("redirectUrl",redirectUrl);
resultMap.put(LoginUserUtil.USER_RESER_PWD,resetpwd);
if(data!=null){
resultMap.put("result", data);
}
return resultMap;
} public static Map<String, Object> resultMap(Integer code, String msg){ Map<String, Object> resultMap = new HashMap<String, Object>(16);
resultMap.put("msg", msg);
resultMap.put("ret", code);
resultMap.put("timestamp", System.currentTimeMillis());
return resultMap;
} public static Map<String, Object> resultMap(boolean flag, String code, String msg){ Map<String, Object> resultMap = new HashMap<String, Object>(16);
resultMap.put("success", flag);
resultMap.put("message", msg);
resultMap.put("code", code);
resultMap.put("timestamp", System.currentTimeMillis());
return resultMap;
}
public static Map<String, Object> resultMap(boolean flag, Integer code, String msg, String redirectUrl,Object data,boolean resetpwd,String token){ Map<String, Object> resultMap = new HashMap<String, Object>(16);
resultMap.put("success", flag);
resultMap.put("message", msg);
resultMap.put("code", code);
resultMap.put("timestamp", System.currentTimeMillis());
resultMap.put("redirectUrl",redirectUrl);
resultMap.put("token", token);
resultMap.put(LoginUserUtil.USER_RESER_PWD,resetpwd);
if(data!=null){
resultMap.put("result", data);
}
return resultMap;
} public static String isOpenid(String redirectUrl,String ssoHost,IDInfo inInfo,String tgc){
if(!StringUtils.isEmpty(redirectUrl) && redirectUrl.contains("openid.ns")) {
String[] requestParam = redirectUrl.split("&");
Map<String,String> parameters = new HashMap<String, String>();
for(String param : requestParam){
Integer arr = param.indexOf("=");
if(arr>0) {
parameters.put(param.substring(0, arr), param.substring(arr+1, param.length()));
}
}
ParameterList requestParameters = new ParameterList(parameters);
redirectUrl = new OpenIdProviderService().sendSuccessfulResponse(
requestParameters,
inInfo,
ssoHost+"/ssoserver/openid/getopenid",
tgc,
ssoHost);
}
return redirectUrl;
} public static Map<String, Object> resultJwtMap(String token, String username,String msg,String stat) { Map<String, Object> resultMap = new HashMap<String, Object>(16);
if (!StringUtils.isEmpty(token)) {
resultMap.put("token", token);
}
if (!StringUtils.isEmpty(username)) {
resultMap.put("username", username);
}
resultMap.put("message", msg);
resultMap.put("stat", stat);
return resultMap;
} /**
* <p>
* Description: 手机oauth认证,信息返回值构造
* </p>
* @param success
* @param code
* @param msg
* @return
*
* @author Tianzy
*
* 2019年10月24日 上午11:28:08
*
*/
public static Map<String, Object> buildResultByMobileOauth(boolean success, String code,String msg) { Map<String, Object> resultMap = new HashMap<String, Object>(16);
if(success) {
resultMap.put("ret", 0) ;
}else {
resultMap.put("ret", 1) ;
}
resultMap.put("code", code) ;
resultMap.put("msg", msg) ; return resultMap;
} }
ResponseUtil 请求返回的更多相关文章
- ionic 发送请求返回一直都是404
在web端调试一直都没有问题,生成app之后发现所有的请求返回的都是404, 断掉wifi和4G之后发送的也是404 原因是未引入插件 解决方法是在根目录下执行一下命令 cordova plugin ...
- ajax请求返回数据,模板中的数据处理
/*ajax请求返回数据,模板中的数据处理*/ function QueryGameAsset(){ var new_start_time=$('#new_start_time').val();//开 ...
- postman简单教程,如何在请求中引用上次请求返回的值
做接口测试,一定会遇到这种情况,需要拿上次请求的值在本次请求中使用,比如,我们去测试一个东西,要去登录才能做其他的操作,需要拿到登录返回数据中的某些字段,比如,token啊等... 如果发一次请求,就 ...
- 如何解决http请求返回结果中文乱码
如何解决http请求返回结果中文乱码 1.问题描述 http请求中,请求的结果集中包含中文,最终以乱码展示. 2.问题的本质 乱码的本质是服务端返回的字符集编码与客户端的编码方式不一致. 场景的如服务 ...
- ajaxSubmit请求返回数据成功,但是不执行success回调函数
最近项目涉及到附件上传就头痛,一直在用plupload插件在做...ie9偶尔抽风但还是可以的... 然后有个需求,表格每行都有个上传按钮,页面多上传按钮. 一.开始的时候,用plupload做的,多 ...
- java 接口请求返回通用json
public class BaseResponseBody { // 不能添加属性 仅做泛型使用 } public class ResponseBase<T extends BaseRespon ...
- nodejs request-promise 请求返回中文乱码
nodejs request-promise 请求返回中文乱码 解决方法: 具体步骤如下: 1. 引用iconv-lite 进行转码. 2. 请求时要写参数:encoding:null 3. 对bod ...
- 在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法
在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法 最近在做一个小东西,使用kindeditor上传图片的时候,自己写了一个上传的方法,按照协议规则通过ajax返回json ...
- HP发送HTTP POST请求 返回结果
HP发送HTTP POST请求 返回结果 <?php $srv_ip = '192.168.10.188';//你的目标服务地址或频道.$srv_port = 80;$url = '/demo/ ...
- ajax异步请求返回对象
使用ajax异步请求返回一个对象. java code: @RequestMapping({"getAstSingleWheelImg_bbs"+Constant.JSON}) @ ...
随机推荐
- vue实现记录分享是否有上级
前言: 项目需要做活动分享功能(增加网站.app等访问量),但是,,,无功不受禄,也就需要分享时带上级ID,好友中奖,本人也受同样优惠 需求开发: 开发一个活动后,本人参加之后,分享给好友,增加自身中 ...
- thymeleaf checkbox的回显
最近用到了一些thymeleaf 的界面,有写问题一并写出来,如果这篇文章能给你带来帮助不胜荣幸,如果有问题,也请予以批评和改正 第一就是涉及到复选框的一个回显:例如我是单个复选框的是否选中 在< ...
- Spring全家桶(二)之SpringMVC总结
SpringMVC面试题 关于Spring,SpringMVC,SpringBoot三者的源码等解析,会在博客园上详细整理! 这个仅仅是面试题整理 SpringMVC工作原理 1.是否需要在类路径中使 ...
- log4net两分钟三步急速搭建日志框架教程(注意System.Configuration.ConfigurationErrorsException: 配置系统未能初始化 ---> System.Configuration.ConfigurationErrorsException: )
最近接了个活,winform的帮人做几个页面,这里就以winform项目为例了,之前log4net都是项目中继承好了的,这次自己研究从0到1搭建了一个,发现其实也蛮简单的,主要分为以下三步和一个注意事 ...
- Kubernetes 1.26.0 集群部署Prometheus监控
前言 该存储库收集 Kubernetes 清单.Grafana仪表板和Prometheus 规则,结合文档和脚本,使用Prometheus Operator提供易于操作的端到端 Kubernetes ...
- Prometheus 特点
1.1 Prometheus的特点 Prometheus是一个开源的完整监控解决方案,其对传统监控系统的测试和告警模型进行了彻底的颠覆,形成了基于中央化的规则计算.统一分析和告警的新模型. 相比于传统 ...
- HIVE-文字提取
regexp_extract(filed,('aaa|bbb|ccc|ddd'),0) 从字段filed中提取含有aaa或bbb或ccc或ddd的string信息
- 教你快速理解Linux虚拟化网络的全脉络,正确配置网络联通性。
https://www.bilibili.com/video/BV1iy4y177f4?p=12 实用的干货快先码起来,说不定以后会用到哟
- errgroup.Group
在一组 Goroutine 中提供了同步.错误传播以及上下文取消的功能,我们可以使用如下所示的方式并行获取网页的数据: package main import ( "fmt" &q ...
- C# 通过程序执行svn更新或提交更改
实现方法: private static void RunBat(string program, string parm) { try { Process proc = new Process(); ...