openplatform.go 994 B

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