|
|
|
@ -40,6 +40,13 @@ import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.*; |
|
|
|
import java.util.concurrent.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -67,7 +74,7 @@ public class SmsSend { |
|
|
|
private RedisProcessService redisProcessService; |
|
|
|
private RedisProcessService redisProcessService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private RestTemplate restTemplate; |
|
|
|
private static RestTemplate restTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${sms.send.enabled}") |
|
|
|
@Value("${sms.send.enabled}") |
|
|
|
private String smsSendEnabled; //挡板
|
|
|
|
private String smsSendEnabled; //挡板
|
|
|
|
@ -171,10 +178,11 @@ public class SmsSend { |
|
|
|
mobileNums.setMobileNum(phoneList); |
|
|
|
mobileNums.setMobileNum(phoneList); |
|
|
|
message.setMobileNums(mobileNums); |
|
|
|
message.setMobileNums(mobileNums); |
|
|
|
message.setMessTopic(configVo.getTemplateName()); |
|
|
|
message.setMessTopic(configVo.getTemplateName()); |
|
|
|
String paramsStr = parms.entrySet().stream() |
|
|
|
// String paramsStr = parms.entrySet().stream()
|
|
|
|
.map(entry -> entry.getKey() + "=" + entry.getValue()) |
|
|
|
// .map(entry -> entry.getKey() + "=" + entry.getValue())
|
|
|
|
.collect(Collectors.joining(";")); |
|
|
|
// .collect(Collectors.joining(";"));
|
|
|
|
message.setSendData(paramsStr); |
|
|
|
// message.setSendData(paramsStr);
|
|
|
|
|
|
|
|
message.setSendData("测试短信"); |
|
|
|
message.setDataType(0); |
|
|
|
message.setDataType(0); |
|
|
|
message.setSendWay(0); |
|
|
|
message.setSendWay(0); |
|
|
|
message.setUnitCode(bo.getSystem()); |
|
|
|
message.setUnitCode(bo.getSystem()); |
|
|
|
@ -206,6 +214,7 @@ public class SmsSend { |
|
|
|
|
|
|
|
|
|
|
|
log.info("SmsSend-send,response={},是否成功={}",response,response.isSuccess()); |
|
|
|
log.info("SmsSend-send,response={},是否成功={}",response,response.isSuccess()); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
|
|
|
|
log.info("短信发送开关未开启-------------"); |
|
|
|
response.setSuccess(Boolean.TRUE); |
|
|
|
response.setSuccess(Boolean.TRUE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -289,6 +298,82 @@ public class SmsSend { |
|
|
|
smsReturn.setData(messageTotal); |
|
|
|
smsReturn.setData(messageTotal); |
|
|
|
return smsReturn; |
|
|
|
return smsReturn; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 示例代码仅供参考,实际使用需要通过依赖注入获取实例
|
|
|
|
|
|
|
|
SmsDto smsDto = new SmsDto(); |
|
|
|
|
|
|
|
PublicInfo publicInfo = new PublicInfo(); |
|
|
|
|
|
|
|
Message message = new Message(); |
|
|
|
|
|
|
|
smsDto.setPublicInfo(publicInfo); |
|
|
|
|
|
|
|
smsDto.setMessage(message); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
publicInfo.setServiceCode("**"); |
|
|
|
|
|
|
|
publicInfo.setSystemCode("**"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message.setMessageId(""); |
|
|
|
|
|
|
|
MobileNums mobileNums = new MobileNums(); |
|
|
|
|
|
|
|
List<String> phoneList = Arrays.asList("152323723"); |
|
|
|
|
|
|
|
mobileNums.setMobileNum(phoneList); |
|
|
|
|
|
|
|
message.setMobileNums(mobileNums); |
|
|
|
|
|
|
|
message.setMessTopic("短信主题"); |
|
|
|
|
|
|
|
message.setSendData("测试短信"); |
|
|
|
|
|
|
|
message.setDataType(0); |
|
|
|
|
|
|
|
message.setSendWay(0); |
|
|
|
|
|
|
|
message.setUnitCode("单位代码"); |
|
|
|
|
|
|
|
message.setDealOrder(0); |
|
|
|
|
|
|
|
message.setAnswerMatch(0); |
|
|
|
|
|
|
|
System.out.println(message); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpURLConnection connection = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// 1. 创建URL对象并打开连接
|
|
|
|
|
|
|
|
URL url = new URL("http://10.8.1.27:8080/sms/interface/SysSendMsg.jsp?userName=***&password=***"); |
|
|
|
|
|
|
|
connection = (HttpURLConnection) url.openConnection(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 配置连接
|
|
|
|
|
|
|
|
connection.setRequestMethod("POST"); |
|
|
|
|
|
|
|
connection.setDoOutput(true); // 允许写入请求体
|
|
|
|
|
|
|
|
connection.setDoInput(true); // 允许读取响应体
|
|
|
|
|
|
|
|
connection.setRequestProperty("Content-Type", "application/xml; charset=UTF-8"); |
|
|
|
|
|
|
|
connection.setRequestProperty("Accept", "application/xml"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("开始发送数据"); |
|
|
|
|
|
|
|
// 3. 发送XML数据
|
|
|
|
|
|
|
|
try (OutputStream outputStream = connection.getOutputStream(); |
|
|
|
|
|
|
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) { |
|
|
|
|
|
|
|
writer.write(String.valueOf(message)); |
|
|
|
|
|
|
|
writer.flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 获取响应
|
|
|
|
|
|
|
|
int responseCode = connection.getResponseCode(); |
|
|
|
|
|
|
|
System.out.println("响应状态码: " + responseCode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据状态码选择正确的输入流来读取响应
|
|
|
|
|
|
|
|
try (BufferedReader reader = new BufferedReader( |
|
|
|
|
|
|
|
new InputStreamReader( |
|
|
|
|
|
|
|
responseCode >= 400 ? connection.getErrorStream() : connection.getInputStream(), |
|
|
|
|
|
|
|
StandardCharsets.UTF_8))) { |
|
|
|
|
|
|
|
StringBuilder response = new StringBuilder(); |
|
|
|
|
|
|
|
String line; |
|
|
|
|
|
|
|
while ((line = reader.readLine()) != null) { |
|
|
|
|
|
|
|
response.append(line); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
System.out.println("响应内容: " + response.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
if (connection != null) { |
|
|
|
|
|
|
|
connection.disconnect(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Deprecated |
|
|
|
@Deprecated |
|
|
|
public SmsReturn send(String tempId, |
|
|
|
public SmsReturn send(String tempId, |
|
|
|
MsgTemplateConfigVo configVo, |
|
|
|
MsgTemplateConfigVo configVo, |
|
|
|
|