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}) @ ...
随机推荐
- OI常见缩写
AC = Apareciym 显形咒 CE = Crucio 钻心咒 PE = Petrificus 石化咒 RE = Reducto 粉碎咒 WA = Wingardium Leviosa 悬浮咒 ...
- python读取图片相关属性
背景:工作中用到一些基础的图片处理的任务,比如获取图片宽高.获取图片的旋转角度等等图片属性,都是比较零散的,这里简单做个记录备忘 这里用到的库exifread,安装 pip isntall exifr ...
- Mac卡顿 CPU占100%的原因Photolibraryd
找到了造成电脑卡顿的元凶,第一步要做的就是杀进程,选中这两个进程,点击上面的结束按钮,世界立马恢复了宁静,高兴的继续码代码,可是好景不长,大约一个小时以后,又特么卡了,"任务管理器" ...
- CentOS7.6下安装MySql和Redis
安装的MySQL为5.7版本1.下载安装官方的Yum Repository [root@localhost ~]# wget http://dev.mysql.com/get/mysql57-comm ...
- Springboot+Vue实现短信与邮箱验证码登录
体验网址:http://mxyit.com 示例 1.新增依赖 <!-- 短信服务 --> <dependency> <groupId>com.aliyun< ...
- 2、k8s 基础环境安装
3 k8s 环境配置 3.1 基础环境准备 所有机器执行 #各个机器设置自己的域名 我的设置为 hostnamectl set-hostname ks8-master.hostnamectl set- ...
- 1、docker 安装
1 准备三台linux服务器 2 docker安装 三台机器全部执行docker安装操作 2.1 移除以前docker相关包 sudo yum remove docker \ docker-clien ...
- Blockchain-enabled Access Control with Fog Nodes for Independent IoTs
摘要: 物联网设备能力有限且数量多,因此当前的传统物联网平台可能无法在可扩展性.可靠性和实时响应方面有效地处理访问控制.本文提出了一种基于区块链.雾节点和物的角色的分散式物联网访问控制系统,利用以太坊 ...
- drools规则的入门使用
1:pom文件 <!--drools--><dependency> <groupId>org.drools</groupId> <artifact ...
- python菜鸟学习: 11. 装饰器的基础用法
# -*- coding: utf-8 -*-# decorator# 定义:本质是函数,就是为其他函数添加附件功能# 原则:# 1.不能修改被装饰的函数的源代码# 2.不能修改被装饰的函数的调用方式 ...