MessageAction.java
9.81 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package com.cjs.site.action.pub;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cjs.site.biz.ServiceException;
import com.cjs.site.biz.pub.SendMessageBiz;
import com.cjs.site.dao.user.account.ClientInfoDao;
import com.cjs.site.model.user.account.ClientInfo;
import com.cjs.site.model.user.account.UserInfo;
import com.cjs.site.util.lang.JsonUtil;
import com.cjs.site.util.lang.StringUtil;
import com.cjs.site.util.t2.T2Result;
import com.cjs.site.util.t2.T2Util;
import com.cjs.site.util.web.ActionUtil;
import com.google.code.kaptcha.Constants;
/**
* 手机号码
*
* @author tongxiaochuan
*
*/
@Controller
@RequestMapping("/msg")
public class MessageAction {
@Autowired
private ClientInfoDao clientInfoDao;
@Autowired
private SendMessageBiz sendMessageBiz;
Logger log = LogManager.getLogger();
/**
* 发送短信验证码
* @param session
* @param mobile_tel
*
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping("/sendMsg")
public @ResponseBody String sendMsg(HttpSession session, String mobile_tel,
String valiadateCode) {
String randomNum = (int) (Math.random() * 1000000) + "";
if (randomNum.length() < 6) {
randomNum = StringUtil.lpad(6, randomNum);
}
Map<String, Object> outmap = new HashMap<String, Object>();
String validCode = (String) session.getAttribute(Constants.KAPTCHA_SESSION_KEY);
if (StringUtils.isBlank(validCode) || !StringUtils.equals(valiadateCode, validCode)) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "图形验证码错误");
return JsonUtil.toJson(outmap);
}
if (Integer.parseInt(session.getAttribute("KAPTCHA_TIMES").toString()) > 3) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "图形验证码过期,请刷新后重试");
return JsonUtil.toJson(outmap);
}
//测试临时添加
// randomNum = "111111";
if (StringUtil.isBlank(mobile_tel)) {
UserInfo userInfo = ActionUtil.getUser();
ClientInfo clientInfo = clientInfoDao.queryByClientId(userInfo.getClient_id());
mobile_tel = clientInfo.getMobileTel();
}
String randomStr = "您的开户验证码:" + randomNum + ",请确保本人操作。如有疑问,详询400-969-0800。【赵涌牛】";
System.out.println("the num is :" + randomNum);
outmap = sendMessageBiz.send(mobile_tel, randomStr);
session.setAttribute("KAPTCHA_TIMES",
Integer.parseInt(session.getAttribute("KAPTCHA_TIMES").toString()) + 1);
if ("0".equals(outmap.get("resultCode"))) {
return JsonUtil.toJson(outmap);
}
List<Map<String, Object>> randomNums = (List<Map<String, Object>>) session
.getAttribute("randomNum");
if (randomNums == null) {
randomNums = new ArrayList<Map<String, Object>>();
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("tel", mobile_tel);
map.put("smsCode", randomNum);
randomNums.add(map);
session.setAttribute("randomNum", randomNums);
session.setAttribute("yz_phone", mobile_tel);
session.setAttribute("sms_order_id", outmap.get("result"));
session.setAttribute("sms_code", randomNum);
outmap.put("resultCode", "1");
return JsonUtil.toJson(outmap);
}
/**
* 给当前用户发送短信验证码(无图形验证码)
* @param type 验证码信息类型
* @return
*/
@ResponseBody
@RequestMapping("sendValidCode")
public String sendValidCode(HttpSession session) {
return sendMessageBiz.sendMsg(1, session);
}
/**
* 发送提现短信
* @param session
* @return
*/
@ResponseBody
@RequestMapping("kiting")
public String sendForKiting(HttpSession session) {
return sendMessageBiz.sendMsg(2, session);
}
/**
* 银行卡换绑发送短信验证码
* @param session
* @param mobile_tel
*
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping("/changeCardSendMsg")
public @ResponseBody String changeCardSendMsg(HttpSession session) {
UserInfo userInfo = ActionUtil.getUser();
String randomNum = (int) (Math.random() * 1000000) + "";
if (randomNum.length() < 6) {
randomNum = StringUtil.lpad(6, randomNum);
}
ClientInfo clientInfo = clientInfoDao.queryByClientId(userInfo.getClient_id());
if (clientInfo == null) {
throw new ServiceException("用户信息不存在");
}
String mobile_tel = clientInfo.getMobileTel();
String randomStr = "您的换绑银行卡验证码:" + randomNum + ",请确保本人操作。如有疑问,详询400-969-0800。【赵涌牛】";
System.out.println("the num is :" + randomNum);
Map<String, Object> result = sendMessageBiz.send(mobile_tel, randomStr);
if ("0".equals(result.get("resultCode"))) {
return JsonUtil.toJson(result);
}
List<String> randomNums = (List<String>) session.getAttribute("randomNumber");
if (randomNums == null) {
randomNums = new ArrayList<String>();
}
randomNums.add(randomNum);
session.setAttribute("randomNumber", randomNums);
session.setAttribute("yz_phone", mobile_tel);
session.setAttribute("sms_order_id", result.get("result"));
session.setAttribute("sms_code", randomNum);
return JsonUtil.toJson(result);
}
/**
* 验证短信验证码
* @param randomNum
* @param session
* @param model
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping("/checkRandomMsg")
public @ResponseBody String checkRandomMsg(String randomNum, String mobile,
HttpSession session) {
List<Map<String, Object>> randomNums = (List<Map<String, Object>>) session
.getAttribute("randomNum");
Map<String, Object> map = new HashMap<String, Object>();
map.put("tel", mobile);
map.put("smsCode", randomNum);
if (randomNums != null && randomNums.contains(map)) {
//验证码正确
return JsonUtil.toJson("resultCode", "1");
} else {
return JsonUtil.toJson("resultCode", "0");
}
}
/**
* 绑卡短信验证码
* @param session
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping("/bindCardSendMsg")
public @ResponseBody String bindCardSendMsg(HttpSession session) {
UserInfo userInfo = ActionUtil.getUser();
Map<String, Object> params = new HashMap<String, Object>();
params.put("client_id", userInfo.getClient_id());
params.put("fund_account", userInfo.getFund_account());
T2Result result = T2Util.request(params, "619829");
System.out.println(result);
String mobile_tel = result.getData().get(0).get("mobile_tel").toString();
String randomNum = (int) (Math.random() * 1000000) + "";
if (randomNum.length() < 6) {
randomNum = StringUtil.lpad(6, randomNum);
}
String randomStr = "您的绑卡验证码:" + randomNum + ",请确保本人操作。如有疑问,详询400-969-0800。【赵涌牛】";
System.out.println("您的绑卡验证码::" + randomNum + ",手机号" + mobile_tel);
Map<String, Object> outmap = sendMessageBiz.send(mobile_tel, randomStr);
if ("0".equals(outmap.get("resultCode"))) {
return JsonUtil.toJson(outmap);
}
List<String> randomNums = (List<String>) session.getAttribute("randomNumer");
if (randomNums == null) {
randomNums = new ArrayList<String>();
}
randomNums.add(randomNum);
session.setAttribute("randomNumber", randomNums);
return JsonUtil.toJson(outmap);
}
/**
* 更换手机号_发送验证码
* @param mobileTel
* @param session
* @return
*/
@ResponseBody
@SuppressWarnings("unchecked")
@RequestMapping("/changeTelSms")
public String changeTelSms(String mobileTel, HttpSession session) {
String randomNum = (int) (Math.random() * 1000000) + "";
if (randomNum.length() < 6) {
randomNum = StringUtil.lpad(6, randomNum);
}
String randomStr = "您的更换手机验证码:" + randomNum + ",请确保本人操作。如有疑问,详询400-969-0800。【赵涌牛】";
System.out.println("您的更换手机验证码::" + randomNum + ",手机号" + mobileTel);
Map<String, Object> outmap = sendMessageBiz.send(mobileTel, randomStr);
if ("0".equals(outmap.get("resultCode"))) {
return JsonUtil.toJson(outmap);
}
List<Map<String, Object>> randomNums = (List<Map<String, Object>>) session
.getAttribute("randomNum");
if (randomNums == null) {
randomNums = new ArrayList<Map<String, Object>>();
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("tel", mobileTel);
map.put("smsCode", randomNum);
randomNums.add(map);
session.setAttribute("randomNum", randomNums);
return JsonUtil.toJson(outmap);
}
}