zqbao 9 сар өмнө
parent
commit
b5d9c31f56

+ 16 - 0
controllers/wechat.go

@@ -297,6 +297,22 @@ func (this *WechatController) Subscribe() {
 		br.ErrMsg = "新增失败,Err:" + err.Error()
 		return
 	}
+	if u.UnionId == "" {
+		wxInfo, er := wechat.GetUserInfo(u.OpenId)
+		if er != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + er.Error()
+			return
+		}
+		u.UnionId = wxInfo.UnionID
+		er = u.Update([]string{"union_id"})
+		if er != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + er.Error()
+			return
+		}
+
+	}
 	user, err := models.GetUserByUnionId(u.UnionId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取用户信息失败"

+ 5 - 2
services/wechat/wechat.go

@@ -30,10 +30,13 @@ type WechatAccessToken struct {
 
 func GetWxChat() (officialAccount *officialaccount.OfficialAccount) {
 	wc := wechat.NewWechat()
+	minConf, _ := models.GetMiniConf()
 	memory := cache.NewMemory()
 	conf := &config.Config{
-		AppID:          utils.HZ_WX_APPID,
-		AppSecret:      utils.HZ_WX_APP_SECRET,
+		// AppID:          utils.HZ_WX_APPID,
+		// AppSecret:      utils.HZ_WX_APP_SECRET,
+		AppID:          minConf["WxAppId"],
+		AppSecret:      minConf["WxAppSecret"],
 		Token:          "",
 		EncodingAESKey: "",
 		Cache:          memory,