Browse Source

修改信件导入细节,添加内网sms工具类

dev_ycq
21819 2 years ago
parent
commit
0dbfd21b19
  1. 6
      mailbox-lan/src/main/java/com/biutag/lan/controller/work/WorkController.java
  2. 1
      mailbox-lan/src/main/java/com/biutag/lan/service/MailSourceService.java
  3. 2
      mailbox-lan/src/main/java/com/biutag/lan/service/WorkService.java
  4. 182
      mailbox-lan/src/main/java/com/biutag/lan/util/SmsLan.java

6
mailbox-lan/src/main/java/com/biutag/lan/controller/work/WorkController.java

@ -11,7 +11,6 @@ import com.biutag.lan.service.MailSourceService;
import com.biutag.lan.service.WorkService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -46,12 +45,9 @@ public class WorkController {
@NotPower
@PostMapping("import")
@Transactional(rollbackFor = Exception.class)
public AjaxResult<Void> importExcel(@RequestBody String workVoList) {
List<WorkVo> data = JSON.parseArray(workVoList, WorkVo.class);
workService.saveExcelBatch(data);
mailSourceService.saveExcelBatch(data);
return AjaxResult.success();
return workService.saveExcelBatch(data) && mailSourceService.saveExcelBatch(data) ? AjaxResult.success() : AjaxResult.failed("导入失败");
}
@NotPower

1
mailbox-lan/src/main/java/com/biutag/lan/service/MailSourceService.java

@ -43,6 +43,7 @@ public class MailSourceService extends ServiceImpl<MailSourceMapper, MailSource>
return count(queryWrapper);
}
@Transactional(rollbackFor = Exception.class)
public boolean saveExcelBatch(List<WorkVo> mailSources) {
LocalDateTime now = LocalDateTime.now();
List<MailSource> list = mailSources.stream().map(mail -> {

2
mailbox-lan/src/main/java/com/biutag/lan/service/WorkService.java

@ -24,6 +24,7 @@ import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@ -61,6 +62,7 @@ public class WorkService extends ServiceImpl<WorkMapper, Work> {
return saveBatch(list);
}
@Transactional(rollbackFor = Exception.class)
public boolean saveExcelBatch(List<WorkVo> mailSources) {
LocalDateTime now = LocalDateTime.now();
List<Work> list = mailSources.stream().map(mail -> {

182
mailbox-lan/src/main/java/com/biutag/lan/util/SmsLan.java

@ -0,0 +1,182 @@
package com.biutag.lan.util;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
/**
* 内网信息平台工具类未测试
*/
@Slf4j
public class SmsLan {
private static final String BASE_URL = "http://10.143.55.119:8989/kezansms/SendSms";
private static final String USERNAME = "fzzd";
private static final String PASSWORD = "fzzd12345678dxpt";
private SmsLan() {
}
/**
* @param mobiles 手机号 多个用","隔开 英文逗号必填
* @param content 短信内容 必填
* @param orderNo 批次号 必填
* @param appendID 扩展字号 非必填
* @param sendTime 拟发送时间 非必填
* @param validTime 拟发送最后时间超过不发送 非必填
* @return
*/
public static String send(String mobiles, String content, String orderNo, String appendID, String sendTime, String validTime) {
try {
Map<String, Object> dataMap = new HashMap<>();
long timeStamp = System.currentTimeMillis() / 1000;
dataMap.put("timeStamp", timeStamp);
log.info("timeStamp: {}", timeStamp);
dataMap.put("mobiles", mobiles);
dataMap.put("content", content);
dataMap.put("orderNo", orderNo);
dataMap.put("appendID", appendID);
dataMap.put("sendTime", sendTime);
dataMap.put("validTime", validTime);
String jsonStr = JSON.toJSONString(dataMap);
log.info("jsonStr: {}", jsonStr);
String key = encrypt(jsonStr, PASSWORD, true);
log.info("key: {}", key);
key = URLEncoder.encode(key, "UTF-8");
log.info("key: {}", key);
String response = httpUtilPost(BASE_URL, "userid=" + USERNAME + "&key=" + key);
log.info(response);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* @param mobiles 手机号 多个用","隔开 英文逗号必填
* @param content 短信内容 必填
* @param orderNo 批次号 必填
* @param validTime 拟发送最后时间超过不发送 非必填
* @return
*/
public static String send(String mobiles, String content, String orderNo, String validTime) {
try {
Map<String, Object> dataMap = new HashMap<>();
long timeStamp = System.currentTimeMillis() / 1000;
dataMap.put("timeStamp", timeStamp);
log.info("timeStamp: {}", timeStamp);
dataMap.put("mobiles", mobiles);
dataMap.put("content", content);
dataMap.put("orderNo", orderNo);
dataMap.put("validTime", validTime);
String jsonStr = JSON.toJSONString(dataMap);
log.info("jsonStr: {}", jsonStr);
String key = encrypt(jsonStr, PASSWORD, true);
log.info("key: {}", key);
key = URLEncoder.encode(key, "UTF-8");
log.info("key: {}", key);
String response = httpUtilPost(BASE_URL, "userid=" + USERNAME + "&key=" + key);
log.info(response);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* @param mobiles 手机号 多个用","隔开 英文逗号必填
* @param content 短信内容 必填
* @param orderNo 批次号 必填
* @return
*/
public static String send(String mobiles, String content, String orderNo) {
try {
Map<String, Object> dataMap = new HashMap<>();
long timeStamp = System.currentTimeMillis() / 1000;
dataMap.put("timeStamp", timeStamp);
log.info("timeStamp: {}", timeStamp);
dataMap.put("mobiles", mobiles);
dataMap.put("content", content);
dataMap.put("orderNo", orderNo);
String jsonStr = JSON.toJSONString(dataMap);
log.info("jsonStr: {}", jsonStr);
String key = encrypt(jsonStr, PASSWORD, true);
log.info("key: {}", key);
key = URLEncoder.encode(key, "UTF-8");
log.info("key: {}", key);
String response = httpUtilPost(BASE_URL, "userid=" + USERNAME + "&key=" + key);
log.info(response);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* POST 请求
*
* @param urls
* @param params
* @return
*/
public static String httpUtilPost(String urls, String params) {
URL url;
HttpURLConnection uConn = null;
String result = "";
try {
url = new URL(urls);
uConn = (HttpURLConnection) url.openConnection();
uConn.setRequestMethod("POST");
uConn.setDoInput(true);
uConn.setDoOutput(true);
uConn.connect();
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(uConn.getOutputStream(), "utf-8"));
BufferedReader in = new BufferedReader(new InputStreamReader(uConn.getInputStream(), "utf-8"))) {
out.write(params);
out.flush();
StringBuilder resultBuilder = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
if (line.length() > 0)
resultBuilder.append(line);
}
result = resultBuilder.toString();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (uConn != null) {
uConn.disconnect();
}
}
return result;
}
public static String encrypt(String input, String key, Boolean bs64) throws Exception {
SecretKeySpec skey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skey);
byte[] crypted = cipher.doFinal(input.getBytes(StandardCharsets.UTF_8));
if (bs64) {
return Base64.getEncoder().encodeToString(crypted);
} else {
throw new UnsupportedOperationException("Non-base64 is not supported.");
}
}
}
Loading…
Cancel
Save