wangfei 6 years ago
parent
commit
ee26fd3798

+ 3
- 0
controllers/component.go View File

147
 		break
147
 		break
148
 	case INFOTYPE_UNAUTHORIZED:
148
 	case INFOTYPE_UNAUTHORIZED:
149
 		// 取消授权
149
 		// 取消授权
150
+		// 删除wechatConf信息,同时将org解绑
151
+		appid := msg["AuthorizerAppid"]
152
+		c.wechatServ.UnAuthorized(appid)
150
 		break
153
 		break
151
 	}
154
 	}
152
 	c.ResponseRaw([]byte("success"))
155
 	c.ResponseRaw([]byte("success"))

+ 3
- 0
controllers/wechatmenu/wechatmenu.go View File

7
 	"wechat-conf/service/sysuser"
7
 	"wechat-conf/service/sysuser"
8
 	"wechat-conf/service/wechatmenu"
8
 	"wechat-conf/service/wechatmenu"
9
 	"wechat-conf/utils"
9
 	"wechat-conf/utils"
10
+
11
+	"github.com/astaxie/beego"
10
 )
12
 )
11
 
13
 
12
 // MenuController 信息
14
 // MenuController 信息
30
 	if err != nil {
32
 	if err != nil {
31
 		c.ResponseError(err)
33
 		c.ResponseError(err)
32
 	}
34
 	}
35
+	beego.Error(appId)
33
 	client, err := utils.Component.GetWxClient(appId)
36
 	client, err := utils.Component.GetWxClient(appId)
34
 	if err != nil {
37
 	if err != nil {
35
 		c.ResponseError(err)
38
 		c.ResponseError(err)

+ 14
- 0
models/sysorg/sysorg.go View File

65
 	_, err := m.db.Cols(cols...).Where("org_id = ?", org.OrgId).Update(org)
65
 	_, err := m.db.Cols(cols...).Where("org_id = ?", org.OrgId).Update(org)
66
 	return err
66
 	return err
67
 }
67
 }
68
+
69
+// UnAutoOrg 解绑
70
+func (m *SysorgDAO) UnAutoOrg(confid string) error {
71
+	var org = model.SysOrg{
72
+		WechatId:   "",
73
+		AuthStatus: models.AUTH_STATUS_NO,
74
+	}
75
+	var cols = []string{
76
+		"wechat_id",
77
+		"auth_status",
78
+	}
79
+	_, err := m.db.Cols(cols...).Where("wechat_id = ?", confid).Update(org)
80
+	return err
81
+}

+ 0
- 3
service/user/user.go View File

7
 	"wechat-conf/models/user"
7
 	"wechat-conf/models/user"
8
 	"wechat-conf/utils"
8
 	"wechat-conf/utils"
9
 
9
 
10
-	"github.com/astaxie/beego"
11
-
12
 	"github.com/yl10/kit/encrypt"
10
 	"github.com/yl10/kit/encrypt"
13
 )
11
 )
14
 
12
 
62
 
60
 
63
 // ValidatePassword 验证密码是否正确
61
 // ValidatePassword 验证密码是否正确
64
 func (s *UserServ) ValidatePassword(user *model.SysUser, password string) bool {
62
 func (s *UserServ) ValidatePassword(user *model.SysUser, password string) bool {
65
-	beego.Error(encrypt.Md5(password, user.UserId))
66
 	return user.Pwd == encrypt.Md5(password, user.UserId)
63
 	return user.Pwd == encrypt.Md5(password, user.UserId)
67
 }
64
 }
68
 
65
 

+ 36
- 4
service/wechat/wechat.go View File

3
 import (
3
 import (
4
 	"wechat-conf/models"
4
 	"wechat-conf/models"
5
 	"wechat-conf/models/model"
5
 	"wechat-conf/models/model"
6
+	"wechat-conf/models/sysorg"
6
 	"wechat-conf/models/wechat"
7
 	"wechat-conf/models/wechat"
7
 	"wechat-conf/utils"
8
 	"wechat-conf/utils"
8
 )
9
 )
9
 
10
 
10
 // WechatServ 用户
11
 // WechatServ 用户
11
 type WechatServ struct {
12
 type WechatServ struct {
12
-	ctx *utils.Context
13
-	dao *wechat.WechatDAO
13
+	ctx    *utils.Context
14
+	dao    *wechat.WechatDAO
15
+	orgdao *sysorg.SysorgDAO
14
 }
16
 }
15
 
17
 
16
 // NewWechatServ 初始化
18
 // NewWechatServ 初始化
17
 func NewWechatServ(ctx *utils.Context) *WechatServ {
19
 func NewWechatServ(ctx *utils.Context) *WechatServ {
18
 	return &WechatServ{
20
 	return &WechatServ{
19
-		ctx: ctx,
20
-		dao: wechat.NewWechatDAO(ctx),
21
+		ctx:    ctx,
22
+		dao:    wechat.NewWechatDAO(ctx),
23
+		orgdao: sysorg.NewSysorgDAO(ctx),
21
 	}
24
 	}
22
 }
25
 }
23
 
26
 
58
 	conf, err := s.dao.GetWechatConfByConfId(confid)
61
 	conf, err := s.dao.GetWechatConfByConfId(confid)
59
 	return conf, err
62
 	return conf, err
60
 }
63
 }
64
+
65
+// UnAuthorized 取消授权
66
+func (s *WechatServ) UnAuthorized(appid string) error {
67
+	if appid == "" {
68
+		return nil
69
+	}
70
+	conf, err := s.dao.GetWechatConfByAppID(appid)
71
+	if err != nil {
72
+		utils.LogError("解绑获取微信信息失败:", err)
73
+		return err
74
+	}
75
+	if conf == nil || conf.ConfId == "" {
76
+		utils.LogError("解绑获取微信信息为空")
77
+		return nil
78
+	}
79
+	var wxConf = model.SysWechatConf{
80
+		ConfId: conf.ConfId,
81
+		Status: models.STATUS_DEL,
82
+	}
83
+	err = s.dao.UpdateWechatConf(wxConf, []string{
84
+		"status",
85
+	})
86
+	if err != nil {
87
+		return err
88
+	}
89
+	// 解绑org
90
+	err = s.orgdao.UnAutoOrg(conf.ConfId)
91
+	return err
92
+}