Skip to content

Commit 8a395e5

Browse files
author
羊文武
committed
接收端完成
1 parent a8441ac commit 8a395e5

File tree

5 files changed

+155
-8
lines changed

5 files changed

+155
-8
lines changed

ydl-sms-api/src/main/java/com/ydl/sms/service/impl/SmsSendServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private void checkoutSendTime(String sendTime) {
168168
LocalDateTime localDateTime =
169169
LocalDateTime.parse(sendTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
170170
LocalDateTime nowDateTime = LocalDateTime.now().plusMinutes(1L).withSecond(0).minusSeconds(0).withNano(0);
171-
if (localDateTime.compareTo(nowDateTime) <= 0) {
171+
if (localDateTime.compareTo(nowDateTime) >= 0) {
172172
throw new SmsException("发送时间过于接近当前时间,无法发送");
173173
}
174174
}

ydl-sms-entity/src/main/resources/mapper/ReceiveLogMapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
left join signature s on rl.signature = s.code
3131
left join template t on rl.template = t.code
3232
<where>
33-
rl.is_delete = 1 and sl.is_delete = 1 and s.is_delete = 1 and t.is_delete = 1
33+
rl.is_delete = 1
3434
<if test="params.signatureName != null">
3535
AND s.name LIKE concat('%',#{params.signatureName},'%')
3636
</if>

ydl-sms-entity/src/main/resources/mapper/SendLogMapper.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
left join signature s on sl.signature = s.code
3131
left join template t on sl.template = t.code
3232
<where>
33-
sl.is_delete = 1 and s.is_delete = 1 and t.is_delete = 1 and rl.is_delete = 1
33+
sl.is_delete = 1
3434
<if test="params.mobile != null">
3535
AND sl.mobile LIKE concat('%',#{params.mobile},'%')
3636
</if>
@@ -80,7 +80,7 @@
8080
send_log sl
8181
left join signature s on sl.signature = s.code
8282
<where>
83-
sl.is_delete = 1 and s.is_delete = 1
83+
sl.is_delete = 1
8484
<if test="params.startCreateTime != null">
8585
and sl.create_time >= DATE_FORMAT(#{params.startCreateTime}, '%Y-%m-%d %H:%i:%S' )
8686
</if>
@@ -128,7 +128,7 @@
128128
LEFT JOIN receive_log rl ON sl.api_log_id = rl.api_log_id
129129
LEFT JOIN signature s ON sl.signature = s.CODE
130130
WHERE
131-
rl.business = #{params.business} and sl.is_delete = 1 and rl.is_delete = 1 and s.is_delete = 1
131+
rl.business = #{params.business} and sl.is_delete = 1
132132
</select>
133133
<select id="sendLogPage" resultType="com.ydl.sms.vo.SendLogPageVO">
134134
SELECT
@@ -150,7 +150,7 @@
150150
LEFT JOIN signature s ON sl.signature = s.CODE
151151
LEFT JOIN template t ON sl.template = t.CODE
152152
<where>
153-
sl.is_delete = 1 and rl.is_delete = 1 and s.is_delete = 1 and t.is_delete = 1
153+
sl.is_delete = 1
154154
<if test="params.date != null">
155155
AND sl.create_time >= DATE_FORMAT(concat(#{params.date},' 00:00:00'), '%Y-%m-%d %H:%i:%S' )
156156
AND sl.create_time <![CDATA[ <= ]]> DATE_FORMAT(concat(#{params.date},' 23:59:59'), '%Y-%m-%d %H:%i:%S')

ydl-sms-manage/src/main/java/com/ydl/sms/controller/PlatformController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ public R addPlatform(@RequestBody PlatformDTO platformDTO) {
9393
*/
9494
@DeleteMapping
9595
@ApiOperation("删除")
96-
public R deletePlatform(List<String> ids) {
96+
public R deletePlatform(@RequestBody List<String> ids) {
9797
platformService.removeByIds(ids);
98-
9998
return R.success("删除成功");
10099
}
101100

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package com.ydl.sms.sms.service.impl;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import com.ydl.sms.sms.dto.BaseParamsDTO;
5+
import com.ydl.sms.sms.dto.R;
6+
import com.ydl.sms.sms.dto.SmsBatchParamsDTO;
7+
import com.ydl.sms.sms.dto.SmsParamsDTO;
8+
import com.ydl.sms.sms.service.SmsSendService;
9+
import com.ydl.sms.sms.utils.SmsEncryptionUtils;
10+
import lombok.extern.slf4j.Slf4j;
11+
import org.apache.commons.lang3.StringUtils;
12+
import org.apache.http.HttpEntity;
13+
import org.apache.http.client.methods.CloseableHttpResponse;
14+
import org.apache.http.client.methods.HttpPost;
15+
import org.apache.http.entity.StringEntity;
16+
import org.apache.http.impl.client.CloseableHttpClient;
17+
import org.apache.http.impl.client.HttpClients;
18+
import org.apache.http.util.EntityUtils;
19+
import org.springframework.beans.factory.annotation.Value;
20+
import org.springframework.stereotype.Component;
21+
22+
@Slf4j
23+
@Component
24+
public class SmsSendServiceImpl implements SmsSendService {
25+
26+
// 网站是否认证
27+
@Value("${ydlclass.sms.auth}")
28+
private boolean auth;
29+
// 网站域名
30+
@Value("${ydlclass.sms.domain}")
31+
private String domain;
32+
@Value("${ydlclass.sms.accessKeyId}")
33+
private String accessKeyId;
34+
@Value("${ydlclass.sms.accessKeySecret}")
35+
private String accessKeySecret;
36+
private String send = "/sms/send";
37+
private String batchSend = "/sms/batchSend";
38+
39+
40+
/**
41+
* 单条短信发送
42+
*
43+
* @param smsParamsDTO
44+
* @return
45+
*/
46+
@Override
47+
public R sendSms(SmsParamsDTO smsParamsDTO) {
48+
String url = domain + send;
49+
50+
return send(smsParamsDTO, url);
51+
}
52+
53+
/**
54+
* 批量发送
55+
*
56+
* @param smsBatchParamsDTO
57+
* @return
58+
*/
59+
@Override
60+
public R batchSendSms(SmsBatchParamsDTO smsBatchParamsDTO) {
61+
String url = domain + batchSend;
62+
63+
return send(smsBatchParamsDTO, url);
64+
}
65+
66+
/**
67+
* 发送http请求
68+
*
69+
* @param baseParamsDTO
70+
* @param url 请求url
71+
* @return 返回请求的响应
72+
*/
73+
private R send(BaseParamsDTO baseParamsDTO, String url) {
74+
// 设置平台秘钥
75+
baseParamsDTO.setAccessKeyId(accessKeyId);
76+
77+
// 认证
78+
if (auth) {
79+
if (StringUtils.isBlank(accessKeyId) || StringUtils.isBlank(accessKeySecret)) {
80+
81+
return R.fail("accessKeyId和accessKeySecret不能为空");
82+
}
83+
} else {
84+
85+
return R.fail("平台未认证");
86+
}
87+
88+
if (StringUtils.isBlank(domain)) {
89+
90+
return R.fail("domain不能为空");
91+
}
92+
93+
baseParamsDTO.setTimestamp(System.currentTimeMillis() + "");
94+
// 加密编码
95+
String encode = SmsEncryptionUtils.encode(baseParamsDTO.getTimestamp(), accessKeyId, accessKeySecret);
96+
baseParamsDTO.setEncryption(encode);
97+
98+
99+
// 创建客户端
100+
CloseableHttpClient httpClient = HttpClients.createDefault();
101+
// 构建请求
102+
HttpPost post = new HttpPost(url);
103+
// 设置请求头
104+
post.setHeader("Content-Type", "application/json; charset=UTF-8");
105+
// 设置请求体
106+
StringEntity stringEntity = new StringEntity(JSON.toJSONString(baseParamsDTO), "UTF-8");
107+
post.setEntity(stringEntity);
108+
109+
110+
// 发送post请求
111+
CloseableHttpResponse response = null;
112+
try {
113+
response = httpClient.execute(post);
114+
// 拿到响应体
115+
HttpEntity responseEntity = response.getEntity();
116+
// 拿到响应状态码
117+
int statusCode = response.getStatusLine().getStatusCode();
118+
119+
// 解析响应体
120+
if (statusCode == 200) {
121+
// 成功
122+
log.info("httpRequest access success, StatusCode is:{}", statusCode);
123+
String responseEntityStr = EntityUtils.toString(responseEntity);
124+
log.info("responseContent is : {}", responseEntityStr);
125+
126+
return JSON.parseObject(responseEntityStr, R.class);
127+
128+
} else {
129+
// 失败
130+
log.error("httpRequest access fail ,StatusCode is:{}", statusCode);
131+
132+
return R.fail("status is ", statusCode);
133+
}
134+
135+
} catch (Exception e) {
136+
log.error("error", e);
137+
138+
return R.fail(e.getMessage());
139+
} finally {
140+
post.releaseConnection();
141+
}
142+
143+
144+
}
145+
146+
147+
}
148+

0 commit comments

Comments
 (0)