limeng před 2 roky
rodič
revize
d9b3c3c1b6
17 změnil soubory, kde provedl 1038 přidání a 4 odebrání
  1. 124 0
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/controller/HwMeetingController.java
  2. 29 0
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/HwMeetingService.java
  3. 46 0
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingApi.java
  4. 141 0
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingServiceImpl.java
  5. 53 0
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/HmacSHA256.java
  6. 96 0
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/hwMeetingCacheUtil.java
  7. 4 3
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/controller/WaterPressureController.java
  8. 0 1
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/WaterPressureService.java
  9. 18 0
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/mq/RocketMQConsumer.java
  10. 22 0
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/mq/RocketMQController.java
  11. 18 0
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/mq/RocketMQProducer.java
  12. 127 0
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/MailTools.java
  13. 32 0
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendMessageController.java
  14. 238 0
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendSms.java
  15. 68 0
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/domain/MessageContent.java
  16. 7 0
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/SendMessageService.java
  17. 15 0
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/impl/SendMessageServiceImpl.java

+ 124 - 0
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/controller/HwMeetingController.java

@@ -0,0 +1,124 @@
+package com.ruoyi.hwMeeting.controller;
+
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.dahuatech.hutool.json.JSONTokener;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.hwMeeting.util.hwMeetingCacheUtil;
+import com.ruoyi.hwMeeting.service.HwMeetingService;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 华为云会议控制器
+ */
+@Controller
+@RequestMapping("/hwMeeting")
+public class HwMeetingController {
+
+    private String prefix = "hwMeeting/meeting";
+
+    @Resource
+    private HwMeetingService hwMeetingService;
+
+    /**
+     * 创建或加入会议
+     */
+    @GetMapping("/joinConferences/{eventId}/{subject}/{nickName}")
+    @ResponseBody
+    public AjaxResult hasConferences(@PathVariable(name = "eventId") String eventId,
+                                     @PathVariable(name = "subject") String subject,
+                                     @PathVariable(name = "nickName") String nickName) {
+        Map<String,Object> map = new HashMap<>();
+        if (hwMeetingCacheUtil.has(eventId)) {
+            Object ob = hwMeetingCacheUtil.get(eventId);
+            //ob转换为JSONObject 取来宾入会信息返回
+            JSONObject object = JSONUtil.parseObj(ob);
+            //取密码数组 passwordEntry
+            JSONArray array = JSONUtil.parseArray(object.get("passwordEntry"));
+            for (Object o : array) {
+                JSONObject password = JSONUtil.parseObj(o);
+                JSONObject generalInfo = new JSONObject();
+                if (password.getStr("conferenceRole").equals("general")) {
+                    generalInfo.set("conferenceID", object.getStr("conferenceID"));
+                    generalInfo.set("password", password.getStr("password"));
+                    map.put("info",generalInfo);
+                }
+            }
+            map.put("nickName",nickName);
+            map.put("nonce",hwMeetingService.getNonce());
+            return AjaxResult.success(map);
+        }else{
+            this.createConferences(eventId,subject,map);
+            map.put("nickName",nickName);
+            map.put("nonce",hwMeetingService.getNonce());
+            return AjaxResult.success(map);
+        }
+    }
+
+    /**
+     * 创建会议
+     */
+    public boolean createConferences(String eventId,String subject,Map map) {
+        String result = hwMeetingService.conferences(subject);
+        if (isSuccess(result)) {
+            /**将会议信息保存到数据库**/
+            //将结果转换为json数组,当处理成功时返回的格式为数组
+            Object ob = JSONUtil.parseArray(result).get(0);
+            //会议信息存入缓存
+            hwMeetingCacheUtil.put(eventId,JSONUtil.parseObj(ob));
+            //ob转换为JSONObject 取主持人入会信息返回
+            JSONObject object = JSONUtil.parseObj(ob);
+            //取密码数组 passwordEntry
+            JSONArray array = JSONUtil.parseArray(object.get("passwordEntry"));
+            for (Object o : array) {
+                JSONObject password = JSONUtil.parseObj(o);
+                JSONObject chairInfo = new JSONObject();
+                if (password.getStr("conferenceRole").equals("chair")) {
+                    chairInfo.set("conferenceID", object.getStr("conferenceID"));
+                    chairInfo.set("password", password.getStr("password"));
+                    map.put("info",chairInfo);
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 获取加入会议URI
+     */
+    @ResponseBody
+    @GetMapping("/guestJoinUri/{eventId}")
+    public AjaxResult guestJoinUri(@PathVariable(name = "eventId") String eventId) {
+        Object ob = hwMeetingCacheUtil.get(eventId);
+        if(ob != null){
+            JSONObject object = JSONUtil.parseObj(ob);
+            return AjaxResult.success(object.get("guestJoinUri"));
+        }
+        return AjaxResult.error("未查询到数据");
+    }
+
+    /**
+     * 判断返回数据是JSONArray还是JSONObject,
+     * 如果是Array 则表示成功
+     * 反之失败
+     * */
+    private boolean isSuccess(String result) {
+        Object object = new JSONTokener(result).nextValue();
+        if (object instanceof JSONObject) {
+            JSONObject jsonObject = (JSONObject) object;
+            String error_code = jsonObject.get("error_code").toString();
+            System.err.println(error_code);
+            return false;
+        }
+        return true;
+    }
+
+}

+ 29 - 0
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/HwMeetingService.java

@@ -0,0 +1,29 @@
+package com.ruoyi.hwMeeting.service;
+
+public interface HwMeetingService {
+
+    /**
+     * appId鉴权方法 获取token
+     */
+    String appauth();
+
+    /**
+     * 获取页面免登陆跳转的nonce信息
+     */
+    String getNonce();
+
+    /**
+     * 构成Authorization
+     */
+    String getAuthorization(String appId, String userId, String nonce);
+
+    /**
+     * 绑定给当前创会帐号的VMR ID。通过查询云会议室及个人会议ID接口获取。
+     */
+    String vmrID(String token);
+
+    /**
+     * 创建会议
+     */
+    String conferences(String subject);
+}

+ 46 - 0
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingApi.java

@@ -0,0 +1,46 @@
+package com.ruoyi.hwMeeting.service.impl;
+
+import org.springframework.beans.factory.annotation.Value;
+
+/**
+ * 华为接口类
+ */
+public abstract class HwMeetingApi {
+
+    /**
+     * 请求地址
+     **/
+    public static final String url = "https://api.meeting.huaweicloud.com";
+
+    /**
+     * appId
+     **/
+    @Value("${HwM.appId}")
+    public static final String appId = "3f989ae3a9664bbd8e78dde9d29a5a22";
+
+    /**
+     * appKey 也是HmacSHA256加密秘钥
+     **/
+    @Value("${HwM.appKey}")
+    public static final String appKey = "a48cbf11d0172b1c9fd4e9017bd8cf4dca674aa3a40696bd59f2542e746552fa";
+
+    /**
+     * 第三方平台的userId
+     **/
+    public static final String userId = "1001";
+
+    /**
+     * 执行AppID鉴权
+     */
+    public static final String appauth = "/v2/usg/acs/auth/appauth";
+
+    /**
+     * 普通用户分页查询云会议室及个人会议ID
+     **/
+    public static final String vmr = "/v1/usg/dcs/member/vmr";
+
+    /**
+     * 创建会议
+     */
+    public static final String conferences = "/v1/mmc/management/conferences";
+}

+ 141 - 0
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingServiceImpl.java

@@ -0,0 +1,141 @@
+package com.ruoyi.hwMeeting.service.impl;
+
+import com.dahuatech.hutool.core.util.RandomUtil;
+import com.dahuatech.hutool.http.HttpRequest;
+import com.dahuatech.hutool.json.JSONArray;
+import com.dahuatech.hutool.json.JSONObject;
+import com.dahuatech.hutool.json.JSONUtil;
+import com.ruoyi.config.service.IMeetingConfigService;
+import com.ruoyi.hwMeeting.service.HwMeetingService;
+import com.ruoyi.hwMeeting.util.HmacSHA256;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class HwMeetingServiceImpl implements HwMeetingService {
+
+    private static final Logger log = LoggerFactory.getLogger(HwMeetingServiceImpl.class);
+
+    @Autowired
+    private IMeetingConfigService meetingConfigService;
+
+    /**
+     * appId鉴权方法 获取token
+     */
+    @Override
+    public String appauth() {
+        String appId = meetingConfigService.selectMeetingConfigById((long) 2).getVal();
+        String userId = meetingConfigService.selectMeetingConfigById((long) 4).getVal();
+        String url = meetingConfigService.selectMeetingConfigById((long) 1).getVal();
+        String appauth = meetingConfigService.selectMeetingConfigById((long) 5).getVal();
+        //64位随机字符串
+        String nonce = RandomUtil.randomString(64);
+        log.info("nonce:{}", nonce);
+        //鉴权信息
+        String authorization = getAuthorization(appId, userId, nonce);
+        log.info("authorization:{}", authorization);
+        //body
+        JSONObject json = new JSONObject();
+        json.put("appId", appId);
+        json.put("expireTime", 0);
+        json.put("nonce", nonce);
+        json.put("userId", userId);
+        json.put("clientType", 72);
+        //请求结果
+        String result = HttpRequest.post(url + appauth)
+                .header("Authorization", authorization)
+                .header("Content-Type", "application/json")
+                .body(json)
+                .execute().body();
+        //打印
+        log.info("result:{}", result);
+        return JSONUtil.parseObj(result).get("accessToken").toString();
+    }
+
+    /**
+     * 构成Authorization
+     */
+    @Override
+    public String getAuthorization(String appId, String userId, String nonce) {
+        String appKey = meetingConfigService.selectMeetingConfigById((long) 3).getVal();
+        String data = appId + ":" + userId + ":" + 0 + ":" + nonce;
+        String authorization = "HMAC-SHA256 signature=" + HmacSHA256.encode(data, appKey);
+        return authorization;
+    }
+
+    /**
+     * 绑定给当前创会帐号的VMR_ID。通过查询云会议室及个人会议ID接口获取。
+     */
+    @Override
+    public String vmrID(String token) {
+        String url = meetingConfigService.selectMeetingConfigById((long) 1).getVal();
+        String vmr = meetingConfigService.selectMeetingConfigById((long) 6).getVal();
+        //body
+        String result = HttpRequest.get(url + vmr)
+                .header("X-Access-Token", token)
+                .header("Content-Type", "application/json")
+                .execute().body();
+        log.info("vmr:{}", result);
+        JSONArray rooms = JSONUtil.parseArray(JSONUtil.parseObj(result).get("data"));
+        log.info("rooms.get(0):{}", rooms.get(0));
+        log.info("JSONUtil.parseObj(rooms.get(0)):{}", JSONUtil.parseObj(rooms.get(0)));
+        log.info("vmrID:{}", JSONUtil.parseObj(rooms.get(0)).get("vmrId"));
+        return JSONUtil.parseObj(rooms.get(0)).get("id").toString();
+    }
+
+    /**
+     * 创建会议
+     */
+    @Override
+    public String conferences(String subject) {
+        String token = appauth();
+        String vmrID = vmrID(token);
+        String url = meetingConfigService.selectMeetingConfigById((long) 1).getVal();
+        String conferences = meetingConfigService.selectMeetingConfigById((long) 7).getVal();
+        //body
+        JSONObject json = new JSONObject();
+        /**会议的媒体类型。Voice:语音会议,HDVideo:视频会议**/
+        json.put("mediaTypes", "HDVideo");
+        /**
+         * 会议持续时长,单位分钟。默认30分钟。
+         * 最大1440分钟(24小时),最小15分钟。
+         * */
+        json.put("length", 15);
+        /**会议主题。最多128个字符。**/
+        json.put("subject", subject);
+        /**
+         * 是否使用云会议室或者个人会议ID召开预约会议。默认0。
+         * 0:不使用云会议室或者个人会议ID
+         * 1:使用云会议室或者个人会议ID
+         * */
+        json.put("vmrFlag", 1);
+        /**绑定给当前创会帐号的VMR ID。通过查询云会议室及个人会议ID接口获取。**/
+        json.put("vmrID", vmrID);
+        //请求
+        String result = HttpRequest.post(url + conferences)
+                .header("X-Access-Token", token)
+                .header("Content-Type", "application/json")
+                .body(json)
+                .execute().body();
+        log.info("创建会议:{}", result);
+        return result;
+    }
+
+    /**
+     * 获取页面免登陆跳转的nonce信息
+     */
+    public String getNonce(){
+        String url = meetingConfigService.selectMeetingConfigById((long) 1).getVal();
+        String getNonce = meetingConfigService.selectMeetingConfigById((long) 8).getVal();
+        String result = HttpRequest.post(url + getNonce)
+                .header("X-Access-Token", appauth())
+                .header("Content-Type", "application/json")
+                .execute().body();
+        log.info("获取页面免登陆跳转的nonce信息:{}", result);
+        Object nonce = JSONUtil.parseObj(result).get("nonce");
+        return nonce !=null ? nonce.toString() : "";
+    }
+
+}

+ 53 - 0
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/HmacSHA256.java

@@ -0,0 +1,53 @@
+package com.ruoyi.hwMeeting.util;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+public class HmacSHA256 {
+
+    //十六进制字符集
+    private final static char[] DIGEST_ARRAYS = {
+            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+    };
+
+    /**
+     * 功能:Signature生成算法
+     * 输入参数:
+     *          1.data: HMAC-SHA256的输入数据
+     *          2.key: App Key
+     * 输出参数:十六进制字符串编码的HMAC-SHA256值
+     */
+    public static String encode(String data, String key) {
+        byte[] hashByte;
+        try {
+            Mac sha256HMAC = Mac.getInstance("HmacSHA256");
+            SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
+            sha256HMAC.init(secretKey);
+
+            hashByte = sha256HMAC.doFinal(data.getBytes("UTF-8"));
+        } catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) {
+            return null;
+        }
+
+        return bytesToHex(hashByte);
+    }
+
+    /**
+     * 功能:byte类型数组转换成十六进制字符串
+     * 输入参数:
+     *          1.bytes:被转换的字节数组
+     * 输出参数:十六进制字符串
+     */
+    private static String bytesToHex(byte[] bytes) {
+        StringBuffer hexStr = new StringBuffer();
+        for (int i = 0; i < bytes.length; i++) {
+            hexStr.append(DIGEST_ARRAYS[bytes[i] >>> 4 & 0X0F]);
+            hexStr.append(DIGEST_ARRAYS[bytes[i] & 0X0F]);
+        }
+
+        return hexStr.toString();
+    }
+}

+ 96 - 0
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/hwMeetingCacheUtil.java

@@ -0,0 +1,96 @@
+package com.ruoyi.hwMeeting.util;
+
+import com.ruoyi.common.utils.CacheUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
+import org.apache.shiro.cache.Cache;
+import org.apache.shiro.cache.CacheManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class hwMeetingCacheUtil {
+
+    private static Logger logger = LoggerFactory.getLogger(CacheUtils.class);
+
+    private static CacheManager cacheManager = SpringUtils.getBean(CacheManager.class);
+
+    private static final String CACHE = "hwMeetingCache";
+
+    /**
+     * 获取CACHE缓存
+     *
+     * @param key
+     * @return
+     */
+    public static Object get(String key)
+    {
+        return get(CACHE, key);
+    }
+
+    /**
+     * 获取缓存
+     *
+     * @param cacheName
+     * @param key
+     * @return
+     */
+    private static Object get(String cacheName, String key)
+    {
+        return getCache(cacheName).get(key);
+    }
+
+    /**
+     * 写入CACHE缓存
+     *
+     * @param key
+     * @return
+     */
+    public static void put(String key, Object value)
+    {
+        put(CACHE, key, value);
+    }
+
+
+    /**
+     * 写入缓存
+     *
+     * @param cacheName
+     * @param key
+     * @param value
+     */
+    private static void put(String cacheName, String key, Object value)
+    {
+        getCache(cacheName).put(key, value);
+    }
+
+    /**
+     * 判断是否有CACHE缓存
+     *
+     * @param key
+     * @return
+     */
+    public static boolean has(String key)
+    {
+        Object o = getCache(CACHE).get(key);
+        if(o == null){
+            return false;
+        }
+        return true;
+    }
+
+
+    /**
+     * 获得一个Cache,没有则显示日志。
+     *
+     * @param cacheName
+     * @return
+     */
+    private static Cache<String, Object> getCache(String cacheName)
+    {
+        Cache<String, Object> cache = cacheManager.getCache(cacheName);
+        if (cache == null)
+        {
+            throw new RuntimeException("当前系统中没有定义“" + cacheName + "”这个缓存。");
+        }
+        return cache;
+    }
+}

+ 4 - 3
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/controller/WaterPressureController.java

@@ -1,9 +1,10 @@
 package com.ruoyi.monitorInterface.chenganshengbang.controller;
 
-import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.monitorInterface.chenganshengbang.service.WaterPressureService;
-import com.ruoyi.monitorInterface.sennor.service.SennorService;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 

+ 0 - 1
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/WaterPressureService.java

@@ -1,6 +1,5 @@
 package com.ruoyi.monitorInterface.chenganshengbang.service;
 
-import org.springframework.web.bind.annotation.RequestBody;
 
 public interface WaterPressureService {
 

+ 18 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/mq/RocketMQConsumer.java

@@ -0,0 +1,18 @@
+package com.ruoyi.monitorInterface.mq;//package com.ruoyi.monitorInterface.mq;
+//
+//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
+//import org.apache.rocketmq.spring.core.RocketMQListener;
+//import org.springframework.stereotype.Component;
+//
+///**
+// * 泛型可选
+// */
+//@Component
+//@RocketMQMessageListener(consumerGroup = "group1", topic = "topic1")
+//public class RocketMQConsumer implements RocketMQListener<String> {
+//
+//    @Override
+//    public void onMessage(String message) {
+//        System.out.println("Received message : " + message);
+//    }
+//}

+ 22 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/mq/RocketMQController.java

@@ -0,0 +1,22 @@
+package com.ruoyi.monitorInterface.mq;//package com.ruoyi.monitorInterface.mq;
+//
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//
+//import javax.annotation.Resource;
+//
+//@RestController
+//@RequestMapping("/RocketMQ")
+//public class RocketMQController {
+//
+//    private final String topic = "topic1";
+//
+//    @Resource
+//    private RocketMQProducer producer;
+//
+//    @RequestMapping("/sendMessage")
+//    public String sendMessage(String message) {
+//        producer.sendMessage(topic, message);
+//        return "消息已发送";
+//    }
+//}

+ 18 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/mq/RocketMQProducer.java

@@ -0,0 +1,18 @@
+package com.ruoyi.monitorInterface.mq;//package com.ruoyi.monitorInterface.mq;
+//
+//import org.apache.rocketmq.spring.core.RocketMQTemplate;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Component;
+//
+//@Component
+//public class RocketMQProducer {
+//
+//    @Autowired
+//    private RocketMQTemplate rocketMQTemplate;
+//
+//    // 发送消息
+//    public void sendMessage(String topic, String msg) {
+//        rocketMQTemplate.convertAndSend(topic, msg);
+//    }
+//
+//}

+ 127 - 0
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/MailTools.java

@@ -0,0 +1,127 @@
+package com.ruoyi.sendSMS.controller;
+
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import java.util.Date;
+import java.util.Properties;
+
+public class MailTools {
+
+    // 发件人的 邮箱 和 密码(替换为自己的邮箱和密码)
+    // PS: 某些邮箱服务器为了增加邮箱本身密码的安全性,给 SMTP 客户端设置了独立密码(有的邮箱称为“授权码”),
+    //     对于开启了独立密码的邮箱, 这里的邮箱密码必需使用这个独立密码(授权码)。
+    public static String myEmailAccount = "sys5923812@163.com";
+    public static String myEmailPassword = "sys200888";
+
+    public static String fromuser = "二道应急局";
+
+    // 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
+    // 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
+    public static String myEmailSMTPHost = "smtp.163.com";
+
+//    // 收件人邮箱(替换为自己知道的有效邮箱)
+//    public static String receiveMailAccount = "sys5923812@126.com";
+
+    public static void main(String[] args) {
+        try {
+        String mail = "huapyluo@126.com";
+        String title = "隐患限期整改告知书";
+        String count = ("测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容");
+            sendMain(mail, title, count);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    public static void sendMain(String tomail, String title, String content) throws Exception {
+        // 1. 创建参数配置, 用于连接邮件服务器的参数配置
+        Properties props = new Properties();                    // 参数配置
+        props.setProperty("mail.transport.protocol", "smtp");   // 使用的协议(JavaMail规范要求)
+        props.setProperty("mail.smtp.host", myEmailSMTPHost);   // 发件人的邮箱的 SMTP 服务器地址
+        props.setProperty("mail.smtp.auth", "true");            // 需要请求认证
+
+        // PS: 某些邮箱服务器要求 SMTP 连接需要使用 SSL 安全认证 (为了提高安全性, 邮箱支持SSL连接, 也可以自己开启),
+        //     如果无法连接邮件服务器, 仔细查看控制台打印的 log, 如果有有类似 “连接失败, 要求 SSL 安全连接” 等错误,
+        //     打开下面 /* ... */ 之间的注释代码, 开启 SSL 安全连接。
+        /*
+        // SMTP 服务器的端口 (非 SSL 连接的端口一般默认为 25, 可以不添加, 如果开启了 SSL 连接,
+        //                  需要改为对应邮箱的 SMTP 服务器的端口, 具体可查看对应邮箱服务的帮助,
+        //                  QQ邮箱的SMTP(SLL)端口为465或587, 其他邮箱自行去查看)
+        final String smtpPort = "465";
+        props.setProperty("mail.smtp.port", smtpPort);
+        props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
+        props.setProperty("mail.smtp.socketFactory.fallback", "false");
+        props.setProperty("mail.smtp.socketFactory.port", smtpPort);
+        */
+
+        // 2. 根据配置创建会话对象, 用于和邮件服务器交互
+        Session session = Session.getDefaultInstance(props);
+        session.setDebug(true);                                 // 设置为debug模式, 可以查看详细的发送 log
+
+        // 3. 创建一封邮件
+        MimeMessage message = createMimeMessage(session, myEmailAccount, tomail, title, content);
+
+        // 4. 根据 Session 获取邮件传输对象
+        Transport transport = session.getTransport();
+
+        // 5. 使用 邮箱账号 和 密码 连接邮件服务器, 这里认证的邮箱必须与 message 中的发件人邮箱一致, 否则报错
+        //
+        //    PS_01: 成败的判断关键在此一句, 如果连接服务器失败, 都会在控制台输出相应失败原因的 log,
+        //           仔细查看失败原因, 有些邮箱服务器会返回错误码或查看错误类型的链接, 根据给出的错误
+        //           类型到对应邮件服务器的帮助网站上查看具体失败原因。
+        //
+        //    PS_02: 连接失败的原因通常为以下几点, 仔细检查代码:
+        //           (1) 邮箱没有开启 SMTP 服务;
+        //           (2) 邮箱密码错误, 例如某些邮箱开启了独立密码;
+        //           (3) 邮箱服务器要求必须要使用 SSL 安全连接;
+        //           (4) 请求过于频繁或其他原因, 被邮件服务器拒绝服务;
+        //           (5) 如果以上几点都确定无误, 到邮件服务器网站查找帮助。
+        //
+        //    PS_03: 仔细看log, 认真看log, 看懂log, 错误原因都在log已说明。
+        transport.connect(myEmailAccount, myEmailPassword);
+
+        // 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
+        transport.sendMessage(message, message.getAllRecipients());
+
+        // 7. 关闭连接
+        transport.close();
+    }
+
+    /**
+     * 创建一封只包含文本的简单邮件
+     *
+     * @param session     和服务器交互的会话
+     * @param sendMail    发件人邮箱
+     * @param receiveMail 收件人邮箱
+     * @return
+     * @throws Exception
+     */
+    public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String title, String content) throws Exception {
+        // 1. 创建一封邮件
+        MimeMessage message = new MimeMessage(session);
+
+        // 2. From: 发件人
+        message.setFrom(new InternetAddress(sendMail, fromuser, "UTF-8"));
+
+        // 3. To: 收件人(可以增加多个收件人、抄送、密送)
+        message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "XX用户", "UTF-8"));
+
+        // 4. Subject: 邮件主题
+        message.setSubject(title, "UTF-8");
+
+        // 5. Content: 邮件正文(可以使用html标签)
+        message.setContent(content, "text/html;charset=UTF-8");
+
+        // 6. 设置发件时间
+        message.setSentDate(new Date());
+
+        // 7. 保存设置
+        message.saveChanges();
+
+        return message;
+    }
+
+}

+ 32 - 0
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendMessageController.java

@@ -0,0 +1,32 @@
+package com.ruoyi.sendSMS.controller;
+
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.sendSMS.domain.MessageContent;
+import com.ruoyi.sendSMS.service.SendMessageService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@RestController
+@RequestMapping("/sendMessageController")
+public class SendMessageController {
+
+    @Resource
+    SendMessageService sendMessageService;
+
+    @PostMapping("/sendMessage")
+    public String sendMessage(@RequestBody MessageContent messageContent) {
+        return sendMessageService.sendMessage(messageContent.getPhone(), messageContent.getStr(), messageContent.getSMSsignature());
+    }
+
+    @PostMapping("/sendEmail")
+    public AjaxResult sendEmail(@RequestBody MessageContent messageContent) {
+        try {
+            MailTools.sendMain(messageContent.getMail(), messageContent.getTitle(), messageContent.getCount());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return AjaxResult.success("操作成功!");
+    }
+}

+ 238 - 0
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendSms.java

@@ -0,0 +1,238 @@
+package com.ruoyi.sendSMS.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import javax.net.ssl.*;
+import java.io.*;
+import java.net.URL;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+// If the JDK version is earlier than 1.8, use the third-party library to provide the Base64 class.
+public class SendSms {
+    /**
+     * 设置不验证主机
+     */
+    private static final HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
+        @Override
+        public boolean verify(String hostname, SSLSession session) {
+            return true;
+        }
+    };
+
+    public static void main(String[] args) throws Exception {
+        sendMessage("17612476018", "1231231321", "数字梨树");
+    }
+
+    public static Map<String, Object> buildRequestBody(String msisdn, String smsTemplateId,
+                                                       Map<String, String> paramValues, String accout, String passward, String SMSsignature) {
+        if (null == msisdn || null == smsTemplateId || null == accout || null == passward) {
+            System.out.println(
+                    "buildRequestBody(): mobiles, templateId or templateParas or account or password is null.");
+            return null;
+        }
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        List<MtSmsMessage> requestLists = new ArrayList<MtSmsMessage>();
+        MtSmsMessage mtSmsMessage = new MtSmsMessage();
+        List<String> mobiles = new ArrayList<String>();
+        mobiles.add(msisdn);
+        mtSmsMessage.setMobiles(mobiles);
+        mtSmsMessage.setTemplateId(smsTemplateId);
+        mtSmsMessage.setTemplateParas(paramValues);
+        mtSmsMessage.setSignature("【"+SMSsignature+"】");
+        requestLists.add(mtSmsMessage);
+        map.put("account", accout);
+        map.put("password", passward);
+        map.put("requestLists", requestLists);
+        return map;
+    }
+
+    public static class MtSmsMessage {
+        List<String> mobiles;
+        String templateId;
+        Map<String, String> templateParas;
+        String signature;
+        String messageId;
+        String extCode;
+        List<NamedPatameter> extendInfos;
+
+        public List<String> getMobiles() {
+            return mobiles;
+        }
+
+        public void setMobiles(List<String> mobiles) {
+            this.mobiles = mobiles;
+        }
+
+        public String getTemplateId() {
+            return templateId;
+        }
+
+        public void setTemplateId(String templateId) {
+            this.templateId = templateId;
+        }
+
+        public Map<String, String> getTemplateParas() {
+            return templateParas;
+        }
+
+        public void setTemplateParas(Map<String, String> templateParas) {
+            this.templateParas = templateParas;
+        }
+
+        public String getSignature() {
+            return signature;
+        }
+
+        public void setSignature(String signature) {
+            this.signature = signature;
+        }
+
+        public String getMessageId() {
+            return messageId;
+        }
+
+        public void setMessageId(String messageId) {
+            this.messageId = messageId;
+        }
+
+        public String getExtCode() {
+            return extCode;
+        }
+
+        public void setExtCode(String extCode) {
+            this.extCode = extCode;
+        }
+
+        public List<NamedPatameter> getExtendInfos() {
+            return extendInfos;
+        }
+
+        public void setExtendInfos(List<NamedPatameter> extendInfos) {
+            this.extendInfos = extendInfos;
+        }
+    }
+
+    public class NamedPatameter {
+        String key;
+        String value;
+
+        public String getKey() {
+            return key;
+        }
+
+        public void setKey(String key) {
+            this.key = key;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        public void setValue(String value) {
+            this.value = value;
+        }
+    }
+
+    static void trustAllHttpsCertificates() throws Exception {
+        TrustManager[] trustAllCerts = new TrustManager[]{
+                new X509TrustManager() {
+                    @Override
+                    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+                        return;
+                    }
+
+
+                    @Override
+                    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+                        return;
+                    }
+
+
+                    @Override
+                    public X509Certificate[] getAcceptedIssuers() {
+                        return null;
+                    }
+                }
+        };
+        SSLContext sc = SSLContext.getInstance("SSL");
+        sc.init(null, trustAllCerts, null);
+        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
+    }
+
+    public static String sendMessage(String phone, String message, String SMSsignature) {
+
+        String url = "https://139.9.32.119:18312/common/sms/sendTemplateMessage";
+
+        //【数字梨树】
+//        String smsTemplateId = "SMS_21010400002";
+        //【四平市林业局】
+        String smsTemplateId = "SMS_21030400002";
+        Map<String, String> templateParas = new HashMap<String, String>();
+        templateParas.put("dxnr", message);
+        String accout = "760395"; //实际账号
+        String passward = "Mds*e&sd2D"; //实际密码
+        // If the request body does not contain the signature name, set signature to null.
+        Map<String, Object> body = buildRequestBody(phone, smsTemplateId, templateParas, accout, passward,SMSsignature);
+        if (null == body || body.isEmpty()) {
+            System.out.println("body is null.");
+            return "body is null";
+        }
+        HttpsURLConnection connection = null;
+        InputStream is = null;
+        BufferedReader br = null;
+        try {
+            trustAllHttpsCertificates();
+            URL realUrl = new URL(url);
+            connection = (HttpsURLConnection) realUrl.openConnection();
+            connection.setHostnameVerifier(DO_NOT_VERIFY);
+            connection.setDoInput(true); // 设置可输入
+            connection.setDoOutput(true); // 设置该连接是可以输出的
+            connection.setRequestMethod("POST"); // 设置请求方式
+            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
+            // connection.connect();
+            ObjectMapper objectMapper = new ObjectMapper();
+            PrintWriter pw = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8"));
+            pw.write(objectMapper.writeValueAsString(body));
+            pw.flush();
+            pw.close();
+
+            br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
+            int status = connection.getResponseCode();
+            if (200 == status) { // 200
+                is = connection.getInputStream();
+            } else { // 400/401
+                is = connection.getErrorStream();
+            }
+            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+            String line = null;
+            StringBuilder result = new StringBuilder();
+            while ((line = br.readLine()) != null) { // 读取数据
+                result.append(line + "\n");
+            }
+            connection.disconnect();
+            System.out.println(result.toString());
+            return result.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (null != is) {
+                    is.close();
+                }
+                if (null != br) {
+                    br.close();
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+}

+ 68 - 0
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/domain/MessageContent.java

@@ -0,0 +1,68 @@
+package com.ruoyi.sendSMS.domain;
+
+/**
+ * @author pengyu
+ * @date 2023年05月02日 13:06
+ */
+
+public class MessageContent {
+
+    //短信发送需要字段
+    public  String phone;
+    public  String str;
+    public  String SMSsignature;
+
+
+    //邮箱发送需要字段
+    public  String mail;
+    public  String title;
+    public  String count;
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
+    public String getStr() {
+        return str;
+    }
+
+    public void setStr(String str) {
+        this.str = str;
+    }
+
+    public String getSMSsignature() {
+        return SMSsignature;
+    }
+
+    public void setSMSsignature(String SMSsignature) {
+        this.SMSsignature = SMSsignature;
+    }
+
+    public String getMail() {
+        return mail;
+    }
+
+    public void setMail(String mail) {
+        this.mail = mail;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getCount() {
+        return count;
+    }
+
+    public void setCount(String count) {
+        this.count = count;
+    }
+}

+ 7 - 0
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/SendMessageService.java

@@ -0,0 +1,7 @@
+package com.ruoyi.sendSMS.service;
+
+public interface SendMessageService {
+
+    public String sendMessage(String phone, String str, String SMSsignature);
+
+}

+ 15 - 0
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/impl/SendMessageServiceImpl.java

@@ -0,0 +1,15 @@
+package com.ruoyi.sendSMS.service.impl;
+
+import com.ruoyi.sendSMS.controller.SendSms;
+import com.ruoyi.sendSMS.service.SendMessageService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SendMessageServiceImpl implements SendMessageService {
+
+
+    public String sendMessage(String phone, String message, String SMSsignature) {
+
+        return  SendSms.sendMessage(phone, message,SMSsignature);
+    }
+}