微调
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
package com.njcn.msgpush.module.push.util;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-02-28
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SmsApiUtil {
|
||||
|
||||
@Resource
|
||||
private RestTemplateUtil restTemplateUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 群发短信接口
|
||||
*
|
||||
* @param mobiles 手机号列表,多个手机号用逗号分隔
|
||||
* @param content 短信内容
|
||||
* @return 发送结果
|
||||
*/
|
||||
public ResponseEntity<String> sendBatchSms(String mobiles, String content) {
|
||||
return sendBatchSms(SmsConstant.SMS_ACCOUNT, SmsConstant.SMS_PASSWORD, mobiles, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发短信接口
|
||||
*
|
||||
* @param account 账号
|
||||
* @param password 密码
|
||||
* @param mobiles 手机号列表,多个手机号用逗号分隔
|
||||
* @param content 短信内容
|
||||
* @return 发送结果
|
||||
*/
|
||||
public ResponseEntity<String> sendBatchSms(String account, String password, String mobiles, String content) {
|
||||
try {
|
||||
String[] mobileArray = mobiles.split(",");
|
||||
log.info("开始群发短信,手机号数量: {}, 扩展号码: {}", mobileArray.length, SmsConstant.SMS_ACCESS_CODE);
|
||||
|
||||
// 构建请求参数
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("action", "send");
|
||||
request.put("account", account);
|
||||
request.put("password", password);
|
||||
request.put("mobile", mobiles);
|
||||
request.put("content", content);
|
||||
request.put("extno", SmsConstant.SMS_ACCESS_CODE);
|
||||
|
||||
// 设置请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", SmsConstant.SMS_CONTENT_TYPE);
|
||||
|
||||
// 发送请求
|
||||
ResponseEntity<String> response = restTemplateUtil.post(
|
||||
SmsConstant.SMS_API_URL,
|
||||
request,
|
||||
headers,
|
||||
String.class
|
||||
);
|
||||
|
||||
log.info("群发短信完成,响应状态: {}, 响应内容: {}",
|
||||
response.getStatusCode(), response.getBody());
|
||||
|
||||
return response;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("群发短信失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("群发短信失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 消息状态报告查询接口
|
||||
*
|
||||
* @param size 查询数量,建议不超过1000
|
||||
* @return 状态报告查询结果
|
||||
*/
|
||||
public ResponseEntity<String> messageReport(Integer size) {
|
||||
return messageReport(SmsConstant.SMS_ACCOUNT, SmsConstant.SMS_PASSWORD, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息状态报告查询接口
|
||||
*
|
||||
* @param account 账号
|
||||
* @param password 密码
|
||||
* @param size 查询数量,建议不超过1000
|
||||
* @return 状态报告查询结果
|
||||
*/
|
||||
public ResponseEntity<String> messageReport(String account, String password, Integer size) {
|
||||
try {
|
||||
log.info("开始查询消息状态报告,查询数量: {}", size);
|
||||
|
||||
// 构建请求参数
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("action", "report");
|
||||
request.put("account", account);
|
||||
request.put("password", password);
|
||||
request.put("size", size != null ? size : 1000);
|
||||
|
||||
// 设置请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", SmsConstant.SMS_CONTENT_TYPE);
|
||||
|
||||
// 发送请求
|
||||
ResponseEntity<String> response = restTemplateUtil.post(
|
||||
SmsConstant.SMS_API_URL,
|
||||
request,
|
||||
headers,
|
||||
String.class
|
||||
);
|
||||
|
||||
log.info("消息状态报告查询完成,响应状态: {}, 响应内容: {}",
|
||||
response.getStatusCode(), response.getBody());
|
||||
|
||||
return response;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("消息状态报告查询失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("消息状态报告查询失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package com.njcn.msgpush.module.push.util;
|
||||
|
||||
/**
|
||||
* 短信发送的一些常量,微服务添加在nacos中
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年08月24日 18:25
|
||||
*/
|
||||
public interface SmsConstant {
|
||||
|
||||
String DEFAULT_CONNECT_TIME_OUT = "sun.net.client.defaultConnectTimeout";
|
||||
String DEFAULT_READ_TIME_OUT = "sun.net.client.defaultReadTimeout";
|
||||
//短信API产品名称(短信产品名固定,无需修改)
|
||||
String PRODUCT = "Dysmsapi";
|
||||
//短信API产品域名(接口地址固定,无需修改)
|
||||
String DOMAIN = "dysmsapi.aliyuncs.com";
|
||||
//accessKeyId
|
||||
String ACCESS_KEY_ID = "LTAI4FxsR76x2dq3w9c5puUe";
|
||||
//accessKeySecret
|
||||
String ACCESS_KEY_SECRET = "GxkTR8fsrvHtixTlD9UPmOGli35tZs";
|
||||
//短信所属地
|
||||
String LOCATION = "cn-hangzhou";
|
||||
|
||||
/**
|
||||
* 通知签名
|
||||
*/
|
||||
String SGIN = "灿能云";
|
||||
|
||||
/**
|
||||
* 验证码签名
|
||||
*/
|
||||
String VERIFICATION_SIGNATURE = "南京灿能电力自动化股份";
|
||||
|
||||
/**
|
||||
* 短信接口地址
|
||||
*/
|
||||
String SMS_API_URL = "https://sms.ymeeting.cn/smsv2";
|
||||
|
||||
/**
|
||||
* 短信接口内容类型
|
||||
*/
|
||||
String SMS_CONTENT_TYPE = "application/json;charset=utf-8";
|
||||
|
||||
/**
|
||||
* 接口编码方式
|
||||
*/
|
||||
String SMS_CHARSET = "UTF-8";
|
||||
|
||||
/**
|
||||
* 短信接口账号
|
||||
*/
|
||||
String SMS_ACCOUNT = "925631";
|
||||
|
||||
/**
|
||||
* 短信接口密码
|
||||
*/
|
||||
String SMS_PASSWORD = "AMW2pOVrdky";
|
||||
|
||||
/**
|
||||
* 虚拟接入码
|
||||
*/
|
||||
String SMS_ACCESS_CODE = "106905631";
|
||||
}
|
||||
Reference in New Issue
Block a user