/**
* 订单查询发送验证码
* @param request
* @param response
* @return
*/
@RequestMapping(value="/sendCode",method={RequestMethod.POST,RequestMethod.GET})
public String sendCode(HttpServletRequest request,HttpServletResponse response){
HttpSession session = request.getSession();
String ret="";
String o_tel = request.getParameter("o_tel");//获取前端传送过来的电话号码
if(o_tel!=null&&o_tel!=""){
int Random = (int) ((Math.random()*9+1)*1000);//随机生成的4位数(验证码)
String mes = Random+"(用于测试的验证码,两分钟内有效)【学而思博客】";//需在短信中显示的文字信息描述
ApiSendMobile asm = new ApiSendMobile();
String msg = asm.sendSM(o_tel, mes);//发送短信
if("发送成功".equals(msg)){
ret = "{\"msg\":\"SUCCESS\"}";
//把验证码与电话号码存入session中,并设置120秒有效期限
session.setAttribute("code", Random);
session.setAttribute("tel", o_tel);
session.setMaxInactiveInterval(2*60);
}else {
ret = "{\"msg\":\"ERROR\"}";
}
}else{
ret = "{\"msg\":\"ERROR\"}";
}
response.setContentType("application/json;charset=UTF-8");
PrintWriter writer = null;
try {
writer = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
writer.write(ret);//推送回前端
return null;
}