|
|
@ -2,13 +2,17 @@ package me.zhengjie.modules.uploadnew.task;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
|
import cn.hutool.extra.ssh.JschUtil;
|
|
|
|
import cn.hutool.extra.ssh.JschUtil;
|
|
|
|
import cn.hutool.extra.ssh.Sftp;
|
|
|
|
import cn.hutool.extra.ssh.Sftp;
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
@ -16,12 +20,16 @@ import com.google.common.collect.Sets;
|
|
|
|
import com.jcraft.jsch.Session;
|
|
|
|
import com.jcraft.jsch.Session;
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import me.zhengjie.constant.SmsConstant;
|
|
|
|
import me.zhengjie.exception.BadRequestException;
|
|
|
|
import me.zhengjie.exception.BadRequestException;
|
|
|
|
import me.zhengjie.modules.constant.DefaultConstant;
|
|
|
|
import me.zhengjie.modules.constant.DefaultConstant;
|
|
|
|
import me.zhengjie.modules.constant.FileConstant;
|
|
|
|
import me.zhengjie.modules.constant.FileConstant;
|
|
|
|
|
|
|
|
import me.zhengjie.modules.system.domain.sms.dto.ShortLinkUrlDto;
|
|
|
|
import me.zhengjie.modules.upload.task.model.ResponseEncryptJsonContent;
|
|
|
|
import me.zhengjie.modules.upload.task.model.ResponseEncryptJsonContent;
|
|
|
|
import me.zhengjie.modules.upload.task.model.SendEncryptJsonContent;
|
|
|
|
import me.zhengjie.modules.upload.task.model.SendEncryptJsonContent;
|
|
|
|
import me.zhengjie.modules.upload.task.model.SendRemoteUpdateJsonContent;
|
|
|
|
import me.zhengjie.modules.upload.task.model.SendRemoteUpdateJsonContent;
|
|
|
|
|
|
|
|
import me.zhengjie.modules.uploadnew.consts.DecryptionDTO;
|
|
|
|
|
|
|
|
import me.zhengjie.modules.uploadnew.consts.DecryptionJsonContent;
|
|
|
|
import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew;
|
|
|
|
import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew;
|
|
|
|
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService;
|
|
|
|
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService;
|
|
|
|
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto;
|
|
|
|
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto;
|
|
|
@ -46,10 +54,7 @@ import java.nio.file.Paths;
|
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static me.zhengjie.modules.upload.consts.SysConst.*;
|
|
|
|
import static me.zhengjie.modules.upload.consts.SysConst.*;
|
|
|
@ -75,21 +80,30 @@ public class SaveToFileNewTask {
|
|
|
|
@Value(value = "${inter.address}")
|
|
|
|
@Value(value = "${inter.address}")
|
|
|
|
private String encryptAddress;
|
|
|
|
private String encryptAddress;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value(value = "${inter.decryptAddress}")
|
|
|
|
|
|
|
|
private String decryptAddress;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 分割标识 - 逗号
|
|
|
|
* 分割标识 - 逗号
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static final String SPLIT_TAG = ",";
|
|
|
|
private static final String SPLIT_TAG = ",";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 请求地址
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static final int TEN_NUM = 10;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 调用加密接口的加密内容数量限制
|
|
|
|
* 调用加密接口的加密内容数量限制
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private final static int SEND_ENCRYPT_LIMIT = 200;
|
|
|
|
private static final int SEND_ENCRYPT_LIMIT = 200;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 时间格式
|
|
|
|
* 时间格式
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private final static String FORMATE_TIMESTAMP = "yyyyMMddHHmmss";
|
|
|
|
private static final String FORMATE_TIMESTAMP = "yyyyMMddHHmmss";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 号码长度
|
|
|
|
* 号码长度
|
|
|
@ -154,17 +168,29 @@ public class SaveToFileNewTask {
|
|
|
|
List<String> phoneList = Lists.newArrayList();
|
|
|
|
List<String> phoneList = Lists.newArrayList();
|
|
|
|
String fileFormat = tbUploadFileNewDto.getFileFormat();
|
|
|
|
String fileFormat = tbUploadFileNewDto.getFileFormat();
|
|
|
|
//根据文件类型进行解析
|
|
|
|
//根据文件类型进行解析
|
|
|
|
List<String> listT = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME) ?
|
|
|
|
List<String> listT = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME)
|
|
|
|
TxtUtils.txtParseListVyUrl(filePath) : fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME)
|
|
|
|
? TxtUtils.txtParseListVyUrl(filePath) :
|
|
|
|
? ToolExcelUtils.csvParseListByUrl(filePath) : ToolExcelUtils.excelParseListByUrl(filePath);
|
|
|
|
fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME)
|
|
|
|
|
|
|
|
? ToolExcelUtils.csvParseListByUrl(filePath)
|
|
|
|
|
|
|
|
: ToolExcelUtils.excelParseListByUrl(filePath);
|
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, List<String>> preEncryptNumMap = listT.stream().filter
|
|
|
|
Map<Integer, List<String>> preEncryptNumMap = listT.stream().filter
|
|
|
|
(phone -> phone.trim().getBytes(StandardCharsets.UTF_8).length == DefaultConstant.ELEVEN_NUMBER)
|
|
|
|
(phone -> StringUtils.isNotBlank(phone.trim())).collect(Collectors.groupingBy(String::length));
|
|
|
|
.collect(Collectors.groupingBy(String::length));
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(preEncryptNumMap)) {
|
|
|
|
if (CollectionUtil.isNotEmpty(preEncryptNumMap)) {
|
|
|
|
// 分批调用接口进行加密
|
|
|
|
// 分批调用接口进行加密
|
|
|
|
List<String> list = preEncryptNumMap.get(PRE_SEND_NUM_LENGTH);
|
|
|
|
|
|
|
|
phoneList = Lists.newArrayList(Sets.newHashSet(list));
|
|
|
|
if (tbUploadFileNewDto.getEncryptionType() == DefaultConstant.TWO_NUMBER) {
|
|
|
|
|
|
|
|
List<String> decryptionList = preEncryptNumMap.get(2 << 4);
|
|
|
|
|
|
|
|
List<String> stringList = decryptFile(decryptionList);
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(stringList)) {
|
|
|
|
|
|
|
|
// 替换集合
|
|
|
|
|
|
|
|
phoneList = stringList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbUploadFileNewDto.getEncryptionType() == DefaultConstant.ONE_NUMBER) {
|
|
|
|
|
|
|
|
List<String> list = preEncryptNumMap.get(PRE_SEND_NUM_LENGTH);
|
|
|
|
|
|
|
|
phoneList = Lists.newArrayList(Sets.newHashSet(list));
|
|
|
|
|
|
|
|
}
|
|
|
|
if (CollectionUtil.isNotEmpty(phoneList)) {
|
|
|
|
if (CollectionUtil.isNotEmpty(phoneList)) {
|
|
|
|
batchSendToEncrypt(filePath, phoneList);
|
|
|
|
batchSendToEncrypt(filePath, phoneList);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -195,65 +221,89 @@ public class SaveToFileNewTask {
|
|
|
|
return DefaultConstant.ZERO_NUMBER;
|
|
|
|
return DefaultConstant.ZERO_NUMBER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> decryptFile(List<String> phoneList) {
|
|
|
|
|
|
|
|
List<String> stringList = Lists.newArrayList();
|
|
|
|
|
|
|
|
List<List<String>> partition = Lists.partition(phoneList, SEND_ENCRYPT_LIMIT);
|
|
|
|
|
|
|
|
for (List<String> list : partition) {
|
|
|
|
|
|
|
|
// 转换
|
|
|
|
|
|
|
|
String decryptStr = StringUtils.listPrintWithSpecialSplit(list, null);
|
|
|
|
|
|
|
|
// 构造请求
|
|
|
|
|
|
|
|
DecryptionJsonContent build =
|
|
|
|
|
|
|
|
DecryptionJsonContent.builder().cellphoneMd5
|
|
|
|
|
|
|
|
(decryptStr).requestId(RandomUtil.randomString(TEN_NUM)).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用HTTP请求发送数据
|
|
|
|
|
|
|
|
DecryptionDTO decryptionDTO = JSONUtil.toBean(HttpUtil.post(decryptAddress, JSON.toJSONString(build)), DecryptionDTO.class);
|
|
|
|
|
|
|
|
log.info("================ response as {} ================", JSONUtil.toJsonStr(decryptionDTO));
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(decryptionDTO.getReason())
|
|
|
|
|
|
|
|
&& "success".equals(decryptionDTO.getReason())) {
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(decryptionDTO.getCellPhone())) {
|
|
|
|
|
|
|
|
String[] split = decryptionDTO.getCellPhone().split(StrUtil.COMMA);
|
|
|
|
|
|
|
|
if (split.length > 0) {
|
|
|
|
|
|
|
|
stringList.addAll(Lists.newArrayList(Arrays.asList(split)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("================ send decryption info result size as {} ================", stringList.size());
|
|
|
|
|
|
|
|
return stringList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void batchSendToEncrypt(String filePath, List<String> fileAllLinesList) {
|
|
|
|
private void batchSendToEncrypt(String filePath, List<String> fileAllLinesList) {
|
|
|
|
List<List<String>> partition = Lists.partition(fileAllLinesList, SEND_ENCRYPT_LIMIT);
|
|
|
|
List<List<String>> partition = Lists.partition(fileAllLinesList, SEND_ENCRYPT_LIMIT);
|
|
|
|
|
|
|
|
|
|
|
|
partition.forEach(
|
|
|
|
partition.forEach(list -> {
|
|
|
|
list -> {
|
|
|
|
// 装配需要的Json参数
|
|
|
|
// 装配需要的Json参数
|
|
|
|
SendEncryptJsonContent sendEncryptJsonContent = new SendEncryptJsonContent();
|
|
|
|
SendEncryptJsonContent sendEncryptJsonContent = new SendEncryptJsonContent();
|
|
|
|
//fixme 还有一个过期时间参数为选填参数,暂时不做设置
|
|
|
|
//fixme 还有一个过期时间参数为选填参数,暂时不做设置
|
|
|
|
String tels = StringUtils.listPrintWithSpecialSplit(list, null);
|
|
|
|
String tels = StringUtils.listPrintWithSpecialSplit(list, null);
|
|
|
|
sendEncryptJsonContent.setTels(Base64.encode(tels));
|
|
|
|
sendEncryptJsonContent.setTels(Base64.encode(tels));
|
|
|
|
sendEncryptJsonContent.setReqId(RandomUtil.randomString(10));
|
|
|
|
sendEncryptJsonContent.setReqId(RandomUtil.randomString(10));
|
|
|
|
sendEncryptJsonContent.setAppId(encryptAppId);
|
|
|
|
sendEncryptJsonContent.setAppId(encryptAppId);
|
|
|
|
// 配置 sign
|
|
|
|
// 配置 sign
|
|
|
|
String signStr = makeSign();
|
|
|
|
String signStr = makeSign();
|
|
|
|
if (StringUtils.isBlank(signStr)) {
|
|
|
|
if (StringUtils.isBlank(signStr)) {
|
|
|
|
log.error("SaveToFileTask|makeSign fail!");
|
|
|
|
log.error("SaveToFileTask|makeSign fail!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendEncryptJsonContent.setSig(signStr);
|
|
|
|
sendEncryptJsonContent.setSig(signStr);
|
|
|
|
// 组装成JSON
|
|
|
|
// 组装成JSON
|
|
|
|
String readSendJsonStr = JSON.toJSONString(sendEncryptJsonContent);
|
|
|
|
String readSendJsonStr = JSON.toJSONString(sendEncryptJsonContent);
|
|
|
|
log.info("SaveToFileTask|batchSendToEncrypt ready send json is : {}", readSendJsonStr);
|
|
|
|
log.info("SaveToFileTask|batchSendToEncrypt ready send json is : {}", readSendJsonStr);
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
while (count < 3) {
|
|
|
|
while (count < 3) {
|
|
|
|
// 调用HTTP请求发送数据
|
|
|
|
// 调用HTTP请求发送数据
|
|
|
|
HttpResponse httpResponse = sendPostReq(readSendJsonStr);
|
|
|
|
HttpResponse httpResponse = sendPostReq(readSendJsonStr);
|
|
|
|
if (httpResponse.isOk() && httpResponse.body().contains("success")) {
|
|
|
|
if (httpResponse.isOk() && httpResponse.body().contains("success")) {
|
|
|
|
log.info("========== [SaveToFileTask|batchSendToEncrypt request success, response is {} ] ==========", httpResponse.body());
|
|
|
|
log.info("========== [SaveToFileTask|batchSendToEncrypt request success, response is {} ] ==========", httpResponse.body());
|
|
|
|
String responseStr = httpResponse.body();
|
|
|
|
String responseStr = httpResponse.body();
|
|
|
|
// 解析返回的结果,并写回本地
|
|
|
|
// 解析返回的结果,并写回本地
|
|
|
|
if (!parseResponseStr(filePath, responseStr)) {
|
|
|
|
if (!parseResponseStr(filePath, responseStr)) {
|
|
|
|
log.error("========== [ SaveToFileTask|batchSendToEncrpt parse fail ] ==========");
|
|
|
|
log.error("========== [ SaveToFileTask|batchSendToEncrpt parse fail ] ==========");
|
|
|
|
booleanTag = false;
|
|
|
|
booleanTag = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 重新发送前休眠3秒
|
|
|
|
|
|
|
|
Thread.sleep(3_0000);
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
log.error("SaveToFileTask|batchSendToEncrypt sleep ERROR. message is", e.getMessage(), e);
|
|
|
|
|
|
|
|
throw new BadRequestException("请求异常!!!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.error("========== [SaveToFileTask|batchSendToEncrypt request fail, response is {} ] ==========", httpResponse.body());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count >= 3) {
|
|
|
|
break;
|
|
|
|
log.error("========== [SaveToFileTask|batchSendToEncrypt update send status fail, url is {} ] ==========", encryptAddress);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 重新发送前休眠3秒
|
|
|
|
|
|
|
|
Thread.sleep(3_0000);
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
log.error("SaveToFileTask|batchSendToEncrypt sleep ERROR. message is", e.getMessage(), e);
|
|
|
|
|
|
|
|
throw new BadRequestException("请求异常!!!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.error("========== [SaveToFileTask|batchSendToEncrypt request fail, response is {} ] ==========", httpResponse.body());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count >= 3) {
|
|
|
|
|
|
|
|
log.error("========== [SaveToFileTask|batchSendToEncrypt update send status fail, url is {} ] ==========", encryptAddress);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String makeSign() {
|
|
|
|
private String makeSign() {
|
|
|
|
|
|
|
|
|
|
|
|
String signBuilder = encryptAppId +
|
|
|
|
String signBuilder = encryptAppId + encryptTK + DateUtil.localDateTimeFormat(LocalDateTime.now(), FORMATE_TIMESTAMP);
|
|
|
|
encryptTK +
|
|
|
|
|
|
|
|
DateUtil.localDateTimeFormat(LocalDateTime.now(), FORMATE_TIMESTAMP);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SecureUtil.md5(signBuilder).toUpperCase();
|
|
|
|
return SecureUtil.md5(signBuilder).toUpperCase();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -266,11 +316,7 @@ public class SaveToFileNewTask {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private HttpResponse sendPostReq(String json) {
|
|
|
|
private HttpResponse sendPostReq(String json) {
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse httpResponse = HttpRequest
|
|
|
|
HttpResponse httpResponse = HttpRequest.post(encryptAddress).header("Content-Type", "application/json;charset=utf-8").body(json).execute();
|
|
|
|
.post(encryptAddress)
|
|
|
|
|
|
|
|
.header("Content-Type", "application/json;charset=utf-8")
|
|
|
|
|
|
|
|
.body(json)
|
|
|
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return httpResponse;
|
|
|
|
return httpResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|