|
@@ -1,21 +1,15 @@
|
|
|
-package com.miaxis.system.controller.common;
|
|
|
+package com.miaxis.system.service.impl;
|
|
|
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.core.domain.ResponseEnum;
|
|
|
import com.miaxis.common.core.domain.entity.SysUser;
|
|
|
import com.miaxis.common.sms.Client;
|
|
|
-import com.miaxis.common.utils.SecurityUtils;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiImplicitParam;
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
+import com.miaxis.system.service.ISmsService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.HashMap;
|
|
@@ -26,20 +20,20 @@ import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
+ * 短信服务层接口实现
|
|
|
* @Author wwl
|
|
|
* @Date 2020/12/23
|
|
|
* @Version 1.0
|
|
|
*/
|
|
|
-@RestController
|
|
|
-@RequestMapping("/user/info")
|
|
|
-@Api(tags={"【短信服务】Controller"})
|
|
|
-public class smsController {
|
|
|
+@Service
|
|
|
+public class SmsServiceImpl implements ISmsService {
|
|
|
|
|
|
private final String MOBILE_REGEX = "^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$";//手机号码验证
|
|
|
private final Integer SMS_MAX_COUNT = 500 ;//每天系统发送最大次数(预留)
|
|
|
private final Integer MAX_COUNT = 5 ;//每个手机号验证发送最大次数
|
|
|
private final long SEND_INTERVAL = 2 ;//发送间隔时间
|
|
|
|
|
|
+
|
|
|
@Value("${sms_user_name}")
|
|
|
private String smsUserName;//用户名
|
|
|
|
|
@@ -49,20 +43,15 @@ public class smsController {
|
|
|
@Autowired
|
|
|
private RedisTemplate redisTemplate;//redis模板引擎
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 获取短信验证码
|
|
|
+ * 发送短信验证码
|
|
|
+ * @param user
|
|
|
+ * @param type
|
|
|
+ * @param phone
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation("获取短信验证码")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "type",value = "login:用户登录验证码、modify:修改手机验证码" ,dataType = "String",required = true),
|
|
|
- @ApiImplicitParam(name = "phone", value = "手机号码", required = true, dataType = "String")
|
|
|
- })
|
|
|
- @PostMapping(value = "/sendVerificationCode")
|
|
|
- public Response sendVerificationCode(String type,String phone){
|
|
|
- //获取当前用户
|
|
|
- SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
+ @Override
|
|
|
+ public Response sendVerificationCode(SysUser user, String type, String phone) {
|
|
|
//字符编码
|
|
|
String charset = "UTF-8";
|
|
|
|
|
@@ -85,7 +74,7 @@ public class smsController {
|
|
|
*/
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
if (type.equals("login")){
|
|
|
- map.put("keyPrefix",Constants.SMS_LOGIN_CODE);
|
|
|
+ map.put("keyPrefix", Constants.SMS_LOGIN_CODE);
|
|
|
map.put("verificationCount",Constants.SMS_LOGIN_CODE_COUNT);
|
|
|
}
|
|
|
if (type.equals("modify")){
|
|
@@ -103,7 +92,7 @@ public class smsController {
|
|
|
}
|
|
|
|
|
|
// 生成验证码
|
|
|
- String code="";
|
|
|
+ String code="";
|
|
|
for (int i=0;i<6;i++){
|
|
|
code += new Random().nextInt(10);
|
|
|
}
|
|
@@ -157,6 +146,7 @@ public class smsController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 手机号验证
|
|
|
* @param mobile
|
|
@@ -213,5 +203,4 @@ public class smsController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|