| | |
| | | package com.ruoyi.auth.utils; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.Base64; |
| | | import java.util.List; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * 聚通达短信发送工具类 |
| | |
| | | * @author mitao |
| | | * @date 2024/6/17 |
| | | */ |
| | | @Slf4j |
| | | public class JuTongDaSMSUtil { |
| | | |
| | | private static final String UID = "201000"; |
| | |
| | | return errMess; |
| | | } |
| | | |
| | | public static void smsSendBatch(List<String> mobileList, String content, |
| | | String ext, String attime) { |
| | | log.info("发送短信:号码{},内容:{}", JSONObject.toJSONString(mobileList), content); |
| | | for (String mobile : mobileList) { |
| | | String errMess = ""; |
| | | StringBuffer sendData = new StringBuffer(""); |
| | | try { |
| | | sendData.append("uid=").append(UID); // 用户名 |
| | | String pwd = getMD5(PWD);// 原始密码做MD5加密,32位大写格式 |
| | | sendData.append("&password=").append(pwd); // 密码 |
| | | |
| | | sendData.append("&encode=").append("GBK"); // encode=GBK或者encode=utf8 |
| | | String contentBase64 = Base64.getEncoder() |
| | | .encodeToString(content.getBytes("gbk"));// 先用encode中定义的格式编码,再用base64加密内容 |
| | | sendData.append("&encodeType=base64"); // 固定 |
| | | sendData.append("&content=").append(contentBase64); // base64加密后的内容 |
| | | |
| | | sendData.append("&mobile=").append(mobile); // 手机号 |
| | | // sendData.append("&cid=").append("45955855252252555"); // 唯一标识,选填,如果不填系统自动生成作为当前批次的唯一标识 |
| | | if (!StringUtils.isNotBlank(ext)) { |
| | | sendData.append("&extNumber=").append(ext); // 扩展 |
| | | } |
| | | |
| | | if (!StringUtils.isNotBlank(attime)) { |
| | | sendData.append("&schtime=").append(attime); // 定时时间,选填,格式2008-06-09 12:00:00 |
| | | } |
| | | errMess = sendPost("https://sms3api.jvtd.cn/jtdsms/smsSend", |
| | | sendData.toString());// 普通短信 |
| | | // errMess =sendPost("http://ip:8090/jtdsms/sendData.do", sendData.toString());//个性短信 |
| | | } catch (Exception e) { |
| | | log.error("发送短信异常:", e); |
| | | errMess = "-601"; |
| | | } |
| | | } |
| | | } |
| | | public static String sendPost(String url, String param) { |
| | | PrintWriter out = null; |
| | | BufferedReader in = null; |