huliguo
2025-08-08 749570394745ae95ee65605eadb42800f42fa20a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.linghu.service.impl;
 
import com.linghu.model.common.ResponseResult;
import com.linghu.model.dto.TokenRequest;
import com.linghu.service.AuthService;
import com.linghu.utils.OpenCryptUtil;
import org.springframework.stereotype.Service;
 
@Service
public class AuthServiceImpl implements AuthService {
 
    @Override
    public ResponseResult<?> parseTokenAuth(TokenRequest tokenRequest) {
        String token = tokenRequest.getToken();
        if (token == null || token.isEmpty()) {
            return ResponseResult.success("token为空");
        }
 
        // 解密token
        OpenCryptUtil openCryptUtil = new OpenCryptUtil();
        String decrypt = openCryptUtil.decrypt(token);
        //转换为对象
        try {
 
            return ResponseResult.success(decrypt);
        } catch (Exception e) {
            return ResponseResult.error(e.getMessage());
        }
    }
 
    /**
     * 清理JSON字符串,处理可能的格式问题
     * @param jsonString 原始JSON字符串
     * @return 清理后的JSON字符串
     */
    private String cleanJsonString(String jsonString) {
        if (jsonString == null) {
            return null;
        }
 
        // 移除字符串开头和结尾可能存在的引号
        String result = jsonString.trim();
        if (result.startsWith("\"") && result.endsWith("\"") && result.length() > 1) {
            result = result.substring(1, result.length() - 1);
        }
 
        // 处理转义的引号
        result = result.replace("\\\"", "\"");
 
        // 处理换行符和其他转义字符
        result = result.replace("\\n", "\n")
                .replace("\\r", "\r")
                .replace("\\t", "\t");
 
        return result;
    }
}