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