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 请求返回的更多相关文章

  1. ionic 发送请求返回一直都是404

    在web端调试一直都没有问题,生成app之后发现所有的请求返回的都是404, 断掉wifi和4G之后发送的也是404 原因是未引入插件 解决方法是在根目录下执行一下命令 cordova plugin ...

  2. ajax请求返回数据,模板中的数据处理

    /*ajax请求返回数据,模板中的数据处理*/ function QueryGameAsset(){ var new_start_time=$('#new_start_time').val();//开 ...

  3. postman简单教程,如何在请求中引用上次请求返回的值

    做接口测试,一定会遇到这种情况,需要拿上次请求的值在本次请求中使用,比如,我们去测试一个东西,要去登录才能做其他的操作,需要拿到登录返回数据中的某些字段,比如,token啊等... 如果发一次请求,就 ...

  4. 如何解决http请求返回结果中文乱码

    如何解决http请求返回结果中文乱码 1.问题描述 http请求中,请求的结果集中包含中文,最终以乱码展示. 2.问题的本质 乱码的本质是服务端返回的字符集编码与客户端的编码方式不一致. 场景的如服务 ...

  5. ajaxSubmit请求返回数据成功,但是不执行success回调函数

    最近项目涉及到附件上传就头痛,一直在用plupload插件在做...ie9偶尔抽风但还是可以的... 然后有个需求,表格每行都有个上传按钮,页面多上传按钮. 一.开始的时候,用plupload做的,多 ...

  6. java 接口请求返回通用json

    public class BaseResponseBody { // 不能添加属性 仅做泛型使用 } public class ResponseBase<T extends BaseRespon ...

  7. nodejs request-promise 请求返回中文乱码

    nodejs request-promise 请求返回中文乱码 解决方法: 具体步骤如下: 1. 引用iconv-lite 进行转码. 2. 请求时要写参数:encoding:null 3. 对bod ...

  8. 在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法

    在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法 最近在做一个小东西,使用kindeditor上传图片的时候,自己写了一个上传的方法,按照协议规则通过ajax返回json ...

  9. HP发送HTTP POST请求 返回结果

    HP发送HTTP POST请求 返回结果 <?php $srv_ip = '192.168.10.188';//你的目标服务地址或频道.$srv_port = 80;$url = '/demo/ ...

  10. ajax异步请求返回对象

    使用ajax异步请求返回一个对象. java code: @RequestMapping({"getAstSingleWheelImg_bbs"+Constant.JSON}) @ ...

随机推荐

  1. CVE-2020-1938 Tomcat AJP漏洞复现

    一  漏洞环境 # vulhub靶场地址 https://github.com/vulhub/vulhub靶场还需要有python环境,pip,docker docker-composeGitHub上 ...

  2. 雪花算法生成id长度过长处理

    思路:将Long类型转成字符串 代码实现: import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.s ...

  3. Ubuntu系统添加新的普通用户

    1.创建一个新的普通用户 创建了可以登录的yang用户并使用/bin/bash作为shell. 设置密码. 为yang用户增加管理员权限. 切换登录用户为yang. sudo useradd -m y ...

  4. oracle的dblink创建连接查询及使用

    https://www.cnblogs.com/muhai/p/15527463.html https://www.cnblogs.com/leipei2352/archive/2011/04/21/ ...

  5. Java笔记_this关键字_HomeWork(9 - 题)

    第九题 /** * @ClassName HomeWork09 * @Description TODO * @Author Orange * @Date 2021/4/26 16:20 * @Vers ...

  6. blog2对PTA4,5,6集的习题总结

    一.      前言 通过本三次PTA得题目,我受益匪浅.题量的话不算太多,但是题目难度有些大.在本次PTA第六次题目集中,题目难度较中,第四次题目集第一道水文数据处理与第五次题目集的查询关键字出现次 ...

  7. 通过一个简单的实例来展示 Java 编程,创建文件 HelloWorld.java

    public class HelloWorld { public static void main(String[] args) { System.out.println("Hello Wo ...

  8. Camstar代码:指定执行某函数

  9. 杂:python获取所有盘符简单粗暴版

    def _test_p_get_all_driver():    l = []    for i in range(97, 123):        d = chr(i) + ':\\'        ...

  10. 【服务器数据恢复】ZFS文件系统下ZPOOL下线的数据恢复案例

    服务器数据恢复环境:SUN ZFS系列某型号存储阵列:40块磁盘组建的存储池(其中4块磁盘用作全局热备盘),池内划分出若干空间映射到服务器使用:服务器使用Windows操作系统. 服务器故障:服务器在 ...