openplatform.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package openplatform
  2. import (
  3. "github.com/silenceper/wechat/v2/openplatform/account"
  4. "github.com/silenceper/wechat/v2/openplatform/config"
  5. "github.com/silenceper/wechat/v2/openplatform/context"
  6. "github.com/silenceper/wechat/v2/openplatform/miniprogram"
  7. "github.com/silenceper/wechat/v2/openplatform/officialaccount"
  8. )
  9. //OpenPlatform 微信开放平台相关api
  10. type OpenPlatform struct {
  11. *context.Context
  12. }
  13. //NewOpenPlatform new openplatform
  14. func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
  15. if cfg.Cache == nil {
  16. panic("cache 未设置")
  17. }
  18. ctx := &context.Context{
  19. Config: cfg,
  20. }
  21. return &OpenPlatform{ctx}
  22. }
  23. //GetOfficialAccount 公众号代处理
  24. func (openPlatform *OpenPlatform) GetOfficialAccount(appID string) *officialaccount.OfficialAccount {
  25. return officialaccount.NewOfficialAccount(openPlatform.Context, appID)
  26. }
  27. //GetMiniProgram 小程序代理
  28. func (openPlatform *OpenPlatform) GetMiniProgram(appID string) *miniprogram.MiniProgram {
  29. return miniprogram.NewMiniProgram(openPlatform.Context, appID)
  30. }
  31. //GetAccountManager 账号管理
  32. //TODO
  33. func (openPlatform *OpenPlatform) GetAccountManager() *account.Account {
  34. return account.NewAccount(openPlatform.Context)
  35. }