实现签署回调功能
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class DigesdateUtils {
|
||||
|
||||
public static String getSignStr(String paramsStr, String accessSec ) {
|
||||
Mac macDiges = null;
|
||||
try {
|
||||
macDiges = Mac.getInstance("HmacSHA256");
|
||||
SecretKeySpec accessSecKey = new SecretKeySpec(accessSec.getBytes("UTF-8"), "HmacSHA256");
|
||||
macDiges.init(accessSecKey);
|
||||
macDiges.update(paramsStr.getBytes("UTF-8"));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return byteTrasferhex(macDiges.doFinal());
|
||||
}
|
||||
|
||||
public static String byteTrasferhex(byte[] byteArrayData) {
|
||||
StringBuilder hashBuilder = new StringBuilder();
|
||||
String stmpHex;
|
||||
for (int n = 0; byteArrayData != null && n < byteArrayData.length; n++) {
|
||||
stmpHex = Integer.toHexString(byteArrayData[n] & 0XFF);
|
||||
if (stmpHex.length() == 1){
|
||||
hashBuilder.append('0');
|
||||
}else {
|
||||
hashBuilder.append(stmpHex);
|
||||
}
|
||||
}
|
||||
return hashBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -243,7 +243,7 @@ public class FixSelectFlowDetailUtils {
|
||||
/*
|
||||
定时查询签署流程详情
|
||||
*/
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
// @Scheduled(cron = "0/10 * * * * ?")
|
||||
@Transactional
|
||||
public void fixExecuteSelectFlowDetailUtils() {
|
||||
Gson gson = new Gson();
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.ruoyi.common.utils.SealUtil;
|
||||
import com.ruoyi.wisdomarbitrate.domain.dto.dept.DeptIdentify;
|
||||
import com.ruoyi.wisdomarbitrate.domain.dto.mscase.SealSignRecord;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.base.StringIdsReq;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -22,6 +23,9 @@ public class SignAward {
|
||||
private static String eSignAppId = EsignApplicaConfig.EsignAppId;
|
||||
private static String eSignAppSecret = EsignApplicaConfig.EsignAppSecret;
|
||||
|
||||
@Value("${signSealCallbackConfig.url}")
|
||||
private static String signSealCallbackUrl;
|
||||
|
||||
|
||||
public static void main(String[] args) throws EsignDemoException {
|
||||
Gson gson = new Gson();
|
||||
@@ -351,7 +355,7 @@ public class SignAward {
|
||||
" \"signConfig\": {\n" +
|
||||
" \"availableSignClientTypes\": \"1\"\n" +
|
||||
" },\n" +
|
||||
|
||||
" \"notifyUrl\": \"" + signSealCallbackUrl + "\",\n" +
|
||||
" \"autoFinish\": true\n" +
|
||||
" },\n" +
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import com.ruoyi.common.utils.EsignApplicaConfig;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
public class SignVerifyUtils {
|
||||
private static String eSignAppSecret = EsignApplicaConfig.EsignAppSecret;
|
||||
|
||||
|
||||
public static boolean checkSignuter() throws Exception {
|
||||
HttpServletRequest httprequest = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
|
||||
String orialsignature = httprequest.getHeader("X-Tsign-Open-SIGNATURE");
|
||||
String timestampreq = httprequest.getHeader("X-Tsign-Open-TIMESTAMP");
|
||||
String reqQuerystr =getHttpreqQuery();
|
||||
//获取请求参数
|
||||
String reqbodystr =getRequestBody();
|
||||
String signOriaData = timestampreq + reqQuerystr + reqbodystr;
|
||||
String newDisgSignuter= DigesdateUtils.getSignStr(signOriaData, eSignAppSecret);
|
||||
|
||||
System.out.println("请求参数timestampreq:----------->>>>>>"+timestampreq);
|
||||
System.out.println("请求参数reqQuerystr:---------->>>>>>"+reqQuerystr);
|
||||
System.out.println("请求参数reqbodystr:---------->>>>>>"+reqbodystr);
|
||||
System.out.println("加密出来的签名值:----------->>>>>>"+newDisgSignuter);
|
||||
System.out.println("header里面的签名值:---------->>>>>>"+orialsignature);
|
||||
|
||||
if (StringUtils.equals(orialsignature, newDisgSignuter)) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHttpreqQuery() {
|
||||
HttpServletRequest httprequest = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
|
||||
List<String> reqNames= new ArrayList();
|
||||
Enumeration<String> httpreqEle =httprequest.getParameterNames();
|
||||
while (httpreqEle.hasMoreElements()){
|
||||
reqNames.add(httpreqEle.nextElement());
|
||||
}
|
||||
Collections.sort(reqNames);
|
||||
String httpreqQuery = "";
|
||||
for (String reqName : reqNames) {
|
||||
String reqvalue = httprequest.getParameter(reqName);
|
||||
httpreqQuery += reqvalue == null ? "" : reqvalue;
|
||||
}
|
||||
System.out.println("获取请求字符串是:---"+httpreqQuery);
|
||||
return httpreqQuery;
|
||||
}
|
||||
|
||||
public static String getRequestBody() {
|
||||
HttpServletRequest httprequest = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
|
||||
String requestBody = "";
|
||||
int reqContentLen = httprequest.getContentLength();
|
||||
if (reqContentLen < 0) {
|
||||
return null;
|
||||
}
|
||||
byte bufByteArray[] = new byte[reqContentLen];
|
||||
try {
|
||||
for (int i = 0; i < reqContentLen;) {
|
||||
int lengthReadInputStream = httprequest.getInputStream().read(bufByteArray, i, reqContentLen - i);
|
||||
if (lengthReadInputStream == -1) {
|
||||
break;
|
||||
}
|
||||
i += lengthReadInputStream;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
requestBody = new String(bufByteArray, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user