work.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package work
  2. import (
  3. "github.com/silenceper/wechat/v2/credential"
  4. "github.com/silenceper/wechat/v2/work/addresslist"
  5. "github.com/silenceper/wechat/v2/work/appchat"
  6. "github.com/silenceper/wechat/v2/work/checkin"
  7. "github.com/silenceper/wechat/v2/work/config"
  8. "github.com/silenceper/wechat/v2/work/context"
  9. "github.com/silenceper/wechat/v2/work/externalcontact"
  10. "github.com/silenceper/wechat/v2/work/invoice"
  11. "github.com/silenceper/wechat/v2/work/kf"
  12. "github.com/silenceper/wechat/v2/work/material"
  13. "github.com/silenceper/wechat/v2/work/message"
  14. "github.com/silenceper/wechat/v2/work/msgaudit"
  15. "github.com/silenceper/wechat/v2/work/oauth"
  16. "github.com/silenceper/wechat/v2/work/robot"
  17. )
  18. // Work 企业微信
  19. type Work struct {
  20. ctx *context.Context
  21. }
  22. // NewWork init work
  23. func NewWork(cfg *config.Config) *Work {
  24. defaultAkHandle := credential.NewWorkAccessToken(cfg.CorpID, cfg.CorpSecret, cfg.AgentID, credential.CacheKeyWorkPrefix, cfg.Cache)
  25. ctx := &context.Context{
  26. Config: cfg,
  27. AccessTokenHandle: defaultAkHandle,
  28. }
  29. return &Work{ctx: ctx}
  30. }
  31. // GetContext get Context
  32. func (wk *Work) GetContext() *context.Context {
  33. return wk.ctx
  34. }
  35. // GetOauth get oauth
  36. func (wk *Work) GetOauth() *oauth.Oauth {
  37. return oauth.NewOauth(wk.ctx)
  38. }
  39. // GetMsgAudit get msgAudit
  40. func (wk *Work) GetMsgAudit() (*msgaudit.Client, error) {
  41. return msgaudit.NewClient(wk.ctx.Config)
  42. }
  43. // GetKF get kf
  44. func (wk *Work) GetKF() (*kf.Client, error) {
  45. return kf.NewClient(wk.ctx.Config)
  46. }
  47. // GetExternalContact get external_contact
  48. func (wk *Work) GetExternalContact() *externalcontact.Client {
  49. return externalcontact.NewClient(wk.ctx)
  50. }
  51. // GetAddressList get address_list
  52. func (wk *Work) GetAddressList() *addresslist.Client {
  53. return addresslist.NewClient(wk.ctx)
  54. }
  55. // GetMaterial get material
  56. func (wk *Work) GetMaterial() *material.Client {
  57. return material.NewClient(wk.ctx)
  58. }
  59. // GetRobot get robot
  60. func (wk *Work) GetRobot() *robot.Client {
  61. return robot.NewClient(wk.ctx)
  62. }
  63. // GetMessage 获取发送应用消息接口实例
  64. func (wk *Work) GetMessage() *message.Client {
  65. return message.NewClient(wk.ctx)
  66. }
  67. // GetAppChat 获取应用发送消息到群聊会话接口实例
  68. func (wk *Work) GetAppChat() *appchat.Client {
  69. return appchat.NewClient(wk.ctx)
  70. }
  71. // GetInvoice get invoice
  72. func (wk *Work) GetInvoice() *invoice.Client {
  73. return invoice.NewClient(wk.ctx)
  74. }
  75. // GetCheckin 获取打卡接口实例
  76. func (wk *Work) GetCheckin() *checkin.Client {
  77. return checkin.NewClient(wk.ctx)
  78. }