mp.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // @description 微信公共平台的接口
  2. package gowechat
  3. import (
  4. "net/http"
  5. "github.com/yaotian/gowechat/mp/bridge"
  6. "github.com/yaotian/gowechat/mp/jssdk"
  7. "github.com/yaotian/gowechat/mp/material"
  8. "github.com/yaotian/gowechat/mp/menu"
  9. "github.com/yaotian/gowechat/mp/oauth"
  10. "github.com/yaotian/gowechat/mp/template"
  11. "github.com/yaotian/gowechat/mp/user"
  12. )
  13. //MpMgr mp mgr
  14. type MpMgr struct {
  15. Wechat
  16. }
  17. //GetAccessToken 获取access_token
  18. func (c *MpMgr) GetAccessToken() (string, error) {
  19. return c.Context.GetAccessToken()
  20. }
  21. // GetOauth oauth2网页授权
  22. func (c *MpMgr) GetOauth() *oauth.Oauth {
  23. return oauth.NewOauth(c.Context)
  24. }
  25. // GetMaterial 素材管理
  26. func (c *MpMgr) GetMaterial() *material.Material {
  27. return material.NewMaterial(c.Context)
  28. }
  29. // GetJs js-sdk配置
  30. func (c *MpMgr) GetJs() *jssdk.Js {
  31. return jssdk.NewJs(c.Context)
  32. }
  33. // GetMenu 菜单管理接口
  34. func (c *MpMgr) GetMenu() *menu.Menu {
  35. return menu.NewMenu(c.Context)
  36. }
  37. // GetUser 用户管理接口
  38. func (c *MpMgr) GetUser() *user.User {
  39. return user.NewUser(c.Context)
  40. }
  41. // GetTemplate 模板消息接口
  42. func (c *MpMgr) GetTemplate() *template.Template {
  43. return template.NewTemplate(c.Context)
  44. }
  45. // GetMsgHandler 消息管理
  46. func (c *MpMgr) GetMsgHandler(req *http.Request, writer http.ResponseWriter) *bridge.MsgHandler {
  47. c.Context.Request = req
  48. c.Context.Writer = writer
  49. return bridge.NewMsgHandler(c.Context)
  50. }