提交 | 用户 | age
|
a6a76f
|
1 |
package com.yc.sdk.shopping.action.api; |
F |
2 |
|
|
3 |
|
021a6f
|
4 |
import com.alibaba.fastjson.JSON; |
a6a76f
|
5 |
import com.google.gson.JsonElement; |
F |
6 |
import com.google.gson.JsonObject; |
|
7 |
import com.yc.action.BaseAction; |
|
8 |
import com.yc.action.grid.GridUtils; |
|
9 |
import com.yc.action.login.TokenInfo; |
|
10 |
import com.yc.entity.DataSourceEntity; |
|
11 |
import com.yc.entity.UserAccountEntity; |
|
12 |
import com.yc.exception.ApplicationException; |
|
13 |
import com.yc.exception.CallBackMessage; |
|
14 |
import com.yc.factory.FactoryBean; |
|
15 |
import com.yc.multiData.MultiDataSource; |
|
16 |
import com.yc.multiData.SpObserver; |
|
17 |
import com.yc.sdk.jedis.RedisKey; |
|
18 |
import com.yc.sdk.password.action.ChangePassword; |
|
19 |
import com.yc.sdk.shopping.action.VerificationCodes; |
|
20 |
import com.yc.sdk.shopping.entity.InvitationCodeEntity; |
|
21 |
import com.yc.sdk.shopping.service.invitationcode.InvitationCodeIfc; |
|
22 |
import com.yc.sdk.shopping.service.register.AccountIfc; |
|
23 |
import com.yc.sdk.shopping.service.sms.SendSMSMessagesIfc; |
|
24 |
import com.yc.sdk.shopping.util.SettingKey; |
|
25 |
import com.yc.service.BaseService; |
|
26 |
import com.yc.service.build.type.T_22_Ifc; |
|
27 |
import com.yc.utils.AESUtils; |
|
28 |
import com.yc.utils.EncodeUtil; |
|
29 |
import com.yc.utils.SessionKey; |
|
30 |
import org.springframework.beans.factory.annotation.Autowired; |
|
31 |
import org.springframework.dao.IncorrectResultSizeDataAccessException; |
|
32 |
import org.springframework.data.redis.core.RedisTemplate; |
|
33 |
import org.springframework.stereotype.Controller; |
|
34 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
35 |
|
|
36 |
import javax.servlet.http.HttpServletRequest; |
|
37 |
import javax.servlet.http.HttpServletResponse; |
|
38 |
import javax.servlet.http.HttpSession; |
7dd341
|
39 |
import java.util.List; |
F |
40 |
import java.util.Map; |
a6a76f
|
41 |
import java.util.Map.Entry; |
7dd341
|
42 |
import java.util.Random; |
F |
43 |
import java.util.Set; |
a6a76f
|
44 |
import java.util.concurrent.TimeUnit; |
F |
45 |
|
|
46 |
/** |
|
47 |
* 发送短信验证码 |
|
48 |
* |
|
49 |
* @author JohnsWang |
|
50 |
*/ |
|
51 |
@Controller |
|
52 |
|
|
53 |
public class InvitationCode extends BaseAction { |
|
54 |
@Autowired |
|
55 |
AccountIfc accountIfc; |
|
56 |
@SuppressWarnings("rawtypes") |
|
57 |
@Autowired |
|
58 |
RedisTemplate redisTemplate; |
|
59 |
@Autowired |
|
60 |
SendSMSMessagesIfc sms; |
|
61 |
@Autowired |
|
62 |
T_22_Ifc t22ifc; |
|
63 |
@Autowired |
|
64 |
InvitationCodeIfc invitationCodeIfc; |
|
65 |
|
|
66 |
/** |
|
67 |
* 发送注册验证码给手机用户 |
|
68 |
* |
|
69 |
* @param request |
|
70 |
* @param response |
|
71 |
*/ |
|
72 |
|
|
73 |
@RequestMapping("/SendInvitationCode.do") |
|
74 |
public void sendInvitationCode(HttpServletRequest request, HttpServletResponse response) { |
|
75 |
HttpSession session = request.getSession(); |
|
76 |
//String dbId = (String)session.getAttribute(SessionKey.DATA_BASE_ID); |
|
77 |
//if (dbId == null) { |
|
78 |
// dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); |
|
79 |
//} |
|
80 |
// |
|
81 |
CallBackMessage callBackMessage = new CallBackMessage(); |
|
82 |
String wx = request.getParameter(SessionKey.WEIXIN_FROM); |
|
83 |
if (wx == null) { |
|
84 |
wx = (String) session.getAttribute(SessionKey.WEIXIN_FROM); |
|
85 |
} |
|
86 |
String corpId = request.getParameter(SessionKey.WEIXIN_CORPID); |
|
87 |
if (corpId == null || "".equals(corpId)) { |
|
88 |
corpId = request.getParameter(SessionKey.WEIXIN_APPID); |
|
89 |
} |
|
90 |
if (corpId == null || "".equals(corpId)) { |
|
91 |
corpId = (String) session.getAttribute(SessionKey.WEIXIN_CORPID); |
|
92 |
} |
|
93 |
|
|
94 |
String hostUrl = SettingKey.getHostUrl(request); |
|
95 |
//JsonObject json = new JsonObject(); |
|
96 |
//JsonObject errJson = new JsonObject(); |
|
97 |
|
|
98 |
Map<String, String> map = null; |
|
99 |
try { |
|
100 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request); |
|
101 |
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源 |
|
102 |
//获取 参数集 map |
|
103 |
map = t22ifc.getParamMap(request); |
|
104 |
} catch (Exception e) { |
|
105 |
e.printStackTrace(); |
|
106 |
this.print(response, callBackMessage.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
107 |
return; |
|
108 |
} finally { |
|
109 |
SpObserver.setDBtoInstance(); |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
String userCodes = map.get("usercodes"); //request.getParameter("telephone") ; //手机号码 |
|
114 |
|
|
115 |
|
|
116 |
if (userCodes == null || "".equals(userCodes)) { |
|
117 |
|
|
118 |
//errJson.addProperty("warning", "接收注册验证码的用户不能为空!"); |
|
119 |
//json.add("error", errJson); |
|
120 |
|
|
121 |
this.printJson(response, callBackMessage.sendErrorMessage("接收注册验证码的用户不能为空!")); |
|
122 |
return; |
|
123 |
} |
|
124 |
String userCode[] = userCodes.split(","); |
|
125 |
|
|
126 |
int found = 0; |
|
127 |
try { |
|
128 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request); |
|
129 |
|
|
130 |
InvitationCodeEntity invitationCodeEntity = null; |
|
131 |
for (int i = 0; i < userCode.length; i++) { |
|
132 |
UserAccountEntity userAccountEntity = null; |
|
133 |
try { |
|
134 |
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 |
|
135 |
userAccountEntity = invitationCodeIfc.saveInvitationCode(userCode[i], dataSourceEntity.getInvitationCode(), session.getAttribute(SessionKey.HRCODE) + "", session.getAttribute(SessionKey.HRNAME) + ""); |
|
136 |
invitationCodeEntity = new InvitationCodeEntity().setDbId(dataSourceEntity.getDbId() + "").setInvitationCode(dataSourceEntity.getInvitationCode()).setTelephone(userAccountEntity.getTel()); |
|
137 |
|
|
138 |
} catch (Exception e) { |
|
139 |
e.printStackTrace(); |
|
140 |
this.printJson(response, callBackMessage.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
141 |
return; |
|
142 |
} finally { |
|
143 |
SpObserver.setDBtoInstance(); |
|
144 |
} |
|
145 |
|
|
146 |
|
|
147 |
//保存到demo数据库gProfile,gProfileInvitationCode表 |
|
148 |
try { |
|
149 |
SpObserver.setDBtoDemo();// 切换到demo数据源 |
|
150 |
|
|
151 |
int result = invitationCodeIfc.saveUserTogProfile(userAccountEntity, invitationCodeEntity, dataSourceEntity.getInvitationCode()); |
|
152 |
if (result == 0) { |
|
153 |
throw new ApplicationException("提交数据失败"); |
|
154 |
} |
|
155 |
found++; |
|
156 |
} catch (Exception e) { |
|
157 |
e.printStackTrace(); |
|
158 |
this.printJson(response, callBackMessage.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
159 |
return; |
|
160 |
} finally { |
|
161 |
SpObserver.setDBtoInstance(); |
|
162 |
} |
|
163 |
|
|
164 |
try { |
|
165 |
SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 |
|
166 |
//增加流程跟踪记录 |
|
167 |
invitationCodeIfc.saveTraceLogByUserCode(userCode[i], "成功发送注册验证码", "发送注册验证码", "提交"); |
|
168 |
String content = "手机号" + invitationCodeEntity.getTelephone() + "已开通(" + dataSourceEntity.getSystemDescribe() + ")APP应用,请用该号+ERP系统密码登录,祝使用愉快!"; |
|
169 |
String sendResult = sms.sendSMS(dataSourceEntity.getDbId() + "", hostUrl, invitationCodeEntity.getTelephone(), content, wx, corpId); |
|
170 |
if (sendResult != null && !"".equals(sendResult)) { |
|
171 |
this.printJson(response, callBackMessage.sendErrorMessage(sendResult)); |
|
172 |
return; |
|
173 |
} |
|
174 |
|
|
175 |
} catch (Exception e) { |
|
176 |
e.printStackTrace(); |
|
177 |
this.printJson(response, callBackMessage.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
178 |
return; |
|
179 |
} finally { |
|
180 |
SpObserver.setDBtoInstance(); |
|
181 |
} |
|
182 |
} |
|
183 |
} catch (Exception e) { |
|
184 |
e.printStackTrace(); |
|
185 |
this.printJson(response, callBackMessage.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
186 |
return; |
|
187 |
} |
021a6f
|
188 |
callBackMessage.setMemo("成功开通" + found + "个APP用户!").sendSuccessMessageByDefault(); |
F |
189 |
this.printJson(response, JSON.toJSONString(callBackMessage.toJSONObject())); |
a6a76f
|
190 |
return; |
F |
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* 验证手机APP注册验证码 |
|
195 |
* |
|
196 |
* @param request |
|
197 |
* @param response |
|
198 |
*/ |
|
199 |
@RequestMapping("/api/CheckInvitationCode.do") |
|
200 |
public void checkInvitationCode(HttpServletRequest request, HttpServletResponse response) { |
|
201 |
String invitationCode = request.getParameter("InvitationCode"); //注册验证码 |
|
202 |
JsonObject json = new JsonObject(); |
|
203 |
JsonObject errJson = new JsonObject(); |
|
204 |
//检查 注册验证码是否正确 |
|
205 |
InvitationCodeEntity invitationCodeEntity = null; |
|
206 |
try { |
|
207 |
invitationCodeEntity = (InvitationCodeEntity) redisTemplate.opsForValue().get(RedisKey.InvitationCode + invitationCode); |
|
208 |
if (invitationCodeEntity == null) { |
|
209 |
errJson.addProperty("warning", "注册验证码不正确!"); |
|
210 |
errJson.addProperty("InvitationCode", "注册验证码不正确!"); |
|
211 |
json.add("error", errJson); |
|
212 |
this.printJson(response, json.toString()); |
|
213 |
return; |
|
214 |
} |
|
215 |
//发送验证码到对应手机号,完成最后的注册. |
|
216 |
VerificationCodes verificationCodes = (VerificationCodes) FactoryBean.getBean("verificationCodes"); |
|
217 |
request.setAttribute(SessionKey.SHOPPING_DBID, invitationCodeEntity.getDbId()); |
|
218 |
verificationCodes.GenRandomVcode(invitationCodeEntity.getTelephone(), request, response); |
|
219 |
|
|
220 |
} catch (Exception e) { |
|
221 |
e.printStackTrace(); |
|
222 |
errJson.addProperty("warning", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
|
223 |
errJson.addProperty("InvitationCode", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
|
224 |
json.add("error", errJson); |
|
225 |
this.printJson(response, json.toString()); |
|
226 |
return; |
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
/** |
|
231 |
* 手机APP注册 |
|
232 |
* |
|
233 |
* @param request |
|
234 |
* @param response |
|
235 |
*/ |
|
236 |
@SuppressWarnings("unchecked") |
|
237 |
@RequestMapping("/regUser.do") |
|
238 |
public void regUser(HttpServletRequest request, HttpServletResponse response) { |
|
239 |
String telephone = request.getParameter("Telephone"); //手机号 |
|
240 |
//String applyUserName = request.getParameter("ApplyUserName") ; //真实姓名 |
|
241 |
//String applyCompanyName = request.getParameter("ApplyCompanyName") ; //申请人所属公司名称 |
|
242 |
//String applyCcName = request.getParameter("ApplyCcName") ; //申请人所属部门 |
|
243 |
//String positionName = request.getParameter("PositionName") ; //职位 |
|
244 |
//String applyMemo = request.getParameter("ApplyMemo") ; //备注 |
|
245 |
String code = request.getParameter("code"); //手机验证码 |
|
246 |
String pwd = request.getParameter("Password"); //登录密码 |
|
247 |
String invitationCode = request.getParameter("InvitationCode"); //注册验证码 |
|
248 |
String equipmentModel = request.getParameter("EquipmentModel"); //设备型号,如 iPhoe8 , S9 ,HuaWei Pro10 |
|
249 |
String uniqueIdentifier = request.getParameter("UniqueIdentifier"); //设备唯一标识符 |
|
250 |
String driverType = request.getParameter("driverType"); //设备类型 |
|
251 |
JsonObject json = new JsonObject(); |
|
252 |
JsonObject errJson = new JsonObject(); |
|
253 |
try { |
|
254 |
// if (telephone == null || "".equals(telephone)) { |
|
255 |
// errJson.addProperty("Telephone", "手机号 必须输入!"); |
|
256 |
// } |
|
257 |
// if (applyUserName == null || "".equals(applyUserName)) { |
|
258 |
// errJson.addProperty("ApplyUserName", "真实姓名 必须输入!"); |
|
259 |
// } |
|
260 |
// if (applyCompanyName == null || "".equals(applyCompanyName)) { |
|
261 |
// errJson.addProperty("ApplyCompanyName", "公司名称 必须输入!"); |
|
262 |
// } |
|
263 |
// |
|
264 |
// if (applyCcName == null || "".equals(applyCcName)) { |
|
265 |
// errJson.addProperty("ApplyCcName", "部门 必须输入!"); |
|
266 |
// } |
|
267 |
if (pwd == null || "".equals(pwd)) { |
|
268 |
errJson.addProperty("Password", "密码必须输入!"); |
|
269 |
} |
|
270 |
//检查 注册验证码是否正确 |
|
271 |
InvitationCodeEntity invitationCodeEntity = (InvitationCodeEntity) redisTemplate.opsForValue().get(RedisKey.InvitationCode + invitationCode); |
|
272 |
if (invitationCodeEntity == null) { |
|
273 |
errJson.addProperty("warning", "注册验证码不正确!"); |
|
274 |
errJson.addProperty("InvitationCode", "注册验证码不正确!"); |
|
275 |
json.add("error", errJson); |
|
276 |
this.printJson(response, json.toString()); |
|
277 |
return; |
|
278 |
} |
|
279 |
telephone = invitationCodeEntity.getTelephone(); |
|
280 |
invitationCode = invitationCodeEntity.getInvitationCode();//取企业码,绑定数据源 |
|
281 |
if (verificationCode(response, telephone, code, json, errJson)) return; |
|
282 |
|
|
283 |
Set<Entry<String, JsonElement>> it = errJson.entrySet(); |
|
284 |
if (!it.isEmpty() && it.size() != 0) { |
|
285 |
json.add("error", errJson); |
|
286 |
this.printJson(response, json.toString()); |
|
287 |
return; |
|
288 |
} |
|
289 |
|
|
290 |
// SpObserver.setDBtoInstance("_" + invitationCodeEntity.getDbId());// 切换数据源 |
|
291 |
|
|
292 |
// //保存APP用户的注册信息 |
|
293 |
// boolean success = invitationCodeIfc.saveApplyUserInfo(telephone,applyUserName,applyCompanyName,applyCcName, positionName, applyMemo) ; |
|
294 |
// if (success) { |
|
295 |
// //增加流程跟踪记录,TODO 这里需要有单号才能正常执行 |
|
296 |
// //invitationCodeIfc.saveTraceLogByUserCode(telephone, "注册成功【设备:"+(equipmentModel==null?"":equipmentModel) +"】", "注册成功", "提交") ; |
|
297 |
// }else { |
|
298 |
// errJson.addProperty("warning", "注册失败,原因:【APP注册申请单】不存在该手机号码,请在9668功能号中检查,解决方法:重新向管理员索取【注册验证码】然后再注册!"); |
|
299 |
// json.add("error", errJson); |
|
300 |
// this.printJson(response, json.toString()); |
|
301 |
// return; |
|
302 |
// } |
|
303 |
|
|
304 |
} catch (Exception e) { |
|
305 |
e.printStackTrace(); |
|
306 |
errJson.addProperty("warning", e.getMessage()); |
|
307 |
//errJson.addProperty(SettingKey.CLTTEL, e.getMessage()); |
|
308 |
json.add("error", errJson); |
|
309 |
this.printJson(response, json.toString()); |
|
310 |
return; |
|
311 |
} finally { |
|
312 |
//SpObserver.setDBtoInstance(); |
|
313 |
} |
|
314 |
|
|
315 |
try { |
|
316 |
SpObserver.setDBtoDemo(); //切换到 demo 数据库 |
|
317 |
//更新 gProfileInvitationCode 表中注册状态 |
|
318 |
String pwd_str = null; |
|
319 |
//加密 密码 |
|
320 |
if (pwd.length() < 30) |
|
321 |
pwd_str = ChangePassword.getEncryptPassword(pwd); |
|
322 |
else |
|
323 |
pwd_str = EncodeUtil.replaceUrlChar(pwd); |
|
324 |
//取userid |
|
325 |
String userid = invitationCodeIfc.getUserid(telephone); |
|
326 |
boolean success = invitationCodeIfc.saveGProfileInvitationCode(userid, invitationCode, |
|
327 |
equipmentModel, uniqueIdentifier, pwd_str, driverType); |
|
328 |
if (success) { |
|
329 |
//清空手机号验证码 |
|
330 |
redisTemplate.delete(VerificationCodes.getCodeKey(telephone)); |
|
331 |
//清空注册验证码 |
|
332 |
redisTemplate.delete(RedisKey.InvitationCode + invitationCode); |
|
333 |
json.addProperty("status", "注册成功!"); |
|
334 |
} else { |
|
335 |
errJson.addProperty("warning", "注册失败,原因:写入 表时发生错误,请联系系统管理员 !"); |
|
336 |
json.add("error", errJson); |
|
337 |
this.printJson(response, json.toString()); |
|
338 |
return; |
|
339 |
} |
|
340 |
} catch (Exception e) { |
|
341 |
e.printStackTrace(); |
|
342 |
errJson.addProperty("warning", this.getErrorMsg(e)); |
|
343 |
json.add("error", errJson); |
|
344 |
this.printJson(response, json.toString()); |
|
345 |
return; |
|
346 |
} finally { |
|
347 |
SpObserver.setDBtoInstance(); |
|
348 |
} |
|
349 |
//获取企业列表 |
|
350 |
//this.getMyCompany(telephone,invitationCode,request,response); |
|
351 |
this.printJson(response, json.toString()); |
|
352 |
return; |
|
353 |
} |
|
354 |
|
|
355 |
public boolean verificationCode(HttpServletResponse response, String telephone, String code, JsonObject json, JsonObject errJson) { |
|
356 |
//检查验证码是否正确 |
|
357 |
String code2 = ""; |
|
358 |
try { |
|
359 |
//VerificationCodes.getCodeKey() 函数中的 dbId 值必须传空值 |
|
360 |
code2 = (String) redisTemplate.opsForValue().get(VerificationCodes.getCodeKey(telephone)); |
|
361 |
} catch (Exception e) { |
|
362 |
e.printStackTrace(); |
|
363 |
errJson.addProperty("code", e.getMessage()); |
|
364 |
json.add("error", errJson); |
|
365 |
this.printJson(response, json.toString()); |
|
366 |
return true; |
|
367 |
} |
|
368 |
if (code == null || "".equals(code2) || code2 == null || "".equals(code2) || !code.equals(code2)) { |
|
369 |
errJson.addProperty("code", "验证码不正确!"); |
|
370 |
json.add("error", errJson); |
|
371 |
this.printJson(response, json.toString()); |
|
372 |
} |
|
373 |
return false; |
|
374 |
} |
|
375 |
|
|
376 |
/*** |
|
377 |
* 通过手机号获取所关联的企业数据源信息 |
|
378 |
* @param telephone |
|
379 |
* @param pwd |
|
380 |
* @param request |
|
381 |
* @param response |
|
382 |
* @return |
|
383 |
*/ |
|
384 |
@RequestMapping("/api/myCompany.do") |
|
385 |
public void getMyCompany(String telephone, String pwd, HttpServletRequest request, HttpServletResponse response) { |
|
386 |
JsonObject json = new JsonObject(); |
|
387 |
JsonObject errJson = new JsonObject(); |
|
388 |
CallBackMessage callBackMessage=new CallBackMessage(); |
|
389 |
try { |
|
390 |
boolean flg = false; |
|
391 |
if (telephone == null || "".equals(telephone) || "null".equalsIgnoreCase(telephone)) { |
|
392 |
errJson.addProperty("Telephone", "手机号 必须输入!"); |
|
393 |
flg = true; |
|
394 |
} |
|
395 |
if (flg) { |
|
396 |
json.add("error", errJson); |
|
397 |
this.printJson(response, json.toString()); |
|
398 |
return; |
|
399 |
} |
|
400 |
|
|
401 |
//取得企业数据源列表 |
|
402 |
|
|
403 |
List<Map<String, Object>> list = getDbList(telephone, pwd); |
|
404 |
if (list == null || (list != null && list.size() == 0)) { |
|
405 |
|
|
406 |
this.printJson(response, callBackMessage.sendErrorMessage("企业列表为空,请检查账号或密码是否正确",-1)); |
|
407 |
return; |
|
408 |
} |
|
409 |
this.printJson(response, GridUtils.toJson(list)); |
|
410 |
return; |
|
411 |
}catch (ApplicationException ex){ |
|
412 |
this.printJson(response,callBackMessage.sendErrorMessage(ex.getMessage(),ex.getCode())); |
|
413 |
return; |
|
414 |
}catch (Exception e) { |
|
415 |
this.printJson(response, callBackMessage.sendErrorMessage(e.getMessage(),-1)); |
|
416 |
return; |
|
417 |
} |
|
418 |
} |
|
419 |
|
|
420 |
/** |
|
421 |
* 验证用户是否存在 |
|
422 |
* @param telephone |
|
423 |
* @param pwd |
|
424 |
* @return |
|
425 |
* @throws Exception |
|
426 |
*/ |
|
427 |
public boolean checkPasswordByTelephone(String telephone, String pwd,String dbid) throws Exception { |
|
428 |
String pwd_str = null; |
|
429 |
if (pwd.length() < 50)//TODO 表示传过来的还是未加密 |
|
430 |
pwd_str = ChangePassword.getEncryptPassword(pwd);//加密密码 |
|
431 |
else |
|
432 |
pwd_str = pwd; |
|
433 |
BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); |
|
434 |
|
|
435 |
try { |
|
436 |
SpObserver.setDBtoDemo(); |
|
437 |
Map user = baseService.getJdbcTemplate().queryForMap("set nocount on \n select a.userid,a.password,isnull(b.Status,0) as status from gProfile a join gProfileInvitationCode b on a.UserId=b.UserId \n" + |
|
438 |
" where b.invitationcode in \n" + |
|
439 |
" (select invitationcode from gsystem where id = ?)\n" + |
|
440 |
" and Telephone=? ", dbid,telephone); |
|
441 |
if (user != null) { |
|
442 |
if(GridUtils.prossRowSetDataType_Int(user,"status")==0){ |
|
443 |
throw new ApplicationException("账号["+telephone+"]已禁止登陆,请联系系统管理员"); |
|
444 |
} |
|
445 |
String decryptpwd = ChangePassword.getDecryptPassword(pwd_str); |
|
446 |
String userPwd = ChangePassword.getDecryptPassword(user.get("password") + ""); |
|
447 |
if (!decryptpwd.equals(userPwd)) { |
|
448 |
throw new ApplicationException("密码错误"); |
|
449 |
} else { |
|
450 |
return true; |
|
451 |
} |
|
452 |
} else { |
|
453 |
throw new ApplicationException(telephone + "-未有注册"); |
|
454 |
} |
|
455 |
|
|
456 |
} catch (IncorrectResultSizeDataAccessException ex) { |
|
457 |
throw new ApplicationException("此账号不存在[" + telephone + "]"); |
|
458 |
} catch (Exception ex) { |
|
459 |
throw new ApplicationException(this.getErrorMsg(ex)); |
|
460 |
} finally { |
|
461 |
SpObserver.setDBtoInstance(); |
|
462 |
} |
|
463 |
|
|
464 |
|
|
465 |
} |
|
466 |
|
|
467 |
public List<Map<String, Object>> getDbList(String telephone, String pwd) throws Exception { |
|
468 |
String pwd_str = null; |
|
469 |
if (pwd.length() < 50)//TODO 表示传过来的还是未加密 |
|
470 |
pwd_str = ChangePassword.getEncryptPassword(pwd);//加密密码 |
|
471 |
else |
|
472 |
pwd_str = pwd; |
|
473 |
BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); |
|
474 |
String sql = "set nocount on \n" + |
|
475 |
" select g.Protocol,g.id,g.systemid as name,g.domain,isnull(p.isdebug,0) as isdebug,isnull(p.Status,0) as status \n" + |
|
476 |
" from gsystem g join gProfileInvitationCode p on g.InvitationCode = p.InvitationCode \n" + |
7dd341
|
477 |
" where p.userid =? \n" + |
F |
478 |
" and g.actived = 1 \n" + |
|
479 |
" and (g.expiredDate is null or DATEDIFF(day,g.expiredDate,getdate()) <=0 ) \n" + |
|
480 |
" order by g.systemid asc"; |
a6a76f
|
481 |
|
F |
482 |
String encrypt_tel = telephone; |
|
483 |
if (telephone.length() > 20) {//手机号解密 |
|
484 |
try { |
|
485 |
encrypt_tel = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(telephone)); |
|
486 |
} catch (Exception e) { |
|
487 |
e.printStackTrace(); |
|
488 |
throw new ApplicationException("传入手机号码解密出错",-1); |
|
489 |
} |
|
490 |
} |
|
491 |
List<Map<String, Object>> list = null; |
|
492 |
try { |
|
493 |
SpObserver.setDBtoDemo(); |
|
494 |
Map user = baseService.getJdbcTemplate().queryForMap("set nocount on \n select userid,password from gProfile where Telephone=? ", encrypt_tel); |
|
495 |
if (user != null) { |
|
496 |
String decryptpwd=null; |
|
497 |
try{ |
|
498 |
decryptpwd = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(pwd_str)); |
|
499 |
} catch (Exception e) { |
|
500 |
e.printStackTrace(); |
|
501 |
throw new ApplicationException("传入密码解密出错",-1); |
|
502 |
} |
|
503 |
String userPwd = ChangePassword.getDecryptPassword(user.get("password") + ""); |
|
504 |
if (!decryptpwd.equals(userPwd)) { |
|
505 |
throw new ApplicationException("密码不相符,请重新登录",-1001); |
|
506 |
} else { |
|
507 |
list = baseService.getSimpleJdbcTemplate().queryForList(sql, user.get("userid")); |
|
508 |
//TODO 取9001的域名,可以随时转换成其他域名 |
|
509 |
if(list!=null&&list.size()>0) { |
|
510 |
|
|
511 |
for (Map<String, Object> map : list) { |
|
512 |
if (GridUtils.prossRowSetDataType_Int(map, "status") == 0) { |
|
513 |
String name = GridUtils.prossRowSetDataType_String(map, "name"); |
|
514 |
map.put("name", name + "[禁止登录]"); |
|
515 |
}else{ |
|
516 |
//生成用户的token |
|
517 |
map.put("token",genToken(pwd_str,encrypt_tel,Integer.parseInt(map.get("id")+""))); |
|
518 |
} |
|
519 |
boolean isHttps;//是否已开启https |
|
520 |
if(!"https".equalsIgnoreCase(GridUtils.prossRowSetDataType_StringByReplaceBlank(map, "Protocol"))){ |
|
521 |
isHttps=false; |
|
522 |
map.put("Protocol","http"); |
|
523 |
}else{ |
|
524 |
isHttps=true; |
|
525 |
} |
|
526 |
boolean isdebug = GridUtils.prossRowSetDataType_Boolean(map, "isdebug"); |
|
527 |
String domain = (String) map.get("domain"); |
|
528 |
String name = (String) map.get("name"); |
|
529 |
String[] temp = domain.split(";"); |
|
530 |
boolean isfound = false; |
|
531 |
if (isdebug && domain.indexOf(":9010") > 0) { |
|
532 |
for (String s : temp) { |
|
533 |
if (s.indexOf(":9010") > 0) {// 优先9001,&&s.startsWith("192.168.100.202") |
|
534 |
//s = getProtocol(map, s); |
|
535 |
map.put("domain","http://"+s); |
|
536 |
map.put("name", name + "[调试模式]"); |
|
537 |
isfound = true; |
|
538 |
break; |
|
539 |
} |
|
540 |
} |
|
541 |
} |
|
542 |
|
|
543 |
if(isHttps){ |
|
544 |
if (!isfound) {//查找443 https |
|
545 |
for (String s : temp) { |
|
546 |
if (s.indexOf(":") < 0) {// 取443端口 |
|
547 |
// s = getProtocol(map, s); |
|
548 |
map.put("domain","https://"+s); |
|
549 |
isfound = true; |
|
550 |
break; |
|
551 |
} |
|
552 |
} |
|
553 |
} |
|
554 |
}else{ |
|
555 |
if (!isfound && domain.indexOf(":9001") > 0) { |
|
556 |
for (String s : temp) { |
|
557 |
if (s.indexOf(":9001") > 0) {// 优先9001,&&s.startsWith("192.168.100.202") |
|
558 |
//s = getProtocol(map, s); |
|
559 |
map.put("domain","http://"+s); |
|
560 |
isfound = true; |
|
561 |
break; |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
565 |
if (!isfound && domain.indexOf(":80") > 0) { |
|
566 |
for (String s : temp) { |
|
567 |
if (s.indexOf(":80") > 0) { |
|
568 |
//s = getProtocol(map, s); |
|
569 |
map.put("domain","http://"+s); |
|
570 |
isfound = true; |
|
571 |
break; |
|
572 |
} |
|
573 |
} |
|
574 |
} |
|
575 |
} |
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
} |
|
580 |
} |
|
581 |
return list; |
|
582 |
} |
|
583 |
} else { |
|
584 |
throw new ApplicationException("当前手机号码未有注册",-1); |
|
585 |
} |
|
586 |
|
|
587 |
} catch (IncorrectResultSizeDataAccessException ex) { |
|
588 |
throw new ApplicationException("此账号不存在",-1); |
|
589 |
} finally { |
|
590 |
SpObserver.setDBtoInstance(); |
|
591 |
} |
|
592 |
|
|
593 |
|
|
594 |
} |
|
595 |
/*** |
|
596 |
* app登陆生成token,及写到缓存 ,以dbid,usercode为key |
|
597 |
* @param session |
|
598 |
* @return uuid |
|
599 |
*/ |
|
600 |
public final static String TOKEN_STR="Lg_TokenV2:";//登录token的前缀 |
|
601 |
public String genToken(String pwd,String usercode,int dbid) { |
|
602 |
TokenInfo tokenInfo=new TokenInfo(); |
|
603 |
tokenInfo.setUsercode(usercode); |
|
604 |
tokenInfo.setDbid(dbid); |
|
605 |
double rand=new Random().nextDouble(); |
|
606 |
tokenInfo.setRand(rand);//增加随机数,以便用于生成不同的token |
|
607 |
try { |
|
608 |
//格式dbid:usercode |
|
609 |
String key = InvitationCode.TOKEN_STR+tokenInfo.getDbid() + ":" + tokenInfo.getUsercode(); |
|
610 |
RedisTemplate redisTemplate = (RedisTemplate) FactoryBean.getBean("redisTemplate"); |
|
611 |
final int OVERTIME = 12;//12小时过期,时间限制 |
|
612 |
redisTemplate.opsForValue().set(key, pwd+"#"+rand,OVERTIME,TimeUnit.HOURS); |
|
613 |
String token= AESUtils.encrypt(GridUtils.toJson(tokenInfo));//dbid+usercode加密返回给APP客户端保存 |
|
614 |
return token; |
|
615 |
}catch(Exception ex){ |
|
616 |
ex.printStackTrace(); |
|
617 |
return ""; |
|
618 |
} |
|
619 |
} |
|
620 |
public String getProtocol(Map<String, Object> map, String s) { |
|
621 |
String domain=""; |
|
622 |
Object protocol=map.get("Protocol"); |
|
623 |
if(protocol!=null){ |
|
624 |
domain=protocol+"://"+s; |
|
625 |
}else { |
|
626 |
domain="http://"+s; |
|
627 |
} |
|
628 |
return domain; |
|
629 |
} |
|
630 |
|
|
631 |
} |
|
632 |
|