work.go 766 B

123456789101112131415161718192021222324252627282930313233
  1. package work
  2. import (
  3. "github.com/silenceper/wechat/v2/credential"
  4. "github.com/silenceper/wechat/v2/work/config"
  5. "github.com/silenceper/wechat/v2/work/context"
  6. "github.com/silenceper/wechat/v2/work/oauth"
  7. )
  8. // Work 企业微信
  9. type Work struct {
  10. ctx *context.Context
  11. }
  12. //NewWork init work
  13. func NewWork(cfg *config.Config) *Work {
  14. defaultAkHandle := credential.NewWorkAccessToken(cfg.CorpID, cfg.CorpSecret, credential.CacheKeyWorkPrefix, cfg.Cache)
  15. ctx := &context.Context{
  16. Config: cfg,
  17. AccessTokenHandle: defaultAkHandle,
  18. }
  19. return &Work{ctx: ctx}
  20. }
  21. //GetContext get Context
  22. func (wk *Work) GetContext() *context.Context {
  23. return wk.ctx
  24. }
  25. //GetOauth get oauth
  26. func (wk *Work) GetOauth() *oauth.Oauth {
  27. return oauth.NewOauth(wk.ctx)
  28. }