From bb300015cb34d9a778662239f9ed5ea898645ec5 Mon Sep 17 00:00:00 2001 From: qi Date: Tue, 5 May 2020 21:20:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8F=9C=E5=8D=95=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lq/wechat/util/MenuUtil.java | 31 ++++++++++------- .../java/com/lq/wechat/util/MenuUtilTest.java | 33 +++++++++++++++++++ 2 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 src/test/java/com/lq/wechat/util/MenuUtilTest.java diff --git a/src/main/java/com/lq/wechat/util/MenuUtil.java b/src/main/java/com/lq/wechat/util/MenuUtil.java index 0e4d810..3ce3b28 100755 --- a/src/main/java/com/lq/wechat/util/MenuUtil.java +++ b/src/main/java/com/lq/wechat/util/MenuUtil.java @@ -11,9 +11,13 @@ import com.lq.wechat.mode.menu.WechatMenuCofig; * @date 2018/6/1 */ public class MenuUtil { - + /** + * 创建菜单 + */ public static final String CREATE_MENU_URL = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN"; - + /** + * 查询菜单 + */ public static final String SELECT_MENU_URL = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN"; /** @@ -30,29 +34,32 @@ public class MenuUtil { public static String createMenu(String accessToken,String wechatMenuStr){ String url = CREATE_MENU_URL.replace("ACCESS_TOKEN",accessToken); - String resultStr = HttpKit.post(url,wechatMenuStr); - return resultStr; } + + /** + * 查询自定义菜单 + * @param accessToken + * @return + */ + public static String selectMenuStr(String accessToken){ + String url = SELECT_MENU_URL.replace("ACCESS_TOKEN",accessToken); + String resultStr = HttpKit.get(url); + + return resultStr; + } + /** * 查询自定义菜单 * @param */ public static WechatMenuCofig selectMenu(String accessToken){ - String url = SELECT_MENU_URL.replace("ACCESS_TOKEN",accessToken); - String resultStr = HttpKit.get(url); - - System.out.println(resultStr); - WechatMenuCofig wechatMenuCofig = JSON.parseObject(resultStr,WechatMenuCofig.class); - - System.out.println(wechatMenuCofig.getMenu().getButton().get(0).getName()); - return wechatMenuCofig; } diff --git a/src/test/java/com/lq/wechat/util/MenuUtilTest.java b/src/test/java/com/lq/wechat/util/MenuUtilTest.java new file mode 100644 index 0000000..812b95d --- /dev/null +++ b/src/test/java/com/lq/wechat/util/MenuUtilTest.java @@ -0,0 +1,33 @@ +package com.lq.wechat.util; + + +import com.lq.BaseTest; +import com.lq.entity.WechatInfo; +import com.lq.wechat.mode.menu.WechatMenuCofig; +import com.lq.wechat.util.token.AccessTokenUtil; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class MenuUtilTest extends BaseTest { + + @Autowired + private AccessTokenUtil accessTokenUtil; + + public void testCreateMenu() { + + } + + public void testTestCreateMenu() { + } + + @Test + public void testSelectMenu() { + WechatInfo wechatInfo = new WechatInfo(); + wechatInfo.setAppId("wx76ca7130852c4baa"); + wechatInfo.setAppSecpet("d87125562b8e60618bc7b3120dfe3583"); + wechatInfo.setWechatOpenId("gh_50ba8d7a5efc"); + String token = accessTokenUtil.getAccessToken(wechatInfo); + WechatMenuCofig wechatMenuCofig = MenuUtil.selectMenu(token); + + } +} \ No newline at end of file