1
This commit is contained in:
@@ -97,6 +97,22 @@ public class TencentDocController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取用户信息接口
|
||||
*/
|
||||
@GetMapping("/testUserInfo")
|
||||
public AjaxResult testUserInfo() {
|
||||
try {
|
||||
String token = tencentDocTokenService.getValidAccessToken();
|
||||
JSONObject userInfo = tencentDocService.getUserInfo(token);
|
||||
log.info("获取用户信息成功: {}", userInfo);
|
||||
return AjaxResult.success("获取用户信息成功", userInfo);
|
||||
} catch (Exception e) {
|
||||
log.error("测试获取用户信息失败", e);
|
||||
return AjaxResult.error("测试失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前token状态
|
||||
*/
|
||||
|
||||
@@ -97,5 +97,13 @@ public interface ITencentDocService {
|
||||
* @return 工作表列表
|
||||
*/
|
||||
JSONObject getSheetList(String accessToken, String fileId);
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
* @return 用户信息
|
||||
*/
|
||||
JSONObject getUserInfo(String accessToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,5 +219,15 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
||||
throw new RuntimeException("获取工作表列表失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getUserInfo(String accessToken) {
|
||||
try {
|
||||
return TencentDocApiUtil.getUserInfo(accessToken);
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户信息失败", e);
|
||||
throw new RuntimeException("获取用户信息失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -351,5 +351,17 @@ public class TencentDocApiUtil {
|
||||
String apiUrl = String.format("%s/files/%s/sheets", apiBaseUrl, fileId);
|
||||
return callApi(accessToken, apiUrl, "GET", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
* @return 用户信息
|
||||
*/
|
||||
public static JSONObject getUserInfo(String accessToken) {
|
||||
// 腾讯文档用户信息接口:https://docs.qq.com/open/document/app/oauth2/userinfo.html
|
||||
String apiUrl = "https://docs.qq.com/oauth/v2/userinfo";
|
||||
return callApi(accessToken, apiUrl, "GET", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user