自定义菜单

读取(查询)已设置菜单

  1. OfficialAccountApp.Menu.Get(https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Querying_Custom_Menus.html)

微信官方文档

获取当前菜单

  1. OfficialAccountApp.Menu.CurrentSelfMenu()

微信官方文档

添加菜单

添加普通菜单

  1. OfficialAccountApp.Menu.Create(ctx, &request.RequestMenuCreate{
  2. Buttons: []*request.Button{
  3. {
  4. Type: "click",
  5. Name: "今日歌曲",
  6. Key: "V1001_TODAY_MUSIC",
  7. },
  8. {
  9. Name: "Menu1",
  10. SubButtons: []request.SubButton{
  11. {
  12. Type: "view",
  13. Name: "搜索",
  14. URL: "http://www.soso.com/",
  15. },
  16. {
  17. Type: "miniprogram",
  18. Name: "wxa",
  19. URL: "http://mp.weixin.qq.com",
  20. AppID: "wx286b93c14bbf93aa",
  21. PagePath: "pages/lunar/index",
  22. },
  23. {
  24. Type: "click",
  25. Name: "赞一下我们",
  26. Key: "V1001_GOOD",
  27. },
  28. },
  29. },
  30. },
  31. })

微信官方文档

添加个性化菜单

  1. OfficialAccountApp.Menu.CreateConditional(ctx, &request.RequestMenuCreate{
  2. Buttons: []*request.Button{
  3. {
  4. Type: "click",
  5. Name: "个性化菜单",
  6. Key: "V1001_TODAY_MUSIC",
  7. },
  8. },
  9. }, &request.RequestMatchRule{
  10. Sex: "1",
  11. Country: "中国",
  12. Province: "广东",
  13. City: "广州",
  14. ClientPlatformType: "2",
  15. })

微信官方文档

删除菜单

  1. OfficialAccountApp.Menu.Delete()

微信官方文档

  1. menuID := 1
  2. OfficialAccountApp.Menu.DeleteConditional(menuID)

微信官方文档

测试个性化菜单

  1. OfficialAccountApp.Menu.TryMatch("[userID]")

微信官方文档

使用示例

参考: PowerWechatTutorial