MessageService.java
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.common.exception.StdInterfaceException;
import cn.com.glsx.stdinterface.modules.util.RopHttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/**
* @author zhouhaibao
* @version 1.0
* @description: 短信发送服务
* @date 2021/11/14 14:23
*/
@Slf4j
@Service
@RefreshScope
public class MessageService {
@Value("${sendMessageUrl}")
private String sendMessageUrl;
@Value("${sendMessageMethod}")
private String sendMessageMethod;
/**
* 发送短信
*
* @param phone 电话号码,批量用逗号隔开
* @param source 来源
* @param type 类型
* @param context 发送内容
*/
public void sendMessage(String phone, String source, String type, String context) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(4);
try {
params.add("phone", phone);
params.add("source", source);
params.add("messageSource", source);
params.add("type", type);
params.add("context", context);
String post = RopHttpUtil.postE(params, String.class, sendMessageUrl + "?method=" + sendMessageMethod, sendMessageMethod);
log.info("发送短信结果{}", post);
} catch (Exception e) {
e.printStackTrace();
log.info("发送短信异常,{}", e.getMessage());
throw new StdInterfaceException("4444444", e.getMessage());
}
}
}