@Log4j
public Result<Map<String, Integer>>getValidateCode(StringdeviceId, Stringtype, Stringmobile) {
Result<Map<String, Integer>>result =new Result<>();
longincr = MemcacheUtil.incr(memcachedClient,mobile + "_mc_count");
System.out.println("验证次数"+incr);
if (incr >= 20) {
//一天中发送验证码过多
result.setResultCode("2");
result.setResultMessage("验证次数过多");
returnresult.setError();
}
//生成6位验证码
String code = (int) ((Math.random() * 9 + 1) * 100000) +"";
System.out.println("验证码"+code+"手机号"+mobile);
//存入缓存中
MemcacheUtil.replace(memcachedClient,mobile +"_mc",code);
System.out.println("缓存中"+MemcacheUtil.get(memcachedClient,mobile+"_mc")+"手机号"+mobile);
//发送验证码
String content = "您的验证码为" +code + ",验证码将在5分钟后失效,届时请重新获取";
String data = "username=123&password=123&gateway=0&extendCode=00&mobile=" +mobile +"&content=" +content;
String url = "http://116.**.**.***:8080/CMS/smssrv/Send.html";
String callback = GetValidateCode.sendPost(url,data);
JSONObject callback_json = JSONObject.fromObject(callback);
String data_ = callback_json.getString("result");
if ("0".equals(data_)) {
//验证码发送成功进行缓存保存验证码
result.setResultCode("0");
returnresult.setSusses();
} else {
//验证码发送失败
result.setResultCode("1");
returnresult.setError();
}
}