发表于: 2017-12-20 23:39:11

1 702


今天完成的事
学生证模块的发送验证码和绑定
本来发送验证码分为发送手机验证码和发送邮箱验证码
我把两个接口整合为一个
根据前端传来的参数的值决定发送那种验证码
@RequestMapping(value = "/a/u/code", method = RequestMethod.POST)
public String sendVerificationCode(Long uid, Long mobile, String mail) throws Exception {
String varCode = RandomCodeUtil.getRandomString();
Code code = new Code();
code.setUid(uid);
code.setCode(Long.parseLong(varCode));
if (mobile != null) {
code.setPhone(mobile);
code.setType(1);
codeService.insert(code);
SendSMSUtil.sendSMS(mobile, varCode);
}
if (mail != null && mail != "") {
code.setEmail(mail);
code.setType(0);
codeService.insert(code);
try {
SendEmailUtil.sendEmail(mail, Integer.parseInt(varCode));
} catch (Throwable throwable) {
log.error("sendEmail is fail");
}
}
return "/data/json";
}
绑定功能
同样是判断前端传过来的值
搜索数据库中该用户的验证码记录
@RequestMapping(value = "/a/u/binding", method = RequestMethod.POST)
public String binging(Long uid, Long mobile, String mail, String varCode,ModelMap model) throws Exception {
// 三元操作符,返回mobilemail中间有的那一个
String str = mobile == null ? mail : mobile.toString();
Integer codeType = mobile == null ? 0 : 1;
if (str != null && str != "" && varCode != null && varCode != "") {
User user = userService.getObjectById(uid);
Map<String, Object> map = DynamicUtil.getCodeIDs(uid, codeType);
List<Long> idList =new ArrayList<Long>();
idList= codeService.getIdsByDynamicCondition(Code.class, map, 0, Integer.MAX_VALUE);
Code code = codeService.getObjectById(idList.get(0));
log.error(code.getCode());
log.error(varCode);
if (code.getCode().equals(Long.parseLong(varCode))) {
if (codeType.equals(0)) {
user.setMail(mail);
userService.update(user);
model.addAttribute("code",0);
}
if (codeType.equals(1)) {
user.setMobile(mobile);
userService.update(user);
model.addAttribute("code",0);
}
} else {
log.error("code is not equal varCode");
}
} else {
log.error("mobile and mail is nothing");
}
return "/data/json";
}
明天计划的事
完成学生个人收藏
遇到的问题
收获



返回列表 返回列表
评论

    分享到