Răsfoiți Sursa

Merge branch 'hotfix/v4.9.6.1_ws' of qmx/jy into hotfix/v4.9.6.1

wangshan 1 an în urmă
părinte
comite
ebcac96fb2
2 a modificat fișierele cu 48 adăugiri și 38 ștergeri
  1. 23 5
      src/jfw/front/shorturl.go
  2. 25 33
      src/jfw/modules/app/src/app/front/shorturl.go

+ 23 - 5
src/jfw/front/shorturl.go

@@ -4,7 +4,7 @@ import (
 	"database/sql"
 	"errors"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"jy/src/jfw/config"
 	"jy/src/jfw/wx"
 	"log"
@@ -171,25 +171,43 @@ func (s *Short) LoginCommon(sess map[string]interface{}, stype, id string, bm bo
 			return s.Render("/pc/detail/biddetail_login.html", &s.T)
 		}
 	} else if userId != "" && strings.Contains(s.Request.RequestURI, "article") {
+		mobileHtmlKey := "jy_mobile_index_wx"
 		var loginPageInfo = func() (body []byte) {
 			// 获取页面内容
 			mobileUrl := fmt.Sprintf("%s%s", config.Sysconfig["webdomain"].(string), "/jy_mobile/index.html")
-			resp, err := http.Get(mobileUrl)
 			log.Println("article --- mobileUrl :", mobileUrl)
+			req, err := http.NewRequest("GET", mobileUrl, nil)
 			if err != nil {
-				http.Error(s.ResponseWriter, "Failed to fetch page", http.StatusInternalServerError)
+				log.Println(s.ResponseWriter, "Failed to fetch page", http.StatusInternalServerError)
+				return
+			}
+			req.Header.Set("X-Forwarded-For", util.GetIp(s.Request))
+			client := &http.Client{}
+			// 使用 Do 方法处理请求
+			resp, err := client.Do(req)
+			if err != nil {
+				log.Println(s.ResponseWriter, "Failed to create client", http.StatusInternalServerError)
 				return
 			}
 			defer resp.Body.Close()
-			body, err = ioutil.ReadAll(resp.Body)
+			body, err = io.ReadAll(resp.Body)
 			if err != nil {
-				http.Error(s.ResponseWriter, "Failed to read response body", http.StatusInternalServerError)
+				log.Println(s.ResponseWriter, "Failed to read response body", http.StatusInternalServerError)
 				return
 			}
+			err = redis.PutBytes(redisLimitation, mobileHtmlKey, &body, 3*24*60*60)
+			if err != nil {
+				log.Println("mobile html redis cache err :", err.Error())
+			}
 			return
 		}
 		// 将页面内容返回给前端
 		s.ResponseWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
+		body, err := redis.GetBytes(redisLimitation, mobileHtmlKey)
+		if err == nil && body != nil && len(*body) > 0 {
+			s.ResponseWriter.Write(*body)
+			return nil
+		}
 		s.ResponseWriter.Write(loginPageInfo())
 		return nil
 	}

+ 25 - 33
src/jfw/modules/app/src/app/front/shorturl.go

@@ -4,7 +4,7 @@ import (
 	"database/sql"
 	"errors"
 	"fmt"
-	"io/ioutil"
+	"io"
 	utils "jy/src/jfw/modules/app/src/app/jyutil"
 	"jy/src/jfw/modules/app/src/jfw/config"
 	"net/http"
@@ -90,7 +90,7 @@ func (s *Short) Article(contentType, stype, id string) error {
 	//if userId == "" {
 	//	return s.Redirect("/jyapp/free/swordfish/about", 302)
 	//}
-	disWord := s.GetString("disWord")
+	//disWord := s.GetString("disWord")
 	userPower := jy.GetBigVipUserBaseMsg(s.Session(), *config.Middleground)
 	var (
 		belongUserId, email                                                string
@@ -99,52 +99,44 @@ func (s *Short) Article(contentType, stype, id string) error {
 	//userId = "637dcf3ff143ed326e9e1589"
 	//登录用户 权限
 	if userId != "" {
+		mobileHtmlKey := "jy_mobile_index_app"
 		var loginPageInfo = func() (body []byte) {
 			// 获取页面内容
-			url := fmt.Sprintf("%s%s", config.Sysconfig["webdomain"].(string), "/jy_mobile/index.html")
-			resp, err := http.Get(url)
-			log.Println("article --- url :", url)
+			mobileUrl := fmt.Sprintf("%s%s", config.Sysconfig["webdomain"].(string), "/jy_mobile/index.html")
+			req, err := http.NewRequest("GET", mobileUrl, nil)
 			if err != nil {
-				http.Error(s.ResponseWriter, "Failed to fetch page", http.StatusInternalServerError)
+				log.Println(s.ResponseWriter, "Failed to fetch page", http.StatusInternalServerError)
+				return
+			}
+			req.Header.Set("X-Forwarded-For", util.GetIp(s.Request))
+			client := &http.Client{}
+			// 使用 Do 方法处理请求
+			resp, err := client.Do(req)
+			if err != nil {
+				log.Println(s.ResponseWriter, "Failed to create client", http.StatusInternalServerError)
 				return
 			}
 			defer resp.Body.Close()
-
-			body, err = ioutil.ReadAll(resp.Body)
+			body, err = io.ReadAll(resp.Body)
 			if err != nil {
-				http.Error(s.ResponseWriter, "Failed to read response body", http.StatusInternalServerError)
+				log.Println(s.ResponseWriter, "Failed to read response body", http.StatusInternalServerError)
 				return
 			}
+			err = redis.PutBytes(redisLimitation, mobileHtmlKey, &body, 3*24*60*60)
+			if err != nil {
+				log.Println("mobile html redis cache err :", err.Error())
+			}
 			return
 		}
 		// 将页面内容返回给前端
 		s.ResponseWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
+		body, err := redis.GetBytes(redisLimitation, mobileHtmlKey)
+		if err == nil && body != nil && len(*body) > 0 {
+			s.ResponseWriter.Write(*body)
+			return nil
+		}
 		s.ResponseWriter.Write(loginPageInfo())
 		return nil
-		belongUserId = GetbelongUserId(disWord, userId)
-		b, _ := redis.Exists("sso", "req_"+userId)
-		if b {
-			return s.Redirect("/jyapp/free/mob/err")
-		}
-		isEntnicheNew = userPower.EntIsNew        //新版超级订阅
-		isOldVip = false                          //新购超级订阅不能查看拟建项目详情页
-		isVip = userPower.VipStatus > 0           //超级订阅
-		isMember = userPower.Status > 0           //大会员
-		isEntniche = userPower.EntnicheStatus > 0 //商机管理
-		email = userPower.Email
-		if userPower.Data != nil && userPower.Data.Ent != nil && userPower.Data.Entniche != nil {
-			isEntService = userPower.Data.Ent.PowerSource > 0 && userPower.Data.Entniche.IsEntPower > 0 //商机管理服务
-		} //用户邮箱
-		_, isOldVip, _, _, _ = UserPermission(userId)
-		entId := util.IntAll(sess["entId"])
-		if entId > 0 && userPower.EntInfo[entId] != nil {
-			isEntniche = userPower.EntInfo[entId].Status == 1 && userPower.EntInfo[entId].IsPower
-			isEntnicheNew = userPower.EntInfo[entId].IsNew && isEntniche
-			if isEntService = userPower.EntInfo[entId].IsService && userPower.EntInfo[entId].IsPower; isEntService {
-				isEntnicheNew = false
-				isEntniche = false
-			}
-		}
 	}
 	s.T["isVip"] = isVip
 	s.T["member_status"] = userPower.Status