|
@@ -312,8 +312,17 @@ func BindWxGzh(code string) (isBind bool, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- openId := wxUser.OpenId
|
|
|
+ return BindWxGzhByOpenId(wxUser.OpenId)
|
|
|
+}
|
|
|
|
|
|
+// BindWxGzhByOpenId
|
|
|
+// @Description: 通过openid绑定微信公众号
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-08-13 13:19:49
|
|
|
+// @param openId string
|
|
|
+// @return isBind bool
|
|
|
+// @return err error
|
|
|
+func BindWxGzhByOpenId(openId string) (isBind bool, err error) {
|
|
|
logger.Info("openId:" + openId)
|
|
|
wxUserDetail, err := GetWxUserDetail(openId)
|
|
|
if err != nil {
|
|
@@ -323,6 +332,7 @@ func BindWxGzh(code string) (isBind bool, err error) {
|
|
|
}
|
|
|
|
|
|
unionId := wxUserDetail.UnionID
|
|
|
+ followingGzh := int(wxUserDetail.Subscribe)
|
|
|
|
|
|
logger.Info("unionId:" + unionId)
|
|
|
var isAdd bool
|
|
@@ -341,6 +351,7 @@ func BindWxGzh(code string) (isBind bool, err error) {
|
|
|
if isAdd {
|
|
|
user.GzhOpenId = openId
|
|
|
user.UnionId = unionId
|
|
|
+ user.FollowingGzh = followingGzh
|
|
|
var isRegister bool
|
|
|
|
|
|
//判断unionid是否存在
|
|
@@ -364,13 +375,55 @@ func BindWxGzh(code string) (isBind bool, err error) {
|
|
|
}
|
|
|
} else { //修改微信小程序openid
|
|
|
logger.Info("wxUser.Id:%d", wxUser.Id)
|
|
|
- err = userService.BindUserGzhOpenId(wxUser.Id, openId)
|
|
|
+ err = userService.BindUserGzhOpenId(wxUser.Id, openId, followingGzh)
|
|
|
if err != nil {
|
|
|
logger.Info("BindUserGzhOpenId,Err" + err.Error())
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
isBind = true
|
|
|
+ err = userService.BindUserGzhOpenId(user.Id, openId, followingGzh)
|
|
|
+ if err != nil {
|
|
|
+ logger.Info("BindUserGzhOpenId,Err" + err.Error())
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// UnSubscribeWxGzhByOpenId
|
|
|
+// @Description: 通过openid取消关注微信公众号
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2024-08-13 13:19:49
|
|
|
+// @param openId string
|
|
|
+// @return isBind bool
|
|
|
+// @return err error
|
|
|
+func UnSubscribeWxGzhByOpenId(openId string) {
|
|
|
+ logger.Info("openId:" + openId)
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ logger.Info("通过openid取消关注微信公众号失败,openId:", openId, ";错误信息:", err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ // 通过公众号openid获取用户信息
|
|
|
+ user, err := userService.GetTemplateUserByGzhOpenId(openId)
|
|
|
+ if err != nil {
|
|
|
+ if err == gorm.ErrRecordNotFound {
|
|
|
+ err = nil
|
|
|
+ // 找不到就直接返回了
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ err = exception.New(exception.TemplateUserNotFound)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解绑用户
|
|
|
+ err = userService.BindUserGzhOpenId(user.Id, openId, 0)
|
|
|
+ if err != nil {
|
|
|
+ logger.Info("UnBindWxGzhByOpenId,Err" + err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|