From fa668c325f2dac348fb9f80c0c6c679f9ce1e41b Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期二, 10 三月 2026 18:28:17 +0800
Subject: [PATCH] 小程序 接口开发
---
server/dmmall_service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java | 28 ++++++++++++++++++++++++++--
1 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/server/dmmall_service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java b/server/dmmall_service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
index 016c782..f6978ea 100644
--- a/server/dmmall_service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
+++ b/server/dmmall_service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
@@ -1,10 +1,13 @@
package com.doumee.config.Jwt;
+import com.alibaba.fastjson.JSONObject;
import com.doumee.config.annotation.LoginRequired;
import com.doumee.config.annotation.LoginShopRequired;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.utils.Constants;
+import com.doumee.dao.business.model.Member;
+import com.doumee.dao.business.model.Shop;
import io.jsonwebtoken.JwtException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -20,7 +23,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.lang.reflect.Method;
+import java.util.Objects;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@@ -103,14 +106,26 @@
if(StringUtils.isBlank(tokenRedis)){
throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
}
+ Member member = JSONObject.parseObject(tokenRedis, Member.class);
+ if(Objects.isNull(member)||StringUtils.isBlank(member.getOpenId())){
+ throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
+ }
+ String openid = member.getOpenId();
Integer memberId = getTokenId(token);
Integer isDeleted = dao.queryForObject(" select COALESCE(ISDELETED,0) from Member where id = ?", Integer.class, memberId);
if(isDeleted== Constants.ONE){
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛宸插垹闄�,璇疯仈绯荤鐞嗗憳");
}
Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0) from Member where id = ?", Integer.class, memberId);
- if(isForbidden== Constants.ONE){
+ if(isForbidden == Constants.ONE){
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛宸茬鐢�,璇疯仈绯荤鐞嗗憳");
+ }
+ if(isForbidden == Constants.TWO){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛宸叉敞閿�,璇疯仈绯荤鐞嗗憳");
+ }
+ String dbOpenid = dao.queryForObject(" select ifnull(open_id,'') from Member where id = ?", String.class, memberId);
+ if(StringUtils.isBlank(dbOpenid)||!openid.equals(dbOpenid)){
+ throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�");
}
Integer count = dao.queryForObject("select count(1) from Member where id = ?", Integer.class, memberId);
if (count != null && count > 0) {
@@ -135,6 +150,11 @@
if(StringUtils.isBlank(tokenRedis)){
throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
}
+ Shop shop = JSONObject.parseObject(tokenRedis, Shop.class);
+ if(Objects.isNull(shop)||StringUtils.isBlank(shop.getOpenId())){
+ throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
+ }
+ String openid = shop.getOpenId();
Integer shopId = getTokenId(token);
Integer isDeleted = dao.queryForObject(" select COALESCE(ISDELETED,0) from shop where id = ?", Integer.class, shopId);
if(isDeleted== Constants.ONE){
@@ -144,6 +164,10 @@
if(isForbidden== Constants.ONE){
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛宸茬鐢�,璇疯仈绯荤鐞嗗憳");
}
+ String dbOpenid = dao.queryForObject(" select ifnull(open_id,'') from shop where id = ?", String.class, shopId);
+ if(StringUtils.isBlank(dbOpenid)||!openid.equals(dbOpenid)){
+ throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�");
+ }
Integer count = dao.queryForObject("select count(1) from shop where id = ?", Integer.class, shopId);
if (count != null && count > 0) {
request.setAttribute(JwtTokenUtil.ShopId_Name, shopId);
--
Gitblit v1.9.3