wechat.go 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package wechat
  2. import (
  3. "wechat-conf/models"
  4. "wechat-conf/models/model"
  5. "wechat-conf/models/sysorg"
  6. "wechat-conf/models/wechat"
  7. "wechat-conf/utils"
  8. )
  9. // WechatServ 用户
  10. type WechatServ struct {
  11. ctx *utils.Context
  12. dao *wechat.WechatDAO
  13. orgdao *sysorg.SysorgDAO
  14. }
  15. // NewWechatServ 初始化
  16. func NewWechatServ(ctx *utils.Context) *WechatServ {
  17. return &WechatServ{
  18. ctx: ctx,
  19. dao: wechat.NewWechatDAO(ctx),
  20. orgdao: sysorg.NewSysorgDAO(ctx),
  21. }
  22. }
  23. // SaveWechatConf 保存微信配置
  24. func (s *WechatServ) SaveWechatConf(conf model.SysWechatConf) error {
  25. err := s.dao.SaveWechatConf(conf)
  26. return err
  27. }
  28. // UpdateToken 更新微信token
  29. func (s *WechatServ) UpdateToken(token map[string]interface{}) {
  30. models.UpdateToken(token)
  31. }
  32. // GetComponentInfo 获取第三方信息
  33. func (s *WechatServ) GetComponentInfo() (*model.SysComponentConf, error) {
  34. conf, err := s.dao.GetComponentInfo()
  35. if err != nil {
  36. return nil, err
  37. }
  38. return conf, nil
  39. }
  40. // UpdateComponentTicket 更新微信ticket
  41. func (s *WechatServ) UpdateComponentTicket(conf *model.SysComponentConf) error {
  42. err := s.dao.UpdateComponentTicket(conf)
  43. return err
  44. }
  45. // GetWechatByCode 根据code获取微信信息
  46. func (s *WechatServ) GetWechatByCode(code string) (*model.SysWechatConf, error) {
  47. conf, err := s.dao.GetWxByCode(code)
  48. return conf, err
  49. }
  50. // GetWechatConfByConfId 根据confid获取微信信息
  51. func (s *WechatServ) GetWechatConfByConfId(confid string) (*model.SysWechatConf, error) {
  52. conf, err := s.dao.GetWechatConfByConfId(confid)
  53. return conf, err
  54. }
  55. // UnAuthorized 取消授权
  56. func (s *WechatServ) UnAuthorized(appid string) error {
  57. if appid == "" {
  58. return nil
  59. }
  60. conf, err := s.dao.GetWechatConfByAppID(appid)
  61. if err != nil {
  62. utils.LogError("解绑获取微信信息失败:", err)
  63. return err
  64. }
  65. if conf == nil || conf.ConfId == "" {
  66. utils.LogError("解绑获取微信信息为空")
  67. return nil
  68. }
  69. // var wxConf = model.SysWechatConf{
  70. // ConfId: conf.ConfId,
  71. // Status: models.STATUS_DEL,
  72. // }
  73. // err = s.dao.UpdateWechatConf(wxConf, []string{
  74. // "status",
  75. // })
  76. err = s.dao.DelWechatConf(conf.ConfId)
  77. if err != nil {
  78. return err
  79. }
  80. // 解绑org
  81. err = s.orgdao.UnAutoOrg(conf.ConfId)
  82. return err
  83. }