Browse Source

支付链接

詹子聪 5 năm trước cách đây
mục cha
commit
b73fa76951

+ 24 - 22
src/main/java/com/miekir/shibei/controller/api/GoodsController.java

@@ -26,10 +26,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
+import java.util.*;
 
 @Controller
 public class GoodsController {
@@ -288,15 +285,17 @@ public class GoodsController {
     @RequestMapping(value = "/api/getTorrentSecret", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
     @ResponseBody
     public String getTorrentSecret(@RequestHeader HttpHeaders header, @RequestBody Map<String, Object> map) throws IOException {
-        ResponseResult<String> responseResult = new ResponseResult<String>();
+        ResponseResult<Map<String, Object>> responseResult = new ResponseResult<Map<String, Object>>();
         responseResult.setMessage("获取失败");
-        if (map == null || map.get("fileName") == null) {
+        if (map == null || map.get("fileName") == null || map.get("fileUrl") == null) {
             return JSON.toJSONString(responseResult);
         }
 
         String fileName = "";
+        String fileUrl = "";
         try {
             fileName = (String) map.get("fileName");
+            fileUrl = (String) map.get("fileUrl");
         } catch (Exception e) {
             e.printStackTrace();
             return JSON.toJSONString(responseResult);
@@ -311,16 +310,24 @@ public class GoodsController {
             return JSON.toJSONString(responseResult);
         }
 
-        String secret = "";
+        String s = "";
+        String f = "";
+        String u = "";
         String token = header.getFirst("token");
         try {
-            secret = AESTool.encrypt(token+SPLIT_TOKEN_NAME+fileName);
+            s = AESTool.encrypt(token);
+            f = AESTool.encrypt(fileName);
+            u = AESTool.encrypt(fileUrl);
         } catch (Exception exception) {
             exception.printStackTrace();
             return JSON.toJSONString(responseResult);
         }
 
-        responseResult.setContent(secret);
+        Map<String, Object> secretMap = new HashMap<String, Object>();
+        secretMap.put("s", s);
+        secretMap.put("f", f);
+        secretMap.put("u", u);
+        responseResult.setContent(secretMap);
         responseResult.setCode(ResultCode.SUCCESS);
         responseResult.setMessage("操作成功");
         return JSON.toJSONString(responseResult);
@@ -329,25 +336,20 @@ public class GoodsController {
     /**
      * 下载文件
      */
-    private static final String SPLIT_TOKEN_NAME = "`";
     @RequestMapping(value = "/api/torrent", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
-    public ResponseEntity<FileSystemResource> downloadTorrentFile(String s) throws IOException {
+    public ResponseEntity<FileSystemResource> downloadTorrentFile(String s, String f, String u) throws IOException {
         // s是token+fileName的加密
-        if (TextUtils.isEmpty(s)) {
+        if (TextUtils.isEmpty(s) || TextUtils.isEmpty(f) || TextUtils.isEmpty(u)) {
             return null;
         }
 
         String token = null;
         String fileName = null;
+        String fileUrl = null;
         try {
-            String rawString = AESTool.decrypt(s);
-            String[] tokenFileName = rawString.split(SPLIT_TOKEN_NAME);
-            if (tokenFileName.length != 2 || TextUtils.isEmpty(tokenFileName[0]) || TextUtils.isEmpty(tokenFileName[1])) {
-                return null;
-            }
-
-            token = tokenFileName[0];
-            fileName = tokenFileName[1];
+            token = AESTool.decrypt(s);
+            fileName = AESTool.decrypt(f);
+            fileUrl = AESTool.decrypt(u);
         } catch (Exception exception) {
             exception.printStackTrace();
             return null;
@@ -359,14 +361,14 @@ public class GoodsController {
         }
 
         //File file = new File("D:\\a.txt");
-        File file = new File(FileTool.TARGET_DIR_AUTO_TORRENT, fileName);
+        File file = new File(FileTool.TARGET_DIR_AUTO_TORRENT, fileUrl);
         if (!file.exists()) {
             return null;
         }
 
         HttpHeaders headers = new HttpHeaders();
         headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
-        headers.add("Content-Disposition", "attachment; filename=" + file.getName());
+        headers.add("Content-Disposition", "attachment; filename=" + fileName);
         headers.add("Pragma", "no-cache");
         headers.add("Expires", "0");
         //headers.add("Last-Modified", new Date().toString());

+ 1 - 0
src/main/java/com/miekir/shibei/controller/api/UserController.java

@@ -259,6 +259,7 @@ public class UserController {
 
         responseResult.setCode(ResultCode.SUCCESS);
         responseResult.setMessage("操作成功");
+        responseResult.setContent("操作成功");
         return JSON.toJSONString(responseResult);
     }