openplatform.go 1.5 KB

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