请求,,发送验证码到手机, 把验证码写到 session
@At("/sendAuth")
@POST
public int sendAuth(@Param("telephone") String phone,
HttpServletRequest request, HttpSession session) {
String authCode = RandomAuthCode.getAuthCode();
int code = 600;
BufferedReader in = null;
String statu;
//session=Mvcs.getActionContext().getRequest().getSession();
try {
statu = SendSMS.send(phone, java.net.URLEncoder.encode(
String.format(SMSContrast.codeorder, authCode), "utf-8"));
// authCode写入session
if (Integer.parseInt(statu) <= 0) {
return 700;
}
session.setAttribute("recommedCode", authCode);
session.setAttribute("recommender", phone);
log.info("send-------------" + request.getRequestedSessionId());
} catch (UnsupportedEncodingException e) {
return 700;
}
return code;
}
前段输入验证码---------$post请求,,
验证接口如下,,,,,,发现从 刚刚session写入的值, 取出的 值为空,,
@At("/action")
@POST
public Map<String, String> saveRecommender(
@Param("recommenderName") String customName, HttpSession session,
@Param("recommenderPhone") String customPhone,
HttpServletRequest request, @Param("barberName") String barberName,
@Param("authCode") String authCode,
@Param("barberPhone") String barberPhone) {
//session=Mvcs.getActionContext().getRequest().getSession();
Map<String, String> map = new HashMap<String, String>();
// 检测验证码是否正确
String code = (String) session.getAttribute("recommedCode");
log.info("send---code----------" + request.getRequestedSessionId());
if (!code.equals(authCode)) {
map.put("code", "803");
return map;
}
// 校验手机号码
if (Strings.isBlank(customPhone)) {
map.put("code", "703");
return map;// 无效数据
}