|
@@ -1,6 +1,7 @@
|
|
|
package com.rf.fileCrack.file.rest;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.log.Log;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.rf.fileCrack.base.rest.BaseController;
|
|
|
import com.rf.fileCrack.file.dao.model.FileEntity;
|
|
@@ -10,6 +11,7 @@ import com.rf.fileCrack.utils.FileUtil;
|
|
|
import com.rf.fileCrack.utils.Result;
|
|
|
import com.rf.fileCrack.utils.SendEmail;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.http.HttpEntity;
|
|
@@ -18,6 +20,7 @@ import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -43,6 +46,7 @@ import static com.rf.fileCrack.utils.EmailUtil.checkEmail;
|
|
|
*/
|
|
|
|
|
|
@Controller
|
|
|
+@Slf4j
|
|
|
@RequestMapping("/file")
|
|
|
public class FileController extends BaseController {
|
|
|
|
|
@@ -83,11 +87,42 @@ public class FileController extends BaseController {
|
|
|
return fail("文件上传失败");
|
|
|
}
|
|
|
try {
|
|
|
- HttpResponse response = HttpClient(fileEntity.getFilePath(),fileEntity.getId(),fileEntity.getCallWord());
|
|
|
- if (response.getStatusLine().getStatusCode() == 200){
|
|
|
+ String data = HttpClient(fileEntity.getFilePath(),fileEntity.getId(),fileEntity.getCallWord());
|
|
|
+ if (data != null){
|
|
|
fileEntity.setFileStatus("2");
|
|
|
fileEntity.setUpdateTime(DateUtil.now());
|
|
|
this.fileService.save(fileEntity);
|
|
|
+ JSONObject jsonObjectData = JSONObject.parseObject(data);
|
|
|
+ if (jsonObjectData.getString("msg").equals("文件已破解")){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonObjectData.getString("data"));
|
|
|
+ fileEntity.setFileStatus("3");
|
|
|
+ fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ fileEntity.setPassword(jsonObject.getString("password"));
|
|
|
+ fileEntity = this.fileService.save(fileEntity);
|
|
|
+ //根据邮箱查询用户信息
|
|
|
+ email = fileEntity.getEmail();
|
|
|
+ if (email != null) {
|
|
|
+ SendEmail sendEmail = new SendEmail();
|
|
|
+ //破解密码
|
|
|
+ sendEmail.setPassword(fileEntity.getPassword());
|
|
|
+ //破解的文件名
|
|
|
+ String[] fileNames = fileEntity.getFilePath().split("-=-");
|
|
|
+ fileName = fileNames[fileNames.length - 1];
|
|
|
+ sendEmail.setFileName(fileName);
|
|
|
+
|
|
|
+ //设置要发送的邮箱
|
|
|
+ sendEmail.setReceiveMailAccount(email);
|
|
|
+ try {
|
|
|
+ sendEmail.Send();
|
|
|
+ fileEntity.setFileStatus("4");
|
|
|
+ fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ this.fileService.save(fileEntity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
//WebSocketServer.sendInfo(fileEntity.getId());
|
|
|
} catch (Exception e) {
|
|
@@ -117,7 +152,19 @@ public class FileController extends BaseController {
|
|
|
}
|
|
|
return success(null,"下载成功");
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 修改文件状态
|
|
|
+ */
|
|
|
+ /*@ApiOperation(value = "效验邮箱",notes = "参数包括:fileId:唯一标识,fileStatus:文件状态码 2--开始解密;3--解密完成。示例:{\"fileId\":\"8af1788593b4d21b0193b4d2281a0000\",\"fileStatus\":\"2\"}")
|
|
|
+ @PostMapping("/effectEmail")
|
|
|
+ @ResponseBody
|
|
|
+ public Result effectEmail(String email) {
|
|
|
+ log.info("效验邮箱:{}",email);
|
|
|
+ if (!checkEmail(email)){
|
|
|
+ return fail("邮箱无效,请重新填写有效邮箱!");
|
|
|
+ };
|
|
|
+ return success(null,"修改成功");
|
|
|
+ }*/
|
|
|
/**
|
|
|
* 修改文件状态
|
|
|
*/
|
|
@@ -158,7 +205,7 @@ public class FileController extends BaseController {
|
|
|
String fileId = jsonObject.getString("fileId");
|
|
|
FileEntity fileEntity = this.fileService.findById(fileId);
|
|
|
if (fileEntity == null){
|
|
|
- return failBadRequest(null, "uuid错误!");
|
|
|
+ return success(null, "uuid错误!");
|
|
|
}
|
|
|
fileEntity.setPassword(password);
|
|
|
fileEntity.setUpdateTime(DateUtil.now());
|
|
@@ -189,16 +236,21 @@ public class FileController extends BaseController {
|
|
|
return success(null,"修改成功");
|
|
|
}
|
|
|
|
|
|
- public static HttpResponse HttpClient(String filePath, String fileId, String callWord) {
|
|
|
+ public static String HttpClient(String filePath, String fileId, String callWord) {
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
- HttpPost httpPost = new HttpPost("http://10.113.248.201:9999/api/uploadfile/?file_uuid="+fileId+"&tips_word="+callWord);
|
|
|
+ HttpPost httpPost = new HttpPost("http://123.57.18.29:8061/api/uploadfile/?file_uuid="+fileId+"&tips_word="+callWord);
|
|
|
+ httpPost.setHeader("Authorization", "Basic Y3N6eDUwMTp5b3VndWVzczUwMQ==");
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
builder.addBinaryBody("file", new File(filePath));
|
|
|
HttpEntity multipart = builder.build();
|
|
|
httpPost.setEntity(multipart);
|
|
|
HttpResponse response = null;
|
|
|
+ String responseData = null;
|
|
|
try {
|
|
|
response = httpclient.execute(httpPost);
|
|
|
+ if (response.getStatusLine().getStatusCode() == 200){
|
|
|
+ responseData = EntityUtils.toString(response.getEntity());
|
|
|
+ }
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
@@ -208,7 +260,7 @@ public class FileController extends BaseController {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- return response;
|
|
|
+ return responseData;
|
|
|
}
|
|
|
|
|
|
}
|