openplatform.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. ctx := &context.Context{
  18. Config: cfg,
  19. }
  20. return &OpenPlatform{ctx}
  21. }
  22. // GetServer get server
  23. func (openPlatform *OpenPlatform) GetServer(req *http.Request, writer http.ResponseWriter) *server.Server {
  24. off := officialaccount.NewOfficialAccount(openPlatform.Context, "")
  25. return off.GetServer(req, writer)
  26. }
  27. // GetOfficialAccount 公众号代处理
  28. func (openPlatform *OpenPlatform) GetOfficialAccount(appID string) *officialaccount.OfficialAccount {
  29. return officialaccount.NewOfficialAccount(openPlatform.Context, appID)
  30. }
  31. // GetMiniProgram 小程序代理
  32. func (openPlatform *OpenPlatform) GetMiniProgram(appID string) *miniprogram.MiniProgram {
  33. return miniprogram.NewMiniProgram(openPlatform.Context, appID)
  34. }
  35. // GetAccountManager 账号管理
  36. // TODO
  37. func (openPlatform *OpenPlatform) GetAccountManager() *account.Account {
  38. return account.NewAccount(openPlatform.Context)
  39. }