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}) @ ...
随机推荐
- MDK GCC调试
openocd调试 https://blog.csdn.net/chunyexixiaoyu/article/details/120448515
- JS中面向对象的多种继承方式
JS本身是基于面向对象开发的编程语言,面向对象开发中最重要的一个概念就是类. 类具有三大特性:封装.继承.多态 封装:类也是个函数,函数的目的是把一个功能代码进行封装,以此实现"低耦合高内聚 ...
- MS14-064/CVE-2014-6332漏洞复现(OLE远程代码执行漏洞、IE浏览器漏洞)
漏洞介绍:MS14-064 Microsoft Internet Explorer Windows OLE Automation Array Remote Code Execution,主要利用IE浏 ...
- 对Frobenius 范数的理解
Frobenius 范数是一种矩阵范数,记为 ∣ ∣ ⋅ ∣ ∣ F ||·||_F ∣∣⋅∣∣F,定义为一个矩阵所有元素平方和的开方,即 ∣ ∣ X ∣ ∣ F = ∑ i ∑ j x i , j ...
- linux 下 配置 nginx
服务器:centOS7 安装nginx之前操作: yum install -y pcre pcre-devel // pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http ...
- C# 设置桌面为父窗口
#region 设置桌面为父窗口 IntPtr hDesktop; public const int GW_CHILD = 5; public IntPtr GetDesktopHandle(Desk ...
- JavaScript&TypeScript学习总结
目录 一.JavaScript学习总结 1.什么是JavaScript 2.变量 3.变量命名 4.操作符 5.遍历语句 6.函数 7.对象 8.数组 二.TypeScript学习总结 1.什么是Ty ...
- Windows流媒体怎么关闭。
点击白色框,搜索服务. 步骤阅读 步骤阅读 2 选本地服务旁打开,然后下拉服务. 步骤阅读 步骤阅读 3 选择media,然后右键它属性. 步骤阅读 步骤阅读 4 然后点击停止,点击手动. 步骤阅读 ...
- 用 go 实现多线程下载器
本篇文章我们用Go实现一个简单的多线程下载器. 1.多线程下载原理 通过判断下载文件链接返回头信息中的 Accept-Ranges 字段,如果为 bytes 则表示支持断点续传. 然后在请求头中设置 ...
- ES6-Class类上
一.基础认知 构造方法有点类似构造函数,前面学的构造函数是模拟类的,ES6用类即可 不能直接调用Person()报错,和构造函数不同,构造函数不加new调用也不报错: 一般在constructor里面 ...