mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-26 10:49:24 +08:00
菜单接口支持
This commit is contained in:
@@ -107,17 +107,17 @@ public class WxCpServiceImpl implements WxCpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void menuCreate(WxCpMenu menu) throws WxErrorException {
|
public void menuCreate(WxCpMenu menu) throws WxErrorException {
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/menu/create";
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=" + wxCpConfigStorage.getAgentId();
|
||||||
execute(new SimplePostRequestExecutor(), url, menu.toJson());
|
execute(new SimplePostRequestExecutor(), url, menu.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void menuDelete() throws WxErrorException {
|
public void menuDelete() throws WxErrorException {
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/menu/delete";
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=" + wxCpConfigStorage.getAgentId();
|
||||||
execute(new SimpleGetRequestExecutor(), url, null);
|
execute(new SimpleGetRequestExecutor(), url, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WxCpMenu menuGet() throws WxErrorException {
|
public WxCpMenu menuGet() throws WxErrorException {
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/menu/get";
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + wxCpConfigStorage.getAgentId();
|
||||||
try {
|
try {
|
||||||
String resultContent = execute(new SimpleGetRequestExecutor(), url, null);
|
String resultContent = execute(new SimpleGetRequestExecutor(), url, null);
|
||||||
return WxCpMenu.fromJson(resultContent);
|
return WxCpMenu.fromJson(resultContent);
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ public class WxCpMenuGsonAdapter implements JsonSerializer<WxCpMenu>, JsonDeseri
|
|||||||
* 查询菜单时是 { menu : { button : ... } }
|
* 查询菜单时是 { menu : { button : ... } }
|
||||||
*/
|
*/
|
||||||
WxCpMenu menu = new WxCpMenu();
|
WxCpMenu menu = new WxCpMenu();
|
||||||
JsonArray buttonsJson = json.getAsJsonObject().get("button").getAsJsonArray();
|
JsonObject menuJson = json.getAsJsonObject().get("menu").getAsJsonObject();
|
||||||
|
JsonArray buttonsJson = menuJson.get("button").getAsJsonArray();
|
||||||
for (int i = 0; i < buttonsJson.size(); i++) {
|
for (int i = 0; i < buttonsJson.size(); i++) {
|
||||||
JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
|
JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
|
||||||
WxCpMenu.WxMenuButton button = convertFromJson(buttonJson);
|
WxCpMenu.WxMenuButton button = convertFromJson(buttonJson);
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import me.chanjar.weixin.enterprise.exception.WxErrorException;
|
|||||||
* @author Daniel Qian
|
* @author Daniel Qian
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test(groups="menuAPI", dependsOnGroups="baseAPI")
|
//@Test(groups="menuAPI", dependsOnGroups="baseAPI")
|
||||||
|
@Test
|
||||||
@Guice(modules = ApiTestModule.class)
|
@Guice(modules = ApiTestModule.class)
|
||||||
public class WxCpMenuAPITest {
|
public class WxCpMenuAPITest {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user