新增菜单测试用例

master
星期八 5 years ago
parent e03574fa8d
commit bb300015cb
  1. 31
      src/main/java/com/lq/wechat/util/MenuUtil.java
  2. 33
      src/test/java/com/lq/wechat/util/MenuUtilTest.java

@ -11,9 +11,13 @@ import com.lq.wechat.mode.menu.WechatMenuCofig;
* @date 2018/6/1 * @date 2018/6/1
*/ */
public class MenuUtil { 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 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"; 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){ public static String createMenu(String accessToken,String wechatMenuStr){
String url = CREATE_MENU_URL.replace("ACCESS_TOKEN",accessToken); String url = CREATE_MENU_URL.replace("ACCESS_TOKEN",accessToken);
String resultStr = HttpKit.post(url,wechatMenuStr); String resultStr = HttpKit.post(url,wechatMenuStr);
return resultStr; 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 * @param
*/ */
public static WechatMenuCofig selectMenu(String accessToken){ public static WechatMenuCofig selectMenu(String accessToken){
String url = SELECT_MENU_URL.replace("ACCESS_TOKEN",accessToken); String url = SELECT_MENU_URL.replace("ACCESS_TOKEN",accessToken);
String resultStr = HttpKit.get(url); String resultStr = HttpKit.get(url);
System.out.println(resultStr);
WechatMenuCofig wechatMenuCofig = JSON.parseObject(resultStr,WechatMenuCofig.class); WechatMenuCofig wechatMenuCofig = JSON.parseObject(resultStr,WechatMenuCofig.class);
System.out.println(wechatMenuCofig.getMenu().getButton().get(0).getName());
return wechatMenuCofig; return wechatMenuCofig;
} }

@ -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);
}
}
Loading…
Cancel
Save