Browse Source

Merge branch 'master' into chart2.0

hsun 3 years ago
parent
commit
4c8ed8a227
3 changed files with 48 additions and 13 deletions
  1. 23 0
      controller/wechat/wechat.go
  2. 1 0
      routers/wechat.go
  3. 24 13
      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)
 	}
 }

+ 24 - 13
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"
@@ -34,7 +35,7 @@ var (
 	WxPublicSecretXzs                     string //查研观向小助手公众号
 )
 
-func init() {
+func initConf() {
 	if global.CONFIG.Serve.RunMode == "debug" {
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
@@ -50,22 +51,24 @@ func init() {
 
 		WxMsgTemplateIdAskByUser = `qfNuops-sKrfIkbA7U97A7gSrX03mUpoEpJksRUdloo`
 	} else {
-		//WxAppId = "wx4a844c734d8c8e56"
-		//WxAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
-		//WxId = "gh_b67e0049fb8c"
-		//TemplateIdByProduct = "Cp2wF8gvBtxyWV4DeYuI172oqwyYXVRSm3AyJO42d84"
-		//TemplateRedirectUrl = "https://ficc.hzinsights.com/reportdtl?id="
-		//DayReportTemplateRedirectUrl = "https://report.hzinsights.com/#/allindex/" //晨报模板跳转url
-		//TemplateIdByCompanyApply = "ZKcOfNIWBpwHJxpptufHIK1mp2nIwkT3cxub-35cFqI"
-		//TemplateCompanyApplyRedirectUrl = "https://ficc.hzinsights.com/approval/approval/list"
-		//WxMsgTemplateIdActivityChangeApply = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0"
-		////销售跨部门领取客户通知
-		//TemplateIdByCompanyReceive = "A5fV-XWBcu-LIj_W-tBiOJ-D39a9WDd9GOB0WGbpoBg"
-		//TemplateCompanyApplyRedirectUrl = "https://ficc.hzinsights.com/approval/approval/list"
+		WxAppId = "wx4a844c734d8c8e56"
+		WxAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
+		WxId = "gh_b67e0049fb8c"
+		TemplateIdByProduct = "Cp2wF8gvBtxyWV4DeYuI172oqwyYXVRSm3AyJO42d84"
+		TemplateRedirectUrl = "https://ficc.hzinsights.com/reportdtl?id="
+		DayReportTemplateRedirectUrl = "https://report.hzinsights.com/#/allindex/" //晨报模板跳转url
+		TemplateIdByCompanyApply = "ZKcOfNIWBpwHJxpptufHIK1mp2nIwkT3cxub-35cFqI"
+		TemplateCompanyApplyRedirectUrl = "https://ficc.hzinsights.com/approval/approval/list"
+		WxMsgTemplateIdActivityChangeApply = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0"
+		//销售跨部门领取客户通知
+		TemplateIdByCompanyReceive = "A5fV-XWBcu-LIj_W-tBiOJ-D39a9WDd9GOB0WGbpoBg"
+		TemplateCompanyApplyRedirectUrl = "https://ficc.hzinsights.com/approval/approval/list"
 	}
 }
 
 func GetWxChat() (officialAccount *officialaccount.OfficialAccount) {
+	initConf() //初始化参数
+
 	wc := wechat.NewWechat()
 	memory := cache.NewMemory()
 	conf := &config.Config{
@@ -90,6 +93,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 {
 }