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; } }