12 changed files with 675 additions and 8 deletions
@ -0,0 +1,153 @@ |
|||
package com.kms.config; |
|||
|
|||
import java.security.MessageDigest; |
|||
import java.security.Security; |
|||
import org.bouncycastle.jce.provider.BouncyCastleProvider; |
|||
import org.bouncycastle.util.encoders.Hex; |
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
|
|||
public abstract class SHACoder { |
|||
|
|||
/** |
|||
* SHA加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return byte[] 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static byte[] encodeSHA(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.sha(data); |
|||
} |
|||
|
|||
/** |
|||
* SHAHex加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return String 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static String encodeSHAHex(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.shaHex(data); |
|||
} |
|||
|
|||
/** |
|||
* SHA-224加密 |
|||
* |
|||
* @param data |
|||
* 待加密数据 |
|||
* @return byte[] 消息摘要 |
|||
* |
|||
* @throws Exception |
|||
*/ |
|||
public static byte[] encodeSHA224(byte[] data) throws Exception { |
|||
// 加入BouncyCastleProvider支持
|
|||
Security.addProvider(new BouncyCastleProvider()); |
|||
|
|||
// 初始化MessageDigest
|
|||
MessageDigest md = MessageDigest.getInstance("SHA-224"); |
|||
|
|||
// 执行消息摘要
|
|||
return md.digest(data); |
|||
} |
|||
|
|||
/** |
|||
* SHA-224加密 |
|||
* |
|||
* @param data |
|||
* 待加密数据 |
|||
* @return byte[] 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static String encodeSHA224Hex(byte[] data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
byte[] b = encodeSHA224(data); |
|||
|
|||
// 做十六进制编码处理
|
|||
return new String(Hex.encode(b)); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* SHA256加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return byte[] 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static byte[] encodeSHA256(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.sha256(data); |
|||
} |
|||
|
|||
/** |
|||
* SHA256Hex加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return String 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static String encodeSHA256Hex(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.sha256Hex(data); |
|||
} |
|||
|
|||
/** |
|||
* SHA384加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return byte[] 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static byte[] encodeSHA384(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.sha384(data); |
|||
} |
|||
|
|||
/** |
|||
* SHA384Hex加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return String 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static String encodeSHA384Hex(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.sha384Hex(data); |
|||
} |
|||
|
|||
/** |
|||
* SHA512Hex加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return byte[] 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static byte[] encodeSHA512(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.sha512(data); |
|||
} |
|||
|
|||
/** |
|||
* SHA512Hex加密 |
|||
* |
|||
* @param data 待加密数据 |
|||
* @return String 消息摘要 |
|||
* @throws Exception |
|||
*/ |
|||
public static String encodeSHA512Hex(String data) throws Exception { |
|||
|
|||
// 执行消息摘要
|
|||
return DigestUtils.sha512Hex(data); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,111 @@ |
|||
package com.kms.config; |
|||
|
|||
import cn.hutool.core.lang.UUID; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.http.HttpRequest; |
|||
import cn.hutool.http.HttpResponse; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.jianwei.common.utils.http.HttpUtils; |
|||
import com.jwtech.util.HttpUtil; |
|||
import com.kms.common.http.utils.HttpClientUtils; |
|||
import com.kms.config.singleDomain.SingleOrg; |
|||
import lombok.Data; |
|||
import org.apache.http.HttpEntity; |
|||
import org.apache.http.client.HttpClient; |
|||
import org.apache.http.client.methods.HttpGet; |
|||
import org.apache.http.impl.client.HttpClientBuilder; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.context.annotation.PropertySource; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class WaterPortal { |
|||
|
|||
public static String paasToken; |
|||
|
|||
public static String paasId; |
|||
//网关
|
|||
public static String url; |
|||
//登录
|
|||
public static String login; |
|||
|
|||
//单点登录id
|
|||
public static String loginServiceId; |
|||
//单点登录密钥
|
|||
public static String loginAppsecret; |
|||
|
|||
static String ul = "http://19.25.35.204:31190/data_center/gateway/api"; |
|||
static String loginUrl = ul + "/uaa/social/sso"; |
|||
static String getUserUrl = ul + "/usrc/open-api/user/page"; |
|||
static String orgUrl = ul + "/usrc/open-api/org/orgPage"; |
|||
|
|||
|
|||
public static void main(String[] args) throws Exception { |
|||
String timestamp = String.valueOf(new Date().getTime()); |
|||
String nonce = IdUtil.fastSimpleUUID(); |
|||
String paasToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzeXN0ZW1JZCI6IjE3MzI3MDMxMTE1NDc0ODIxMTQifQ.4oiD3WBwrxT5z8goAvA9O88vsYVxwaE-8vyQmWl7xbg"; |
|||
String paasId = "1732703111547482114"; |
|||
|
|||
String signature = timestamp + paasToken + nonce + timestamp; |
|||
signature = SHACoder.encodeSHA256Hex(signature).toUpperCase(); |
|||
|
|||
// HttpResponse httpGet = HttpRequest.get(loginUrl)
|
|||
// .header("x-tsp-target",paasId)
|
|||
// .header("x-tsp-uid-type","id")
|
|||
// .header("x-tsp-uid","20231207000003")
|
|||
// .header("x-tsp-paasid",paasId)
|
|||
// .header("x-tsp-signature",signature)
|
|||
// .header("x-tsp-timestamp",timestamp)
|
|||
// .header("x-tsp-serviceid","DGSP_1606192265703567361")
|
|||
// .header("x-tsp-nonce", nonce)
|
|||
// .header("x-tsp-appsecret","92c8749c5a424758ba550f3cc79cf882")
|
|||
// .execute();
|
|||
|
|||
//获取用户
|
|||
// HashMap<String, Object> hashMap = new HashMap<>();
|
|||
// hashMap.put("page",1);
|
|||
// hashMap.put("size",100);
|
|||
// hashMap.put("systemCode","sgc-jg");
|
|||
// HttpResponse httpGet = HttpRequest.post(getUserUrl)
|
|||
// .header("x-tsp-paasid","1732703111547482114")
|
|||
// .header("x-tsp-signature",signature)
|
|||
// .header("x-tsp-timestamp",timestamp)
|
|||
// .header("x-tsp-serviceid","DGSP_1606192265703567361")
|
|||
// .header("x-tsp-nonce", nonce)
|
|||
// .header("x-tsp-appsecret","92c8749c5a424758ba550f3cc79cf882")
|
|||
// .body(JSONObject.toJSONString(hashMap))
|
|||
// .execute();
|
|||
|
|||
|
|||
//获取部门信息
|
|||
HashMap<String, Object> hashMap = new HashMap<>(); |
|||
hashMap.put("page",1); |
|||
hashMap.put("size",100); |
|||
hashMap.put("systemCode","sgc-jg"); |
|||
HttpResponse httpGet = HttpRequest.post(orgUrl) |
|||
.header("x-tsp-paasid","1732703111547482114") |
|||
.header("x-tsp-signature",signature) |
|||
.header("x-tsp-timestamp",timestamp) |
|||
.header("x-tsp-serviceid","DGSP_1606192265703567361") |
|||
.header("x-tsp-nonce", nonce) |
|||
.header("x-tsp-appsecret","92c8749c5a424758ba550f3cc79cf882") |
|||
.body(JSONObject.toJSONString(hashMap)) |
|||
.execute(); |
|||
|
|||
String body = httpGet.body(); |
|||
JSONObject jsonObject = JSONObject.parseObject(body); |
|||
String records = jsonObject.getJSONObject("data").getString("records"); |
|||
List<SingleOrg> singleOrgs = JSONObject.parseArray(records, SingleOrg.class); |
|||
|
|||
System.out.println(body); |
|||
|
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,152 @@ |
|||
package com.kms.config; |
|||
|
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.http.HttpRequest; |
|||
import cn.hutool.http.HttpResponse; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.jianwei.common.core.domain.AjaxResult; |
|||
import com.jianwei.common.exception.CustomException; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
|
|||
@Component |
|||
public class WaterRequestUtil { |
|||
|
|||
@Value("${water.paasToken}") |
|||
public String paasToken; |
|||
@Value("${water.paasId}") |
|||
public String paasId; |
|||
//网关
|
|||
@Value("${water.url}") |
|||
public String url; |
|||
|
|||
//单点登录id
|
|||
@Value("${water.singOnServiceId}") |
|||
public String singOnServiceId; |
|||
//单点登录密钥
|
|||
@Value("${water.singOnAppsecret}") |
|||
public String singOnAppsecret; |
|||
@Value("${water.singOnUrl}") |
|||
public String singOnUrl; |
|||
|
|||
//验证用户登录
|
|||
@Value("${water.userUrl}") |
|||
public String userUrl; |
|||
@Value("${water.authUserServiceId}") |
|||
public String authUserServiceId; |
|||
@Value("${water.authUserAppsecret}") |
|||
public String authUserAppsecret; |
|||
@Value("${water.systemCode}") |
|||
public String systemCode; |
|||
|
|||
//获取部门信息
|
|||
@Value("${orgUrl}") |
|||
public String orgUrl; |
|||
@Value("${water.orgServiceId}") |
|||
public String orgServiceId; |
|||
@Value("${water.orgAppsecret}") |
|||
public String orgAppsecret; |
|||
|
|||
|
|||
/** |
|||
* 设置 |
|||
* @param httpRequest |
|||
* @param serviceId |
|||
* @param appsecret |
|||
*/ |
|||
private void setHead(HttpRequest httpRequest,String serviceId,String appsecret){ |
|||
String timestamp = String.valueOf(new Date().getTime()); |
|||
String nonce = IdUtil.fastSimpleUUID(); |
|||
String signature = timestamp + paasToken + nonce + timestamp; |
|||
try { |
|||
signature = SHACoder.encodeSHA256Hex(signature).toUpperCase(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
httpRequest |
|||
.header("x-tsp-paasid",paasId) |
|||
.header("x-tsp-signature",signature) |
|||
.header("x-tsp-timestamp",timestamp) |
|||
.header("x-tsp-nonce", nonce) |
|||
.header("x-tsp-serviceid",serviceId) |
|||
.header("x-tsp-appsecret",appsecret); |
|||
} |
|||
|
|||
|
|||
public HttpRequest createGet(String url,String serviceId,String appsecret){ |
|||
HttpRequest httpRequest = HttpRequest.get(url); |
|||
setHead(httpRequest,serviceId,appsecret); |
|||
return httpRequest; |
|||
} |
|||
|
|||
public HttpRequest createPost(String url,String serviceId,String appsecret){ |
|||
HttpRequest httpRequest = HttpRequest.post(url); |
|||
setHead(httpRequest,serviceId,appsecret); |
|||
return httpRequest; |
|||
} |
|||
|
|||
/** |
|||
* 单点登录 |
|||
* @return |
|||
*/ |
|||
public WaterResult signOn(String userId){ |
|||
HttpRequest get = createGet(userUrl,singOnServiceId,singOnAppsecret); |
|||
HttpResponse response = get.header("x-tsp-target", paasId) |
|||
.header("x-tsp-uid-type", "id") |
|||
.header("x-tsp-uid", userId) |
|||
.execute(); |
|||
String body = response.body(); |
|||
return JSONObject.parseObject(body,WaterResult.class); |
|||
} |
|||
|
|||
/** |
|||
* 验证用户登录 |
|||
* @param authorization |
|||
* @return |
|||
*/ |
|||
public WaterResult authUser(String authorization){ |
|||
HttpRequest get = createGet(userUrl,authUserServiceId,authUserAppsecret); |
|||
HttpResponse response = get.header("Authorization", authorization) |
|||
.execute(); |
|||
String body = response.body(); |
|||
WaterResult waterResult = JSONObject.parseObject(body, WaterResult.class); |
|||
isSuccess(waterResult); |
|||
return waterResult; |
|||
} |
|||
|
|||
|
|||
public WaterResult getOrgPage(){ |
|||
HashMap<String, Object> hashMap = new HashMap<>(); |
|||
hashMap.put("page",1); |
|||
hashMap.put("size",100); |
|||
hashMap.put("systemCode",systemCode); |
|||
HttpRequest get = createPost(userUrl,authUserServiceId,authUserAppsecret); |
|||
HttpResponse response = get.body(JSONObject.toJSONString(hashMap)) |
|||
.execute(); |
|||
String body = response.body(); |
|||
WaterResult waterResult = JSONObject.parseObject(body, WaterResult.class); |
|||
isSuccess(waterResult); |
|||
return waterResult; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
private void isSuccess(WaterResult waterResult){ |
|||
if(waterResult==null){ |
|||
throw new CustomException("请求异常"); |
|||
} |
|||
if(waterResult.getCode()!=200&&waterResult.getSuccess()){ |
|||
throw new CustomException("请求失败,原因:"+waterResult.getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,15 @@ |
|||
package com.kms.config; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
public class WaterResult { |
|||
|
|||
private int code; |
|||
private String message; |
|||
private Boolean success; |
|||
private String data; |
|||
private String timestamp; |
|||
} |
@ -0,0 +1,76 @@ |
|||
package com.kms.config.scheduled; |
|||
|
|||
import cn.hutool.core.bean.BeanUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.jianwei.common.constant.UserConstants; |
|||
import com.jianwei.common.core.domain.AjaxResult; |
|||
import com.jianwei.common.core.domain.entity.SysDept; |
|||
import com.kms.common.utils.BaseEntityUtils; |
|||
import com.kms.config.WaterRequestUtil; |
|||
import com.kms.config.WaterResult; |
|||
import com.kms.config.singleDomain.SingleOrg; |
|||
import com.kms.system.service.SysDeptService; |
|||
import com.kms.system.service.SysUserService; |
|||
import lombok.extern.log4j.Log4j; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.parsing.BeanEntry; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Configuration |
|||
public class UserScheduled { |
|||
|
|||
private static final Logger log = LoggerFactory.getLogger(UserScheduled.class); |
|||
|
|||
@Autowired |
|||
WaterRequestUtil waterRequestUtil; |
|||
|
|||
@Autowired |
|||
SysUserService userService; |
|||
@Autowired |
|||
SysDeptService deptService; |
|||
|
|||
|
|||
// @Scheduled
|
|||
// public void userScheduled(){
|
|||
//
|
|||
//
|
|||
//
|
|||
// }
|
|||
|
|||
|
|||
@Scheduled |
|||
public void orgScheduled(){ |
|||
WaterResult waterResult = waterRequestUtil.getOrgPage(); |
|||
String data = waterResult.getData(); |
|||
String records = JSONObject.parseObject(data).getString("records"); |
|||
List<SingleOrg> singleOrgs = JSONObject.parseArray(records, SingleOrg.class); |
|||
for (SingleOrg singleOrg : singleOrgs) { |
|||
SysDept dept = new SysDept(); |
|||
BaseEntityUtils.preInsert(dept); |
|||
BeanUtils.copyProperties(dept,singleOrg); |
|||
dept.setXzqhId(singleOrg.getArea()); |
|||
dept.setXzqhName(singleOrg.getAreaText()); |
|||
dept.setSingleCode(singleOrg.getCode()); |
|||
dept.setSingleSeq(singleOrg.getSeq()); |
|||
dept.setSingleType(singleOrg.getType()); |
|||
dept.setDeptName(singleOrg.getName()); |
|||
dept.setParentId(singleOrg.getParent()); |
|||
if(singleOrg.getStatus().equals("1")){ |
|||
dept.setStatus("0"); |
|||
} |
|||
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) |
|||
{ |
|||
log.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); |
|||
} |
|||
// dept.setParentId("100");
|
|||
int i = deptService.insertDept(dept); |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,60 @@ |
|||
package com.kms.config.singleDomain; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
public class SingleOrg { |
|||
|
|||
private String address; //机构地址
|
|||
private String area; //机构区域
|
|||
private String areaText; //机构区域描述
|
|||
private String businessScope; //业务范围
|
|||
private String category;//机构类别(单位、部门)
|
|||
private String categoryText;//单位、部门
|
|||
private String code;//机构代码
|
|||
private String parent;//同级父级机构ID
|
|||
private String crossParent; //跨级父级机构ID
|
|||
private String donaQualif;//是否具有公开募捐资格(字典)
|
|||
private String name;//机构名称
|
|||
private String nature;//机构性质
|
|||
private String natureText;//机构性质描述
|
|||
private String level;//机构级别
|
|||
private String levelText;//机构级别名称
|
|||
private String record;//是否备案
|
|||
private String dutyPerson; //机构负责人
|
|||
private String foundDate; //成立时间
|
|||
private String registerDate;//登记日期
|
|||
private String manageOrg;//登记管理机关
|
|||
private String dutyPersonPhone;//负责人联系方式
|
|||
private String expiryDate;//机构有效期
|
|||
|
|||
private String target;//组织建设目标
|
|||
private String promoter;//发起人
|
|||
private String promoterPhone;//发起人联系方式
|
|||
private String source;//机构来源
|
|||
private String volunteerNum;//志愿者人数
|
|||
private String tel;//座机电话
|
|||
private String businessTime;//营业时间
|
|||
|
|||
private String map;//机构经纬度信息
|
|||
private String tifld;//统一社会信用代码
|
|||
private String uscc;//统一身份认证关联id
|
|||
|
|||
private String govOrgId;//监管部门/发起单位Id
|
|||
private String govOrgName;//监管部门/发起单位名称
|
|||
|
|||
private String legalPerson;//法定代表人
|
|||
private String legalPersonNo;//法定代表人身份证
|
|||
private String legalPersonPhone;//法定代表人联系电话
|
|||
|
|||
private String seq; |
|||
private String type; //类型
|
|||
private String id; |
|||
private String status; |
|||
|
|||
|
|||
|
|||
|
|||
} |
Loading…
Reference in new issue