This commit is contained in:
fang 2024-11-13 15:03:13 +08:00
parent a1e4af12b9
commit af325e0125
1 changed files with 15 additions and 22 deletions

View File

@ -1,7 +1,7 @@
package shkd.sys.sys.midservice.utils; package shkd.sys.sys.midservice.utils;
import cn.hutool.crypto.SmUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.bes.mq.org.apache.commons.codec.digest.DigestUtils;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper;
@ -11,8 +11,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -26,19 +24,18 @@ import java.util.Map;
public class RequestClient { public class RequestClient {
private static RequestClient _instance; private static RequestClient _instance;
private static final Logger logger = LoggerFactory.getLogger(RequestClient.class); private static final Logger logger = LoggerFactory.getLogger(RequestClient.class);
// application/x-www-form-urlencoded
private final String protocal;//http private final String protocal;//http
private final String ip;// 域名 private final String ip;// 域名
private final String port;// 端口 private final String port;// 端口
private final String clientKey;// 系统标识 private final String clientKey;// 系统标识
// private String clientSecret_scict;// clientSecret-scict private final String clientSecret;// clientSecret-scict
private RequestClient() { private RequestClient() {
this.protocal = System.getProperty("backlog-protocal"); this.protocal = System.getProperty("backlog-protocal");
this.ip = System.getProperty("backlog-ip"); this.ip = System.getProperty("backlog-ip");
this.port = System.getProperty("backlog-port"); this.port = System.getProperty("backlog-port");
this.clientKey= System.getProperty("clientKey-scict"); this.clientKey= System.getProperty("clientKey-scict");
// this.clientSecret_scict= System.getProperty("clientSecret-scict"); this.clientSecret= System.getProperty("clientSecret-scict");
} }
/** /**
* 获取中台服务客户端实例 * 获取中台服务客户端实例
@ -58,14 +55,8 @@ public class RequestClient {
* @param body JSON格式字符串 * @param body JSON格式字符串
* @return 响应结果报文 * @return 响应结果报文
*/ */
public String callService(String url, String body) throws NoSuchAlgorithmException { public String callService(String url, String body){
/*Map<String, String> header = new HashMap<>();
header.put("systemid", this.clientKey);
header.put("sign",this.clientSecret_scict);
header.put("Content-Type", "application/x-www-form-urlencoded");*/
// header.put("Content-Type", "application/json; charset=utf-8");
Map<String, String> headers = getHeaders(); Map<String, String> headers = getHeaders();
logger.info("获得headers的方法结束"+JSON.toJSONString(headers));
StringBuffer urlStr = new StringBuffer(); StringBuffer urlStr = new StringBuffer();
urlStr.append(this.protocal).append("://").append(this.ip); urlStr.append(this.protocal).append("://").append(this.ip);
if (!StringUtils.isEmpty(this.port)) { if (!StringUtils.isEmpty(this.port)) {
@ -84,15 +75,17 @@ public class RequestClient {
return responseText; return responseText;
} }
private Map<String, String> getHeaders() throws NoSuchAlgorithmException { private Map<String, String> getHeaders(){
MessageDigest md5 = MessageDigest.getInstance("MD5"); Map<String,String> header=new HashMap<>();
byte[] md5Bytes = md5.digest(this.clientKey.getBytes()); String timestamp = Long.toString(System.currentTimeMillis() / 1000);
/*String md5Str = HexUtil.bytes2Hex(md5Bytes).toUpperCase();*/ byte[] securityKey = this.clientKey.substring(10, 26).getBytes();
HashMap<String, String> map = new HashMap(); String authenticationCode = SmUtil.sm4(securityKey).encryptHex(clientKey + clientSecret + timestamp);
map.put("systemid", this.clientKey); header.put("authen", authenticationCode);
/* map.put("sign", md5Str);*/ header.put("clientKey", clientKey);
map.put("Content-Type", "application/x-www-form-urlencoded"); header.put("timestamp", timestamp);
return map; header.put("origin_client", "HttpToken");
logger.info("###authen(sign)"+authenticationCode+"###时间戳"+timestamp);
return header;
} }
/*** /***
* 保存待办日志 * 保存待办日志