SendMessageUtil.java
4.35 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.cjs.cms.util.web;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.cjs.cms.dao.pub.SendMessageLogDao;
import com.jianzhou.sdk.BusinessService;
@Service
public class SendMessageUtil {
@Value("${message.username}")
private String account;
@Value("${message.password}")
private String password;
private Logger log = LogManager.getLogger(SendMessageUtil.class);
@Autowired
private SendMessageLogDao sendMsgLogDao;
/**
* 发送短信
* @param phoneNumber
* @param content
* @return
*
*/
public int send(String phoneNumber, String content) {
// WebService方式
BusinessService bs = new BusinessService();
bs.setWebService("http://www.jianzhou.sh.cn/JianzhouSMSWSServer/services/BusinessService");
int result = bs.sendBatchMessage(account, password, phoneNumber, content);
log.info("短信【" + phoneNumber + "】发送结果:" + result + "\t发送内容:" + content);
Map<String, Object> params = new HashMap<String, Object>();
params.put("phoneNumber", phoneNumber);
params.put("message", content);
params.put("sendResult", result);
sendMsgLogDao.insertMegLog(params);
return result;
}
public String sendMsg(String phoneNumber, String content) {
String msg = "发送成功";
if (StringUtils.isNotBlank(content) && StringUtils.isNotBlank(phoneNumber)) {
String randomStr = content + "【赵涌牛】";
send(phoneNumber, randomStr);
} else {
msg = "手机号或内容不能为空";
}
return msg;
}
/**
* 找回密码发送审核成功信息
* @param phoneNumber
* @param content
* @return
*
*/
public int sendPassword(String phoneNumber, String content) {
// WebService方式
BusinessService bs = new BusinessService();
bs.setWebService("http://www.jianzhou.sh.cn/JianzhouSMSWSServer/services/BusinessService");
int result = bs.sendBatchMessage(account, password, phoneNumber, content);
log.info("短信【" + phoneNumber + "】发送结果:" + result + "\t发送内容:" + content);
Map<String, Object> params = new HashMap<String, Object>();
String str = "";
for (int i = 0; i < content.length(); i++) {
if (NumberUtils.isNumber(content.charAt(i) + "")) {
str = content.replace(content.substring(i, i + 6), "******");
break;
}
}
params.put("phoneNumber", phoneNumber);
params.put("message", str);
params.put("sendResult", result);
sendMsgLogDao.insertMegLog(params);
return result;
}
/**
* 发送审核成功信息
* @param phoneNumber
* @param content
* @return
*
*/
public int sendMess(String phoneNumber, String content) {
// WebService方式
BusinessService bs = new BusinessService();
bs.setWebService("http://www.jianzhou.sh.cn/JianzhouSMSWSServer/services/BusinessService");
int result = bs.sendBatchMessage(account, password, phoneNumber, content);
log.info("短信【" + phoneNumber + "】发送结果:" + result + "\t发送内容:" + content);
Map<String, Object> params = new HashMap<String, Object>();
params.put("phoneNumber", phoneNumber);
params.put("message", content);
params.put("sendResult", result);
sendMsgLogDao.insertMegLog(params);
return result;
}
public String getReceipt(int taskId) {
BusinessService bs = new BusinessService();
bs.setWebService("http://www.jianzhou.sh.cn/JianzhouSMSWSServer/services/BusinessService");
return bs.getReceipt(account, password, taskId);
}
public static void main(String[] args) {
SendMessageUtil send = new SendMessageUtil();
send.account = "sdk_zynybk";
send.password = "zhaoyn@123";
System.out.println(send.getReceipt(190819579));
}
}