mp.go 1.9 KB

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