Explorar o código

fix:新增获取jsConfig接口

Roc %!s(int64=3) %!d(string=hai) anos
pai
achega
e8ee3ff1ad
Modificáronse 3 ficheiros con 33 adicións e 0 borrados
  1. 23 0
      controller/wechat/wechat.go
  2. 1 0
      routers/wechat.go
  3. 9 0
      services/wechat/wechat.go

+ 23 - 0
controller/wechat/wechat.go

@@ -138,3 +138,26 @@ func GetEncryptInfo(c *gin.Context) {
 		Mobile: newUserInfo.Mobile,
 	}, c)
 }
+
+// GetWxJsConf
+// @Title 微信获取签名接口
+// @Description 微信获取签名接口
+// @Param   Url   query   string  true       "url地址"
+// @Success 200 {object} models.WechatSign
+// @router /getWxJsConf [get]
+func GetWxJsConf(c *gin.Context) {
+	getUrl := c.DefaultQuery("Url", "")
+	jsConf, err := wechat.GetJsConfig(getUrl)
+	if err != nil {
+		response.Fail("获取失败,Err:"+err.Error(), c)
+		return
+	}
+	//resp := new(models.WechatSign)
+	//resp.AppId = utils.WxAppId
+	//resp.NonceStr = nonceString
+	//resp.Timestamp = timestamp
+	//resp.Url = getUrl
+	//resp.Signature = signature
+	//jsConf.AppID
+	response.OkData("获取成功", jsConf, c)
+}

+ 1 - 0
routers/wechat.go

@@ -20,5 +20,6 @@ func InitWechat(r *gin.Engine) {
 	rGroup2 := r.Group("wechat").Use(middleware.TokenNoLogin())
 	{
 		rGroup2.POST("/getEncryptInfo", wechat.GetEncryptInfo)
+		rGroup2.GET("/getWxJsConf", wechat.GetWxJsConf)
 	}
 }

+ 9 - 0
services/wechat/wechat.go

@@ -7,6 +7,7 @@ import (
 	"github.com/silenceper/wechat/v2/credential"
 	"github.com/silenceper/wechat/v2/officialaccount"
 	"github.com/silenceper/wechat/v2/officialaccount/config"
+	"github.com/silenceper/wechat/v2/officialaccount/js"
 	"github.com/silenceper/wechat/v2/officialaccount/user"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/tables/wx_token"
@@ -90,6 +91,14 @@ func GetUserInfo(openid string) (userInfo *user.Info, err error) {
 	return
 }
 
+// GetJsConfig 获取公众号jsConfig
+func GetJsConfig(signUrl string) (jsConf *js.Config, err error) {
+	wechatClient := GetWxChat()
+	j := wechatClient.GetJs()
+	jsConf, err = j.GetConfig(signUrl)
+	return
+}
+
 type WechatAccessToken struct {
 }