|
@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -25,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.UUID;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@@ -126,7 +128,7 @@ public class PersonInfoApiController {
|
|
|
|
|
|
messageResult = SMSUtil.send(personInfo.getPhone(), "SMS_49390047", verifyCodeJSON.toString());
|
|
messageResult = SMSUtil.send(personInfo.getPhone(), "SMS_49390047", verifyCodeJSON.toString());
|
|
|
|
|
|
- //设置当前用户的验证码,60秒后过期
|
|
|
|
|
|
+ //设置当前用户的验证码,1分钟内有效
|
|
valueOperations.set(key, verifyCode, 60000, TimeUnit.SECONDS);
|
|
valueOperations.set(key, verifyCode, 60000, TimeUnit.SECONDS);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -166,17 +168,70 @@ public class PersonInfoApiController {
|
|
return messageResult;
|
|
return messageResult;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @PostMapping("validateCode")
|
|
|
|
+ @ApiOperation(value="验证短信验证码")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
|
|
|
|
+ @ApiImplicitParam(name="verifyCode",value = "验证码",required = true,paramType = "form")
|
|
|
|
+ })
|
|
|
|
+ public MessageResult<String> validateCode(Long personId,String verifyCode){
|
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ String smsKey = "SMS_" + personId;
|
|
|
|
+
|
|
|
|
+ String beforeVerifyCode = (String)valueOperations.get(smsKey);
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isEmpty(beforeVerifyCode)) {
|
|
|
|
+ throw new Exception("验证码已过期!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!beforeVerifyCode.equals(verifyCode)){
|
|
|
|
+ throw new Exception("验证码错误!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String tokenKey = "token_" + personId;
|
|
|
|
+ String tokenValue = UUID.randomUUID().toString();
|
|
|
|
+
|
|
|
|
+ //token有效时间30分钟
|
|
|
|
+ valueOperations.set(tokenKey,tokenValue,30, TimeUnit.MINUTES);
|
|
|
|
+
|
|
|
|
+ messageResult.setData(tokenValue);
|
|
|
|
+ messageResult.setResult(true);
|
|
|
|
+ messageResult.setCode(200);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex){
|
|
|
|
+ messageResult.setResult(false);
|
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return messageResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
@PostMapping("save")
|
|
@PostMapping("save")
|
|
@ApiOperation(value="保存人员信息")
|
|
@ApiOperation(value="保存人员信息")
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
|
|
@ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
|
|
@ApiImplicitParam(name="openId",value = "微信openId",required = true,paramType = "form"),
|
|
@ApiImplicitParam(name="openId",value = "微信openId",required = true,paramType = "form"),
|
|
- @ApiImplicitParam(name="faceImageUrl",value = "照片地址",required = true,paramType = "form")
|
|
|
|
|
|
+ @ApiImplicitParam(name="faceImageUrl",value = "照片地址",required = true,paramType = "form"),
|
|
|
|
+ @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form")
|
|
})
|
|
})
|
|
- public MessageResult<String> save(Long personId,String openId,String faceImageUrl){
|
|
|
|
- MessageResult<String> messageResult = new MessageResult<>();
|
|
|
|
|
|
+ public MessageResult<PersonInfo> save(Long personId,String openId,String faceImageUrl,String token){
|
|
|
|
+ MessageResult<PersonInfo> messageResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ String tokenKey = "token_" + personId;
|
|
|
|
+
|
|
|
|
+ String beforeToken = (String)valueOperations.get(tokenKey);
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isEmpty(beforeToken)) {
|
|
|
|
+ throw new Exception("操作已超时!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!beforeToken.equals(token)){
|
|
|
|
+ throw new Exception("无效请求!");
|
|
|
|
+ }
|
|
|
|
+
|
|
PersonInfo personInfo = personInfoService.get(personId);
|
|
PersonInfo personInfo = personInfoService.get(personId);
|
|
|
|
|
|
if (personInfo==null){
|
|
if (personInfo==null){
|
|
@@ -190,6 +245,10 @@ public class PersonInfoApiController {
|
|
|
|
|
|
personInfoService.update(personInfo);
|
|
personInfoService.update(personInfo);
|
|
|
|
|
|
|
|
+ //todo 同步终端
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ messageResult.setData(personInfo);
|
|
messageResult.setResult(true);
|
|
messageResult.setResult(true);
|
|
messageResult.setCode(200);
|
|
messageResult.setCode(200);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|