xiziwen 1 week ago
parent
commit
600a07b36b
1 changed files with 19 additions and 2 deletions
  1. 19 2
      middleware/check_cygx_auth.go

+ 19 - 2
middleware/check_cygx_auth.go

@@ -3,9 +3,11 @@ package middleware
 import (
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/controller/response"
+	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
+	"strconv"
 )
 
 // CheckCygxAuth 如果带thirdCode就可以看,如果有权限也给其他权限
@@ -16,8 +18,23 @@ func CheckCygxAuth() gin.HandlerFunc {
 		userInfo := user.GetInfoByClaims(c)
 
 		thirdCodeEncrypt := c.Request.Header.Get("thirdCode")
-		thirdCode := utils.DesBase64Encrypt([]byte(thirdCodeEncrypt))
-		if len(thirdCode) == 0 {
+
+
+		if thirdCodeEncrypt != "" {
+			thirdCode := utils.DesBase64Decrypt([]byte(thirdCodeEncrypt))
+			userId, err := strconv.Atoi(string(thirdCode))
+			if err != nil {
+				response.FailMsg("参数错误", "参数错误", c)
+				c.Abort()
+				return
+			}
+			_, err = wx_user.GetByUserId(userId)
+			if err != nil {
+				response.FailMsg("获取用户信息失败", "获取用户信息失败", c)
+				c.Abort()
+				return
+			}
+		} else {
 			ok, checkInfo, _, err := company.CheckBaseFiccPermission(userInfo.CompanyID, int(userInfo.UserID))
 			if err != nil {
 				response.FailMsg("用户权限验证失败", "CheckBaseAuth-用户权限验证失败"+err.Error(), c)