Commit 84b4662a by 袁伟铭

添加请求工具类

parent d770fb9d
...@@ -77,3 +77,12 @@ jwt: ...@@ -77,3 +77,12 @@ jwt:
#日志等级 #日志等级
logging.level.com.zq.*: debug logging.level.com.zq.*: debug
#共享平台接口
share:
appkey: 42bc99fb-1d83-4d5d-8145-707fe523df26
appsecret: 113e2e64-4990-45e1-92bf-3351a8e3c119
#API地址
api-url: http://59.211.219.66:8081
#token获取接口
token-url: http://59.211.219.66:8081/epoint-sso-web/rest/oauth2/token
...@@ -63,3 +63,11 @@ jwt: ...@@ -63,3 +63,11 @@ jwt:
# 续期时间范围,默认 1小时,这里单位毫秒 # 续期时间范围,默认 1小时,这里单位毫秒
renew: 3600000 renew: 3600000
#共享平台接口
share:
appkey:
appsecret:
#API地址
api-url: http://59.211.219.71
#token获取接口
token-url: http://59.211.219.71/share/token
package com.zq.resource.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "share")
public class ShareApiConfig {
private String appkey;
private String appsecret;
private String apiUrl;
private String tokenUrl;
}
...@@ -29,7 +29,7 @@ public class DataCategory { ...@@ -29,7 +29,7 @@ public class DataCategory {
*/ */
@ApiModelProperty("自增") @ApiModelProperty("自增")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private Long id; private String id;
/** /**
* 目录名称 * 目录名称
......
...@@ -29,7 +29,7 @@ public class DataDict { ...@@ -29,7 +29,7 @@ public class DataDict {
*/ */
@ApiModelProperty("自增") @ApiModelProperty("自增")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private Long id; private String id;
/** /**
* 类型代码,如:update_cycle * 类型代码,如:update_cycle
......
...@@ -29,13 +29,13 @@ public class GovAffairItem { ...@@ -29,13 +29,13 @@ public class GovAffairItem {
*/ */
@ApiModelProperty("自增") @ApiModelProperty("自增")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private Long id; private String id;
/** /**
* 机构id * 机构id
*/ */
@ApiModelProperty("机构id") @ApiModelProperty("机构id")
private Long deptId; private String deptId;
/** /**
* 政务服务事项类型: 包括1行政许可、2行政确认、3行政裁决、4行政征收、5行政给付、6行政奖励、7其他行政权力、8公共服务。 * 政务服务事项类型: 包括1行政许可、2行政确认、3行政裁决、4行政征收、5行政给付、6行政奖励、7其他行政权力、8公共服务。
......
...@@ -29,13 +29,13 @@ public class GovMonitorItem { ...@@ -29,13 +29,13 @@ public class GovMonitorItem {
*/ */
@ApiModelProperty("自增") @ApiModelProperty("自增")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private Long id; private String id;
/** /**
* 机构id * 机构id
*/ */
@ApiModelProperty("机构id") @ApiModelProperty("机构id")
private Long deptId; private String deptId;
/** /**
* 监管事项: 类型包括1行政检查、2行政强制、3行政处罚、4其他行政权力。 * 监管事项: 类型包括1行政检查、2行政强制、3行政处罚、4其他行政权力。
......
...@@ -29,7 +29,7 @@ public class InfoMetadata { ...@@ -29,7 +29,7 @@ public class InfoMetadata {
*/ */
@ApiModelProperty("自增") @ApiModelProperty("自增")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private Long id; private String id;
/** /**
* 元数据名称 * 元数据名称
...@@ -41,7 +41,7 @@ public class InfoMetadata { ...@@ -41,7 +41,7 @@ public class InfoMetadata {
* 归属资源目录id * 归属资源目录id
*/ */
@ApiModelProperty("归属资源目录id") @ApiModelProperty("归属资源目录id")
private Long belongCategoryId; private String belongCategoryId;
/** /**
* 数据资源格式: 分为1电子文件、2电子表格、3数据库类、4图形图像类、5流媒体类、6接口类。 * 数据资源格式: 分为1电子文件、2电子表格、3数据库类、4图形图像类、5流媒体类、6接口类。
......
...@@ -29,7 +29,7 @@ public class InfoSystem { ...@@ -29,7 +29,7 @@ public class InfoSystem {
*/ */
@ApiModelProperty("自增") @ApiModelProperty("自增")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private Long id; private String id;
/** /**
* 系统名称 * 系统名称
...@@ -41,7 +41,7 @@ public class InfoSystem { ...@@ -41,7 +41,7 @@ public class InfoSystem {
* 归属部门id * 归属部门id
*/ */
@ApiModelProperty("归属部门id") @ApiModelProperty("归属部门id")
private Long belongDeptId; private String belongDeptId;
/** /**
* 信息系统分类:分为1政务服务业务办理系统、2执法监管系统、3共享交换平台、4办公OA、5视频会商系统、6监控系统、7热线系统、8财务系统、9人事系统、10政府网站。 * 信息系统分类:分为1政务服务业务办理系统、2执法监管系统、3共享交换平台、4办公OA、5视频会商系统、6监控系统、7热线系统、8财务系统、9人事系统、10政府网站。
......
...@@ -29,13 +29,13 @@ public class OrgDept { ...@@ -29,13 +29,13 @@ public class OrgDept {
*/ */
@ApiModelProperty("自增") @ApiModelProperty("自增")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private Long id; private String id;
/** /**
* 上级机构id * 上级机构id
*/ */
@ApiModelProperty("上级机构id") @ApiModelProperty("上级机构id")
private Long parentId; private String parentId;
/** /**
* 机构(部门)名称 * 机构(部门)名称
......
package com.zq.resource.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zq.common.config.redis.RedisUtils;
import com.zq.common.exception.BusinessException;
import com.zq.common.http.HttpClientUtils;
import com.zq.resource.config.ShareApiConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Component
@RequiredArgsConstructor
public class RequestUtils {
private final RedisUtils redisUtils;
private final ShareApiConfig shareApiConfig;
private final String AUTHORIZATION = "shareApiAuthorization";
/**
* 设置token
*
* @param token
* @param expiresTime
*/
public void setAuthorization(String token, long expiresTime) {
redisUtils.setStr(AUTHORIZATION, token, expiresTime);
}
/**
* 获取token
*/
public Map<String, String> getAuthorization() {
Map<String, String> headers = new HashMap<>(2);
headers.put("Content-Type", "application/json;charset=utf-8");
String token = redisUtils.getStr(AUTHORIZATION);
if (StringUtils.isNotBlank(token)) {
headers.put("Authorization", token);
} else {
Map<String, String> params = new HashMap<>();
params.put("grant_type", "client_credentials");
params.put("Content-Type", "application/x-www-form-urlencoded");
params.put("client_id", shareApiConfig.getAppkey());
params.put("client_secret", shareApiConfig.getAppsecret());
String result = HttpClientUtils.doFormPost(shareApiConfig.getTokenUrl(), params);
JSONObject jobj = JSON.parseObject(result);
JSONObject status = jobj.getJSONObject("status");
if (status != null) {
String code = status.getString("code");
if ("1".equals(code)) {
token = jobj.getJSONObject("custom").getString("access_token");
headers.put("Authorization", token);
}
}
}
if (StringUtils.isNotBlank(token)) {
return headers;
}
throw new BusinessException("获取access_token失败");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment