Skip to content

菜单反序列化成WxMenu对象时matchRule属性为空 #142

Closed

Description

@yiyi910

WxMenuGsonAdapter的deserialize方法没有取matchrule字段

Activity

  1. zhuyanqing927 commented on Feb 19, 2017

    @zhuyanqing927

    这次对接个性化菜单的时候,查询所有菜单也发现了这个问题。。多谢

  2. binarywang commented on Feb 19, 2017

    @binarywang
    Owner

    me.chanjar.weixin.mp.bean.menu.WxMpMenu
    你们用过这个类吗?是专为公众号创建的

  3. binarywang commented on Feb 19, 2017

    @binarywang
    Owner

    感觉你们可能用的是老版本吧?最新版本的实现已经发生了变化

  4. zhuyanqing927 commented on Feb 19, 2017

    @zhuyanqing927
  5. zhuyanqing927 commented on Feb 19, 2017

    @zhuyanqing927
  6. binarywang commented on Feb 19, 2017

    @binarywang
    Owner

    我今天特意跑过单元测试,没发现有问题啊,不知道你是如何调用的

  7. binarywang commented on Feb 19, 2017

    @binarywang
    Owner

    在反序列化时已经不再使用WxMenuGsonAdapter了

  8. yiyi910 commented on Feb 20, 2017

    @yiyi910
    Author

    发布个性化菜单是调WxMpMenuService的menuCreate(String json)方法对吧

  9. binarywang commented on Feb 20, 2017

    @binarywang
    Owner

    @yiyi910 没错,你的问题到底是什么呢?既然是create,为啥又说到了反序列化的问题?

  10. yiyi910 commented on Feb 20, 2017

    @yiyi910
    Author

    那之前调错了,调的是create(WxMenu menu)这个方法,WxMenu是通过fromJson(String json)构建的

  11. binarywang commented on Feb 21, 2017

    @binarywang
    Owner

    调那两个方法创建菜单都没有问题,关键是你要传对了参数

  12. yiyi910 commented on Feb 21, 2017

    @yiyi910
    Author

    WxMenu.fromJson(String json)构建个性化菜单WxMenu对象时,matchRule属性为null,我json字符串是有matchrule的

  13. binarywang commented on Feb 21, 2017

    @binarywang
    Owner

    WxMenu属于企业号和公众号共用的menu类,在有个性花菜单的情况下不建议使用。你看下WxMpMenu这个类

  14. yiyi910 commented on Mar 13, 2017

    @yiyi910
    Author

    你好, 刚升级到2.5,怎么发现二级菜单是个空集合呢?

  15. yiyi910 commented on Mar 13, 2017

    @yiyi910
    Author

    22:30:39.261 [main] INFO com.vania.MenuTests - 获取-微信自定义菜单:
    {"menu":{"button":[{"type":"view","name":"市场行情","url":"http://www.baidu.com","subButtons":[]},{"name":"资产及投资","subButtons":[]},{"type":"view","name":"我","url":"http://www.baidu.com","subButtons":[]}]}}

    这是我的日志

  16. yiyi910 commented on Mar 13, 2017

    @yiyi910
    Author
    @Test
    public void menuGet() {
    	WxMpMenu wxMenu = null;
    	// 设置菜单
    	try {
    		wxMenu = wxMpMenuService.menuGet();
    		WxMpConditionalMenu menu = wxMenu.getMenu();
    	} catch (WxErrorException e) {
    		log.error("获取-微信自定义菜单失败.", e);
    	}
    	log.info("获取-微信自定义菜单:\n{}", wxMenu.toJson());
    }
    

    这是我的case

  17. binarywang commented on Mar 13, 2017

    @binarywang
    Owner

    你最好对照下项目中的单元测试看下是哪儿的问题吧

  18. yiyi910 commented on Mar 13, 2017

    @yiyi910
    Author

    我跑工程里WxMpMenuServiceImplTest类的testMenuGet 这个name为"菜单"的一级菜单subButtons确实为空集合. 附上日志:

  19. yiyi910 commented on Mar 13, 2017

    @yiyi910
    Author

    Method public java.lang.Object[][] me.chanjar.weixin.mp.api.impl.WxMpMenuServiceImplTest.getMenu() has a @test annotation but also a return value: ignoring it. Use to fix this
    [TestNG] Running:
    C:\Users\vania\AppData\Local\Temp\testng-eclipse--1642397105\testng-customsuite.xml

    {"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}
    00:41:44.230 [main] DEBUG m.c.w.m.api.impl.WxMpMenuServiceImpl - 开始创建菜单:{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}
    00:41:45.308 [main] DEBUG m.c.w.mp.api.impl.WxMpServiceImpl -
    [URL]: https://api.weixin.qq.com/cgi-bin/menu/create
    [PARAMS]: {"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}
    [RESPONSE]: {"errcode":0,"errmsg":"ok"}
    00:41:45.308 [main] DEBUG m.c.w.m.api.impl.WxMpMenuServiceImpl - 创建菜单:{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]},结果:{"errcode":0,"errmsg":"ok"}
    00:41:51.546 [main] DEBUG m.c.w.mp.api.impl.WxMpServiceImpl -
    [URL]: https://api.weixin.qq.com/cgi-bin/menu/get
    [PARAMS]: null
    [RESPONSE]: {"menu":{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","sub_button":[]},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","sub_button":[]},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/","sub_button":[]},{"type":"view","name":"视频","url":"http://v.qq.com/","sub_button":[]},{"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]}]}}
    {"menu":{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","subButtons":[]},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","subButtons":[]},{"name":"菜单","subButtons":[]}]}}
    PASSED: testMenuCreate(WxMenu[
    buttons=[WxMenuButton[
    type=click
    name=今日歌曲
    key=V1001_TODAY_MUSIC
    subButtons=[]
    ], WxMenuButton[
    type=click
    name=歌手简介
    key=V1001_TODAY_SINGER
    subButtons=[]
    ], WxMenuButton[
    name=菜单
    subButtons=[WxMenuButton[
    type=view
    name=搜索
    url=http://www.soso.com/
    subButtons=[]
    ], WxMenuButton[
    type=view
    name=视频
    url=http://v.qq.com/
    subButtons=[]
    ], WxMenuButton[
    type=click
    name=赞一下我们
    key=V1001_GOOD
    subButtons=[]
    ]]
    ]]
    ])
    PASSED: testMenuGet

    ===============================================
    Default test
    Tests run: 2, Failures: 0, Skips: 0

    ===============================================
    Default suite
    Total tests run: 2, Failures: 0, Skips: 0

    [TestNG] Time taken by org.testng.reporters.jq.Main@6295d394: 34 ms
    [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
    [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@78b1cc93: 12 ms
    [TestNG] Time taken by org.testng.reporters.XMLReporter@7c417213: 4 ms
    [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@3bd40a57: 3 ms
    [TestNG] Time taken by org.testng.reporters.EmailableReporter2@5e4c8041: 3 ms

  20. wangjia2016 commented on Mar 14, 2017

    @wangjia2016

    @yiyi910
    这个name为"菜单"的一级菜单subButtons确实为空集合.

    我这也发现了这个问题,的确为空,不过我暂时还没用到个性化菜单

    qq 20170314092844

  21. binarywang commented on Mar 14, 2017

    @binarywang
    Owner

    感谢二位细心调试,我也试了下,确实是有问题,稍后修复下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions