Ver a proveniência

Merge branch 'fea_dev_2023_09_01' into fea_dev_2023_09_07_zhidemaiAndQiHuo

# Conflicts:
#	common/src/main/java/tech/deepq/common/enums/SignatureEnumGroup.java
#	common/src/main/java/tech/deepq/common/utils/signature/AbstractSignatureService.java
#	common/src/main/java/tech/deepq/common/utils/signature/RSASignatureService.java
#	common/src/main/java/tech/deepq/common/utils/signature/SignatureFactory.java
#	source/src/main/java/tech/deepq/source/handler/SourceHandler.java
fea_dev_2023_09_07_zhidemaiAndQiHuo
yechuan há 1 ano
ascendente
cometimento
d4b040edcd
6 ficheiros alterados com 123 adições e 4 eliminações
  1. +4
    -0
      common/src/main/java/tech/deepq/common/enums/SignatureEnumGroup.java
  2. +2
    -2
      common/src/main/java/tech/deepq/common/utils/signature/AbstractSignatureService.java
  3. +37
    -0
      common/src/main/java/tech/deepq/common/utils/signature/MD5SignatureService.java
  4. +1
    -1
      common/src/main/java/tech/deepq/common/utils/signature/RSASignatureService.java
  5. +6
    -1
      source/src/main/java/tech/deepq/source/handler/SourceHandler.java
  6. +73
    -0
      source/src/main/java/tech/deepq/source/util/TokenUtils.java

+ 4
- 0
common/src/main/java/tech/deepq/common/enums/SignatureEnumGroup.java Ver ficheiro

@@ -11,6 +11,7 @@ public class SignatureEnumGroup {
*/
public static enum SignatureLocation{
header,
body,
url
}

@@ -19,6 +20,9 @@ public class SignatureEnumGroup {
* RSA
*/
RSA,
/**
* MD5
*/
MD5
}



+ 2
- 2
common/src/main/java/tech/deepq/common/utils/signature/AbstractSignatureService.java Ver ficheiro

@@ -15,13 +15,13 @@ public abstract class AbstractSignatureService {
protected SignatureContext signatureContext;

/**
* 加密
* 对content进行加密
*
* @param content
* @return
* @throws GeneralSecurityException
*/
public abstract String signature(String content) throws GeneralSecurityException;
public abstract String signatureContent(String content) throws GeneralSecurityException;


void init(SignatureConfig signatureConfig) throws GeneralSecurityException {


+ 37
- 0
common/src/main/java/tech/deepq/common/utils/signature/MD5SignatureService.java Ver ficheiro

@@ -0,0 +1,37 @@
package tech.deepq.common.utils.signature;

import org.springframework.util.DigestUtils;
import tech.deepq.common.dto.SignatureConfig;

import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;

/**
* @author yechuan
* @since 2023/9/1 09:46
**/
public class MD5SignatureService extends AbstractSignatureService {

private final static MD5SignatureService instance = new MD5SignatureService();

private MD5SignatureService() {

}

public static AbstractSignatureService getInstance(SignatureConfig signatureConfig) throws GeneralSecurityException {
return instance;
}

/**
* 对content进行加密
*/
@Override
public String signatureContent(String content) {
return DigestUtils.md5DigestAsHex((content).getBytes(StandardCharsets.UTF_8));
}

@Override
void init(SignatureConfig signatureConfig) {
return;
}
}

+ 1
- 1
common/src/main/java/tech/deepq/common/utils/signature/RSASignatureService.java Ver ficheiro

@@ -32,7 +32,7 @@ class RSASignatureService extends AbstractSignatureService {
}

@Override
public String signature(String content) throws GeneralSecurityException {
public String signatureContent(String content) throws GeneralSecurityException {
if (signatureContext == null) {
throw new RuntimeException("未初始化公私钥对信息");
}


+ 6
- 1
source/src/main/java/tech/deepq/source/handler/SourceHandler.java Ver ficheiro

@@ -34,6 +34,7 @@ import tech.deepq.common.utils.signature.SignatureFactory;
import tech.deepq.source.request.RequestClient;
import tech.deepq.source.spel.CustomRequest;
import tech.deepq.source.spel.ZhiDeMaiRequest;
import tech.deepq.source.util.TokenUtils;

import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
@@ -58,6 +59,7 @@ public class SourceHandler {
private final TaskManager taskManager;
public final Gson gson;
public final ZhiDeMaiRequest zdm;
public final TokenUtils tokenUtils;

public List<Message<HttpRes>> handle(Message<TaskMiniVO> message) {
TaskMiniVO taskMiniVO = message.getPayload();
@@ -220,6 +222,7 @@ public class SourceHandler {
return;
}
}

// 节点命中
List<Dispatcher.NextNodeConfig> nextNodes = filter.getNextNodes();
if (ObjectUtils.isEmpty(nextNodes)) {
@@ -354,10 +357,12 @@ public class SourceHandler {
AbstractSignatureService signatureService = null;
try {
signatureService = SignatureFactory.getSignatureService(signatureConfig);
String signature = signatureService.signature(signatureContext);
String signature = signatureService.signatureContent(signatureContext);
// 优化
if (SignatureEnumGroup.SignatureLocation.header.equals(signatureConfig.getSignatureLocation())) {
requestParams.getHeaders().put(signatureConfig.getSignatureField(), signature);
} else if (SignatureEnumGroup.SignatureLocation.body.equals(signatureConfig.getSignatureLocation())) {
requestParams.getBody().put(signatureConfig.getSignatureField(), signature);
} else if (SignatureEnumGroup.SignatureLocation.url.equals(signatureConfig.getSignatureLocation())) {
String url = requestParams.getUrl();
String separator = "";


+ 73
- 0
source/src/main/java/tech/deepq/source/util/TokenUtils.java Ver ficheiro

@@ -0,0 +1,73 @@
package tech.deepq.source.util;

import com.alibaba.fastjson2.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import tech.deepq.common.dto.HttpRequestParams;
import tech.deepq.common.dto.HttpRes;
import tech.deepq.source.request.RequestClient;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
* @author yechuan
* @since 2023/9/1 09:58
**/
@Component
public class TokenUtils {

@Autowired
private RequestClient requestClient;

@Autowired
private RedisTemplate<String, String> redisTemplate;

@Lazy
@Autowired
private TokenUtils proxy;

private final String TokenFormQHRBCacheKey = "tokenFormQHRBCacheKey";

public String getTokenFormQHRB(String partnerId, String partnerNtr) {
proxy.checkTokenFormQHRB(partnerId, partnerNtr);
return redisTemplate.opsForValue()
.get(TokenFormQHRBCacheKey);
}

@Async
public void checkTokenFormQHRB(String partnerId, String partnerNtr) {
Long expire = redisTemplate.getExpire(TokenFormQHRBCacheKey, TimeUnit.MINUTES);
if (expire == null) {
expire = Long.MIN_VALUE;
}
if (expire.compareTo(15L) > 0) {
return;
}
Map<String, Object> body = new HashMap<>();
String randomNum = UUID.randomUUID().toString().replaceAll("-", "");
randomNum = randomNum.substring(randomNum.length() - 8);
body.put("partnerId", partnerId);
body.put("randomNum", randomNum);
body.put("partnerNtr", DigestUtils.md5DigestAsHex((partnerNtr + randomNum).getBytes(StandardCharsets.UTF_8)));
HttpRequestParams httpRequestParams = new HttpRequestParams();
httpRequestParams.setUrl("https://app.qhrb.com.cn/api/user/partner/getTicket");
httpRequestParams.setBody(body);
httpRequestParams.setMethod("POST");

HttpRes res = requestClient.execute(httpRequestParams);
if (!res.getStatus().is2xxSuccessful()) {
return;
}
redisTemplate.opsForValue().set(TokenFormQHRBCacheKey, JSON.parseObject(res.getBody()).getString("dataPoints"), 120, TimeUnit.MINUTES);
}


}

Carregando…
Cancelar
Guardar