|
@@ -16,6 +16,7 @@ package com.jfinal.club.reg;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jfinal.aop.Before;
|
|
|
+import com.jfinal.aop.Clear;
|
|
|
import com.jfinal.aop.Inject;
|
|
|
import com.jfinal.club.common.kit.IpKit;
|
|
|
import com.jfinal.club.util.HttpSender;
|
|
@@ -25,6 +26,7 @@ import com.jfinal.kit.StrKit;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
@@ -88,26 +90,22 @@ public class RegController extends Controller {
|
|
|
* @Date 2020/3/16
|
|
|
* @Param []
|
|
|
**/
|
|
|
+ @Clear
|
|
|
public void sendMessage() throws Exception {
|
|
|
- JSONObject object = new JSONObject();
|
|
|
String phone = getPara("phone");
|
|
|
String reg = "^[1](([3|5|8][\\d])|([4][4,5,6,7,8,9])|([6][2,5,6,7])|([7][^9])|([9][1,8,9]))[\\d]{8}$";// 验证手机号
|
|
|
if (!StrKit.isBlank(phone)) {
|
|
|
boolean matches = Pattern.compile(reg).matcher(phone).matches();
|
|
|
if (matches) {
|
|
|
- String s = sendSMS(phone);
|
|
|
- object.put("is", true);
|
|
|
-// object.put("code", s);
|
|
|
- renderJson(object);
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("SMSPhone", phone);
|
|
|
- map.put("SMSCode", s);
|
|
|
- setSessionAttr(phone, map);
|
|
|
+ String msg = sendSMS(phone);
|
|
|
+ if(Objects.equals("OK",msg)){
|
|
|
+ renderJson(Ret.ok("msg","短信发送成功"));
|
|
|
+ }else{
|
|
|
+ renderJson(Ret.fail("msg",msg));
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
- object.put("is", false);
|
|
|
-// object.put("code", 0);
|
|
|
- renderJson(object);
|
|
|
+ renderJson(Ret.fail("msg","手机号码错误!"));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -135,8 +133,14 @@ public class RegController extends Controller {
|
|
|
String paramstring = "{\"code\":\"" + sendCoed + "\"}";
|
|
|
String templatecode = "SMS_180054910";
|
|
|
String str = "你的验证码为:" + sendCoed + ",该验证码5分钟内有效,请勿泄漏于他人。\n";
|
|
|
- boolean fag = HttpSender.sendSms("铁嘴网", templatecode, phone, paramstring);
|
|
|
- return sendCoed;
|
|
|
+ String msg = HttpSender.sendSms("铁嘴网", templatecode, phone, paramstring);
|
|
|
+ if(Objects.equals("OK",msg)){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("SMSPhone", phone);
|
|
|
+ map.put("SMSCode", sendCoed);
|
|
|
+ setSessionAttr(phone, map);
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
}
|
|
|
|
|
|
|