|
@@ -80,8 +80,8 @@ public class PersonInfoApiController {
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name="openId",value = "微信openId",required = true,paramType = "form")
|
|
|
})
|
|
|
- public MessageResult<PersonInfo> findByOpenId(String openId){
|
|
|
- MessageResult<PersonInfo> messageResult = new MessageResult<>();
|
|
|
+ public MessageResult<Map> findByOpenId(String openId){
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
PersonInfo personInfo = personInfoService.findByOpenId(openId);
|
|
@@ -90,7 +90,13 @@ public class PersonInfoApiController {
|
|
|
throw new Exception("当前用户不存在!");
|
|
|
}
|
|
|
|
|
|
- messageResult.setData(personInfo);
|
|
|
+ Map<String,Object> dataMap = new HashMap<String, Object>();
|
|
|
+ String token = createToken(personInfo.getId());
|
|
|
+
|
|
|
+ dataMap.put("person",personInfo);
|
|
|
+ dataMap.put("token", token);
|
|
|
+
|
|
|
+ messageResult.setData(dataMap);
|
|
|
messageResult.setResult(true);
|
|
|
messageResult.setCode(200);
|
|
|
}
|
|
@@ -128,8 +134,8 @@ public class PersonInfoApiController {
|
|
|
|
|
|
messageResult = SMSUtil.send(personInfo.getPhone(), "SMS_49390047", verifyCodeJSON.toString());
|
|
|
|
|
|
- //设置当前用户的验证码,1分钟内有效
|
|
|
- valueOperations.set(key, verifyCode, 60000, TimeUnit.SECONDS);
|
|
|
+ //设置当前用户的验证码,5分钟内有效
|
|
|
+ valueOperations.set(key, verifyCode, 5, TimeUnit.MINUTES);
|
|
|
}
|
|
|
|
|
|
messageResult.setResult(true);
|
|
@@ -143,66 +149,88 @@ public class PersonInfoApiController {
|
|
|
return messageResult;
|
|
|
}
|
|
|
|
|
|
- @PostMapping("upload")
|
|
|
- @ApiOperation(value="人员照片上传")
|
|
|
+ @PostMapping("validateCode")
|
|
|
+ @ApiOperation(value="验证短信验证码")
|
|
|
@ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name="photoName",value = "照片名称",required = true,paramType = "form"),
|
|
|
- @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file")
|
|
|
+ @ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="verifyCode",value = "验证码",required = true,paramType = "form")
|
|
|
})
|
|
|
- public MessageResult<String> upload(String photoName, MultipartFile photoFile){
|
|
|
+ public MessageResult<String> validateCode(Long personId,String verifyCode){
|
|
|
MessageResult<String> messageResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
- String retFileUrl = OSSUtil.upload(ossConfig,"/person",photoName,photoFile.getInputStream());
|
|
|
+ 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 token = createToken(personId);
|
|
|
+
|
|
|
+ messageResult.setData(token);
|
|
|
messageResult.setResult(true);
|
|
|
- messageResult.setData(retFileUrl);
|
|
|
messageResult.setCode(200);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e.getMessage(),e);
|
|
|
-
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
messageResult.setResult(false);
|
|
|
- messageResult.setMessage(e.getMessage());
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
}
|
|
|
|
|
|
return messageResult;
|
|
|
}
|
|
|
|
|
|
- @PostMapping("validateCode")
|
|
|
- @ApiOperation(value="验证短信验证码")
|
|
|
+ private String createToken(Long personId) {
|
|
|
+ String key = "token_" + personId;
|
|
|
+ String token = UUID.randomUUID().toString();
|
|
|
+
|
|
|
+ //token有效时间2小时
|
|
|
+ valueOperations.set(key,token,30, TimeUnit.MINUTES);
|
|
|
+
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("upload")
|
|
|
+ @ApiOperation(value="人员照片上传")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
|
|
|
- @ApiImplicitParam(name="verifyCode",value = "验证码",required = true,paramType = "form")
|
|
|
+ @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="photoName",value = "照片名称",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file")
|
|
|
})
|
|
|
- public MessageResult<String> validateCode(Long personId,String verifyCode){
|
|
|
+ public MessageResult<String> upload(
|
|
|
+ Long personId,String token,
|
|
|
+ String photoName, MultipartFile photoFile){
|
|
|
MessageResult<String> messageResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
- String smsKey = "SMS_" + personId;
|
|
|
+ String tokenKey = "token_" + personId;
|
|
|
|
|
|
- String beforeVerifyCode = (String)valueOperations.get(smsKey);
|
|
|
+ String beforeToken = (String)valueOperations.get(tokenKey);
|
|
|
|
|
|
- if(StringUtils.isEmpty(beforeVerifyCode)) {
|
|
|
- throw new Exception("验证码已过期!");
|
|
|
+ if(StringUtils.isEmpty(beforeToken)) {
|
|
|
+ throw new Exception("操作已超时!");
|
|
|
}
|
|
|
|
|
|
- if (!beforeVerifyCode.equals(verifyCode)){
|
|
|
- throw new Exception("验证码错误!");
|
|
|
+ if (!beforeToken.equals(token)){
|
|
|
+ throw new Exception("无效请求!");
|
|
|
}
|
|
|
|
|
|
- String tokenKey = "token_" + personId;
|
|
|
- String tokenValue = UUID.randomUUID().toString();
|
|
|
-
|
|
|
- //token有效时间30分钟
|
|
|
- valueOperations.set(tokenKey,tokenValue,30, TimeUnit.MINUTES);
|
|
|
+ String retFileUrl = OSSUtil.upload(ossConfig,"/person",photoName,photoFile.getInputStream());
|
|
|
|
|
|
- messageResult.setData(tokenValue);
|
|
|
messageResult.setResult(true);
|
|
|
+ messageResult.setData(retFileUrl);
|
|
|
messageResult.setCode(200);
|
|
|
- }
|
|
|
- catch (Exception ex){
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+
|
|
|
messageResult.setResult(false);
|
|
|
- messageResult.setMessage(ex.getMessage());
|
|
|
+ messageResult.setMessage(e.getMessage());
|
|
|
}
|
|
|
|
|
|
return messageResult;
|
|
@@ -260,4 +288,6 @@ public class PersonInfoApiController {
|
|
|
|
|
|
return messageResult;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|