diff --git a/cv/group_cv/group.go b/cv/group_cv/group.go index 54e20f272e5b57e189e1d4e8641ea50a98d771f0..832e3107d2a05eb7287e2bd4d8361c35e36bf7a4 100644 --- a/cv/group_cv/group.go +++ b/cv/group_cv/group.go @@ -154,6 +154,7 @@ type SimpleRoleInfo struct { type BannerElement struct { H5Url string `json:"h5Url"` // h5链接 BannerUrl string `json:"bannerUrl"` // 图片地址 + ActionUrl string `json:"actionUrl"` // 统跳地址 } type RoomInfo struct { diff --git a/route/group_r/group_info.go b/route/group_r/group_info.go index 9b71582456f9b1f04880f0aaa3f19c5a695a1f48..bf2924ef5be8aac47d4bd0d5e5666587dc25bf9e 100644 --- a/route/group_r/group_info.go +++ b/route/group_r/group_info.go @@ -38,6 +38,7 @@ import ( "hilo-group/myerr/bizerr" "hilo-group/req" "hilo-group/resp" + "net/url" "sort" "strconv" "strings" @@ -592,6 +593,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { result.Banners = append(result.Banners, group_cv.BannerElement{ H5Url: i.Url, BannerUrl: i.Image, + ActionUrl: i.Url, // 支持direction=1横屏 }) } } else { @@ -751,6 +753,8 @@ type GroupBanner struct { BannerUrl string `json:"bannerUrl"` //群主Id GroupId string `json:"groupId"` + //统跳地址 http开头:web页面,query参数direction(0:竖屏 1:横屏); hilo开头:原生页面 + ActionUrl string `json:"actionUrl"` } // @Tags 群组 @@ -827,11 +831,27 @@ func GroupBannerList(c *gin.Context) (*mycontext.MyContext, error) { if v.Area == 3 && !utils.IsInStringList(country, v.CountryList) { continue } - + actionUrl := v.Url + if uri, err := url.Parse(actionUrl); err == nil { + query := uri.RawQuery + queryArr := strings.Split(query, "&") + v := url.Values{} + if len(queryArr) > 0 { + for _, q := range queryArr { + if arr := strings.Split(q, "="); len(arr) == 2 { + v.Add(arr[0], arr[1]) + } + } + } + //v.Add("direction", "1") // 横屏的需要这样 + uri.RawQuery = v.Encode() + actionUrl = uri.String() + } groupBanners = append(groupBanners, GroupBanner{ H5Url: v.Url, BannerUrl: v.Image, GroupId: groupMap[v.GroupCode], + ActionUrl: actionUrl, }) } resp.ResponseOk(c, groupBanners) @@ -841,6 +861,7 @@ func GroupBannerList(c *gin.Context) (*mycontext.MyContext, error) { type RoomBanner struct { H5Url string `json:"h5Url"` // h5链接 BannerUrl string `json:"bannerUrl"` // 图片地址 + ActionUrl string `json:"actionUrl"` // 统跳地址 http开头:web页面,query参数direction(0:竖屏 1:横屏); hilo开头:原生页面 } // @Tags 群组 @@ -893,6 +914,7 @@ func RoomBannerList(c *gin.Context) (*mycontext.MyContext, error) { result = append(result, RoomBanner{ H5Url: i.Url, BannerUrl: i.Image, + ActionUrl: i.Url, }) } resp.ResponseOk(c, result) diff --git a/test/url_test.go b/test/url_test.go new file mode 100644 index 0000000000000000000000000000000000000000..5cc999f5a6220b5e0b32c94c4eeca1ee00918ec3 --- /dev/null +++ b/test/url_test.go @@ -0,0 +1,34 @@ +package test + +import ( + "fmt" + "net/url" + "path" + "strings" + "testing" +) + +func TestUrlParse(t *testing.T) { + //rawUrl := "https://pkg.go.dev/net/url?a=b&c=d#example-ParseQuery" + rawUrl := "https://pkg.go.dev/net/url" + uri, err := url.Parse(rawUrl) + if err != nil { + return + } + query := uri.RawQuery + queryArr := strings.Split(query, "&") + v := url.Values{} + if len(queryArr) > 0 { + for _, q := range queryArr { + if arr := strings.Split(q, "="); len(arr) == 2 { + v.Add(arr[0], arr[1]) + } + } + } + v.Add("v1", "v1") + v.Add("v2", "v2") + uri.RawQuery = v.Encode() + uri.Path = path.Join(uri.Path, "/ccc/ddd") + fmt.Println(fmt.Sprintf("修改后的URL是:%s", uri.String())) + +}