123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package wechat
-
- import (
- "wechat-conf/models"
- "wechat-conf/models/model"
- "wechat-conf/models/sysorg"
- "wechat-conf/models/wechat"
- "wechat-conf/utils"
- )
-
- // WechatServ 用户
- type WechatServ struct {
- ctx *utils.Context
- dao *wechat.WechatDAO
- orgdao *sysorg.SysorgDAO
- }
-
- // NewWechatServ 初始化
- func NewWechatServ(ctx *utils.Context) *WechatServ {
- return &WechatServ{
- ctx: ctx,
- dao: wechat.NewWechatDAO(ctx),
- orgdao: sysorg.NewSysorgDAO(ctx),
- }
- }
-
- // SaveWechatConf 保存微信配置
- func (s *WechatServ) SaveWechatConf(conf model.SysWechatConf) error {
- err := s.dao.SaveWechatConf(conf)
- return err
- }
-
- // UpdateToken 更新微信token
- func (s *WechatServ) UpdateToken(token map[string]interface{}) {
- models.UpdateToken(token)
- }
-
- // GetComponentInfo 获取第三方信息
- func (s *WechatServ) GetComponentInfo() (*model.SysComponentConf, error) {
- conf, err := s.dao.GetComponentInfo()
- if err != nil {
- return nil, err
- }
- return conf, nil
- }
-
- // UpdateComponentTicket 更新微信ticket
- func (s *WechatServ) UpdateComponentTicket(conf *model.SysComponentConf) error {
- err := s.dao.UpdateComponentTicket(conf)
- return err
- }
-
- // GetWechatByCode 根据code获取微信信息
- func (s *WechatServ) GetWechatByCode(code string) (*model.SysWechatConf, error) {
- conf, err := s.dao.GetWxByCode(code)
- return conf, err
- }
-
- // GetWechatConfByConfId 根据confid获取微信信息
- func (s *WechatServ) GetWechatConfByConfId(confid string) (*model.SysWechatConf, error) {
- conf, err := s.dao.GetWechatConfByConfId(confid)
- return conf, err
- }
-
- // UnAuthorized 取消授权
- func (s *WechatServ) UnAuthorized(appid string) error {
- if appid == "" {
- return nil
- }
- conf, err := s.dao.GetWechatConfByAppID(appid)
- if err != nil {
- utils.LogError("解绑获取微信信息失败:", err)
- return err
- }
- if conf == nil || conf.ConfId == "" {
- utils.LogError("解绑获取微信信息为空")
- return nil
- }
- // var wxConf = model.SysWechatConf{
- // ConfId: conf.ConfId,
- // Status: models.STATUS_DEL,
- // }
- // err = s.dao.UpdateWechatConf(wxConf, []string{
- // "status",
- // })
- err = s.dao.DelWechatConf(conf.ConfId)
- if err != nil {
- return err
- }
- // 解绑org
- err = s.orgdao.UnAutoOrg(conf.ConfId)
- return err
- }
|