|
|
@@ -94,19 +94,10 @@ public class WeChatController {
|
|
|
@Operation(summary = "获取用户信息", description = "根据 token 返回当前用户信息(支持 Authorization/X-Token/token)")
|
|
|
@PostMapping(path = "/user_info", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public R<?> getUserInfo(@RequestBody(required = false) Map<String, String> body, HttpServletRequest request) {
|
|
|
- // 使用拦截器放入的 currentUserId(AuthInterceptor 已验证 X-Token)
|
|
|
- Object attr = request.getAttribute("currentUserId");
|
|
|
- Long userId = null;
|
|
|
-
|
|
|
- if (attr instanceof Long) {
|
|
|
- userId = (Long) attr;
|
|
|
- } else if (attr instanceof Integer) {
|
|
|
- // 有时框架可能将数字解析为 Integer
|
|
|
- userId = ((Integer) attr).longValue();
|
|
|
- }
|
|
|
-
|
|
|
- // 如果拦截器没有提供 userId,则401
|
|
|
- if (userId == null) {
|
|
|
+ Long userId;
|
|
|
+ try {
|
|
|
+ userId = work.baiyun.chronicdiseaseapp.util.SecurityUtils.getCurrentUserId();
|
|
|
+ } catch (work.baiyun.chronicdiseaseapp.exception.CustomException e) {
|
|
|
return R.fail(401, "No valid userId");
|
|
|
}
|
|
|
|
|
|
@@ -133,19 +124,10 @@ public class WeChatController {
|
|
|
@PostMapping(path = "/update_user_info", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public R<?> updateUserInfo(@RequestBody(required = false) work.baiyun.chronicdiseaseapp.model.vo.UpdateUserInfoRequest req,
|
|
|
HttpServletRequest request) {
|
|
|
- // 使用拦截器放入的 currentUserId(AuthInterceptor 已验证 X-Token)
|
|
|
- Object attr = request.getAttribute("currentUserId");
|
|
|
- Long userId = null;
|
|
|
-
|
|
|
- if (attr instanceof Long) {
|
|
|
- userId = (Long) attr;
|
|
|
- } else if (attr instanceof Integer) {
|
|
|
- // 有时框架可能将数字解析为 Integer
|
|
|
- userId = ((Integer) attr).longValue();
|
|
|
- }
|
|
|
-
|
|
|
- // 如果拦截器没有提供 userId,则401
|
|
|
- if (userId == null) {
|
|
|
+ Long userId;
|
|
|
+ try {
|
|
|
+ userId = work.baiyun.chronicdiseaseapp.util.SecurityUtils.getCurrentUserId();
|
|
|
+ } catch (work.baiyun.chronicdiseaseapp.exception.CustomException e) {
|
|
|
return R.fail(401, "No valid userId");
|
|
|
}
|
|
|
|