|
|
@@ -42,27 +42,25 @@ import com.goafanti.user.service.UserService;
|
|
|
@RequestMapping("/open")
|
|
|
public class PublicController extends BaseController {
|
|
|
@Value(value = "${accessKey}")
|
|
|
- private String accessKey = null;
|
|
|
+ private String accessKey = null;
|
|
|
|
|
|
@Value(value = "${accessSecret}")
|
|
|
- private String accessSecret = null;
|
|
|
+ private String accessSecret = null;
|
|
|
|
|
|
@Value(value = "${upload.path}")
|
|
|
- private String uploadPath = null;
|
|
|
+ private String uploadPath = null;
|
|
|
|
|
|
@Value(value = "${upload.private.path}")
|
|
|
- private String uploadPrivatePath = null;
|
|
|
+ private String uploadPrivatePath = null;
|
|
|
|
|
|
@Value(value = "${static.host}")
|
|
|
- private String staticHost = null;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ private String staticHost = null;
|
|
|
+
|
|
|
@Resource
|
|
|
- private UserService userService;
|
|
|
-
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
@Resource
|
|
|
- private AftFileService aftFileService;
|
|
|
+ private AftFileService aftFileService;
|
|
|
|
|
|
/**
|
|
|
* 获取验证码
|
|
|
@@ -79,7 +77,6 @@ public class PublicController extends BaseController {
|
|
|
|
|
|
// 生成随机字串
|
|
|
String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
|
|
|
- System.out.println(verifyCode);
|
|
|
// 存入Shiro会话session
|
|
|
TokenManager.setVal2Session(VerifyCodeUtils.V_CODE, verifyCode.toLowerCase());
|
|
|
// 生成图片
|
|
|
@@ -92,24 +89,36 @@ public class PublicController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 手机验证码
|
|
|
+ *
|
|
|
* @param mobile
|
|
|
- * @param sign 是否用与找回密码
|
|
|
+ * @param sign
|
|
|
+ * 是否用与找回密码
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/getMCode", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
|
- public Result getMcode(String mobile ,boolean sign,Integer type) {
|
|
|
+ public Result getMcode(String mobile, boolean sign, Integer type, String verificationCode) {
|
|
|
Result res = new Result();
|
|
|
- //用于找回密码
|
|
|
- if(sign){
|
|
|
- if(null == userService.selectByMobieAndType(mobile, type)){
|
|
|
- res.getError().add(buildError(ErrorConstants.NON_REGISTER, "该用户未注册!"));
|
|
|
+ // 用于找回密码
|
|
|
+ if (sign) {
|
|
|
+ if (null == userService.selectByMobieAndType(mobile.trim(), type)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!sign) {
|
|
|
+ if (StringUtils.isBlank(verificationCode)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "验证码"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.V_CODE).equals(verificationCode)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "", "验证码"));
|
|
|
return res;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
|
|
|
|| TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
|
|
|
sendMessage(mobile, res);
|
|
|
@@ -118,11 +127,11 @@ public class PublicController extends BaseController {
|
|
|
TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE_TIME);
|
|
|
sendMessage(mobile, res);
|
|
|
} else {
|
|
|
- res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "手机验证码发送频繁"));
|
|
|
+ res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码发送频繁!"));
|
|
|
}
|
|
|
-
|
|
|
- //resetCode
|
|
|
- if(res.getError().isEmpty() && sign){
|
|
|
+
|
|
|
+ // resetCode
|
|
|
+ if (res.getError().isEmpty() && sign) {
|
|
|
String resetCode = UUID.randomUUID().toString();
|
|
|
TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
|
|
|
TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
|
|
|
@@ -169,29 +178,30 @@ public class PublicController extends BaseController {
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 下载图片
|
|
|
+ *
|
|
|
* @param response
|
|
|
* @param path
|
|
|
* @param request
|
|
|
*/
|
|
|
@RequestMapping(value = "/downLoadPicture", method = RequestMethod.GET)
|
|
|
- public Result downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request){
|
|
|
+ public Result downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request) {
|
|
|
Result res = new Result();
|
|
|
- if (path == "" || path == null){
|
|
|
+ if (path == "" || path == null) {
|
|
|
res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "下载文件不存在!"));
|
|
|
return res;
|
|
|
}
|
|
|
- String filename =Long.toString(System.nanoTime())+".jpg";
|
|
|
+ String filename = Long.toString(System.nanoTime()) + ".jpg";
|
|
|
InputStream in = null;
|
|
|
OutputStream out = null;
|
|
|
byte[] buffer = new byte[8 * 1024];
|
|
|
String fileSaveRootPath = "";
|
|
|
try {
|
|
|
- fileSaveRootPath = uploadPrivatePath + path;
|
|
|
- File file = new File(fileSaveRootPath);
|
|
|
- in = new FileInputStream(file);
|
|
|
+ fileSaveRootPath = uploadPrivatePath + path;
|
|
|
+ File file = new File(fileSaveRootPath);
|
|
|
+ in = new FileInputStream(file);
|
|
|
out = response.getOutputStream();
|
|
|
// 设置文件MIME类型
|
|
|
response.setContentType("application/octet-stream");
|
|
|
@@ -219,30 +229,31 @@ public class PublicController extends BaseController {
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 删除图片文件(public图片)
|
|
|
+ *
|
|
|
* @param path
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/deleteUploadPicture", method = RequestMethod.POST)
|
|
|
- public boolean deleteUploadPicture(String path){
|
|
|
- boolean flag = false;
|
|
|
- path = uploadPath+path;
|
|
|
- File file = new File(path);
|
|
|
- // 判断目录或文件是否存在
|
|
|
- if (!file.exists()||!file.isFile()) { // 不存在返回 false
|
|
|
- return flag;
|
|
|
- } else {
|
|
|
- return file.delete();
|
|
|
- }
|
|
|
+ public boolean deleteUploadPicture(String path) {
|
|
|
+ boolean flag = false;
|
|
|
+ path = uploadPath + path;
|
|
|
+ File file = new File(path);
|
|
|
+ // 判断目录或文件是否存在
|
|
|
+ if (!file.exists() || !file.isFile()) { // 不存在返回 false
|
|
|
+ return flag;
|
|
|
+ } else {
|
|
|
+ return file.delete();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取并输出private图片
|
|
|
- */
|
|
|
- @RequestMapping(value = "/writeImage" , method = RequestMethod.GET)
|
|
|
- public void writeImage (HttpServletResponse response, HttpServletRequest request, String path){
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取并输出private图片
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/writeImage", method = RequestMethod.GET)
|
|
|
+ public void writeImage(HttpServletResponse response, HttpServletRequest request, String path) {
|
|
|
try {
|
|
|
String realPath = uploadPrivatePath + path;
|
|
|
PictureUtils.outputImage(response, realPath);
|
|
|
@@ -250,10 +261,10 @@ public class PublicController extends BaseController {
|
|
|
LoggerUtils.fmtError(getClass(), e, "获取图片异常:%s", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 下载文件
|
|
|
+ *
|
|
|
* @param res
|
|
|
* @param fileName
|
|
|
* @param response
|
|
|
@@ -266,32 +277,33 @@ public class PublicController extends BaseController {
|
|
|
Result res = new Result();
|
|
|
return handleDownloadFile(response, fileName, path, res);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 下载模版文件
|
|
|
+ *
|
|
|
* @param response
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/downloadTemplateFile", method = RequestMethod.GET)
|
|
|
- public Result downloadTemplateFile(HttpServletResponse response,String sign){
|
|
|
+ public Result downloadTemplateFile(HttpServletResponse response, String sign) {
|
|
|
Result res = new Result();
|
|
|
String fileName = "";
|
|
|
String path = aftFileService.selectAftFileBySign(sign).getFilePath();
|
|
|
String suffix = path.substring(path.lastIndexOf("."));
|
|
|
- if (sign.equals("patent_prory_statement")){
|
|
|
+ if (sign.equals("patent_prory_statement")) {
|
|
|
fileName = "专利代理委托书模版" + suffix;
|
|
|
} else {
|
|
|
fileName = System.nanoTime() + " ";
|
|
|
}
|
|
|
- if (!StringUtils.isBlank(path)){
|
|
|
+ if (!StringUtils.isBlank(path)) {
|
|
|
return handleDownloadFile(response, fileName, path, res);
|
|
|
} else {
|
|
|
res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "下载文件不存在!"));
|
|
|
return res;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res){
|
|
|
+
|
|
|
+ private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res) {
|
|
|
String fileSaveRootPath = uploadPrivatePath + path;
|
|
|
InputStream in = null;
|
|
|
OutputStream out = null;
|
|
|
@@ -301,7 +313,7 @@ public class PublicController extends BaseController {
|
|
|
in = new FileInputStream(file);
|
|
|
out = response.getOutputStream();
|
|
|
// 设置文件MIME类型
|
|
|
- //response.setContentType("application/octet-stream");
|
|
|
+ // response.setContentType("application/octet-stream");
|
|
|
response.setContentType("multipart/form-data");
|
|
|
fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
|
@@ -328,5 +340,5 @@ public class PublicController extends BaseController {
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|