发送手机验证码--创蓝
@RequestMapping(value = "/sendphone", produces = "application/json;charset=UTF-8" , method = RequestMethod.POST)
@ResponseBody
public ErrorMsg actionSendPhone(@ModelAttribute SendMessage message, HttpServletRequest request , HttpServletResponse response){
@ResponseBody
public ErrorMsg actionSendPhone(@ModelAttribute SendMessage message, HttpServletRequest request , HttpServletResponse response){
ErrorMsg error = new P2PErrorMsg();
String validate = BaseUtil.validateObj(message);
if(validate != null){//手机号码或者发送类型为空
error.setErrMsg(validate);
}else{
String partten = "^(1[1-9][0-9])\d{8}$";if(Pattern.matches(partten, message.getUserPhone())){//手机号格式正确
//P2PUser user = p2pUserService.checkUserLogin(BaseUtil.getCookie(request, CoreBase.SSO_COOKIE_NAME).getValue());P2PUser search = new P2PUser();search.setUserPhone(message.getUserPhone());P2PUser isHavePhone = p2pUserService.getByAttributes(search);Long userId = isHavePhone == null ? new Long(0) : isHavePhone.getId();HashSet<String> noLoginSend = new HashSet<String>();noLoginSend.add("register_valicode");HashSet<String> haveLoginSend = new HashSet<String>();haveLoginSend.add("forgot_valicode");if(isHavePhone == null && haveLoginSend.contains(message.getSendType())){error.setErrCode(101010);}else if(isHavePhone != null && noLoginSend.contains(message.getSendType())){error.setErrCode(100113);}else{if(StringUtil.isBlank(message.getAuthCode())){//验证码为空HashSet<String> noAuthSend = new HashSet<String>();noAuthSend.add("forget_paypass_valicode");if(!noAuthSend.contains(message.getSendType())){error.setErrCode(100115);}else{Map<String, String> params = new HashMap<>();error = sendTmplService.sendMessage(new Long(0), userId, message.getUserPhone(), message.getSendType(), params, HttpTookit.getRealIpAddr(request));}}else{ //验证码不为空Cookie Vcookie = BaseUtil.getCookie(request, "vali");String authCookie = (Vcookie!=null) ? Vcookie.getValue() : "" ;boolean auth = BaseUtil.validate(authCookie, message.getAuthCode().toUpperCase(),BaseUtil.VALICODE_SALT);if(auth == false){error.setErrCode(100114);}else{ //验证码校验成功Map<String, String> params = new HashMap<>();error = sendTmplService.sendMessage(new Long(0), userId, message.getUserPhone(), message.getSendType(), params, HttpTookit.getRealIpAddr(request));}·}}
}else{ //手机号格式不正确error.setErrCode(100111);}
}}
return error;
public ErrorMsg sendPhone(Long sendId, Long userId, String target, String content, SendTmpl tmpl, String ip){
ErrorMsg error = new P2PErrorMsg();
SendPhone targetTotal = new SendPhone();
targetTotal.setGetUserPhone(new Long(target));
targetTotal.setUseTmpl(new Long(CoreBase.SEND_TMPL_REGISTER_CODE));
targetTotal.setSendTime(String.valueOf(System.currentTimeMillis()/1000l - 86400));
int tarTotal = sendPhoneDao.countByAttributes(targetTotal);
SendPhone ipCountTotal = new SendPhone();
ipCountTotal.setCreateIp(ip);
ipCountTotal.setUseTmpl(new Long(CoreBase.SEND_TMPL_REGISTER_CODE));
ipCountTotal.setCreateTime(String.valueOf(System.currentTimeMillis()/1000l - 86400));
int ipTotal = sendPhoneDao.countByAttributes(ipCountTotal);
if(tarTotal > 20){
error.setErrCode(100104);
}else if(ipTotal > 500){
error.setErrCode(100105);
}else{
SendPhone sendPhone = new SendPhone();sendPhone.setSendUserId(sendId);sendPhone.setGetUserId(userId);sendPhone.setGetUserPhone(new Long(target));sendPhone.setGetUserContent(content);sendPhone.setUseTmpl(tmpl.getId());sendPhone.setRemark(tmpl.getName());sendPhone.setSendTime(String.valueOf(System.currentTimeMillis()/1000l));sendPhone.setCreateIp(ip);Long id = insertWithParams(sendPhone);if(id > 0){SystemParam search = new SystemParam();search.setTypeId(new Long(CoreBase.SYS_SMS_CONF));Map<String, String> map = systemParamLogic.getParamsMap(search);SMSUtil sendUtil = SMSUtil.getPhoneUtil(map);Boolean result = sendUtil.doSendMessage(target, tmpl.getName(), content);if(result == true){error.setErrCode(100188);
}else{
error.setErrCode(100107);
}
}else{
error.setErrCode(100106);
}
}
return error ;
}
@SuppressWarnings("unchecked")
Map<String, Object> map = new HashMap<String, Object>();
map.put("account", Chuanglan_User);
map.put("password", Chuanglan_Pass);
map.put("msg", message);map.put("phone", phone);
//发送http请求
HttpResult result = HttpUtil.sendPost(Chuanglan_Url, JSONArray.toJSONString(map), "UTF-8");
String content = result.getContent();
Object obj = JSON.parse(content);
Map<String, Object> mapResult = (Map<String, Object>) obj;
if (null != mapResult.get("code") && "0".equals(mapResult.get("code").toString())) {
return true;
}
return false;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。