实现获取自定义菜单配置的接口 for #70

This commit is contained in:
Binary Wang
2016-11-25 16:31:59 +08:00
parent fd4505d606
commit 95821dab20
6 changed files with 389 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
/**
* 菜单相关操作接口
@@ -56,4 +57,20 @@ public interface WxMpMenuService {
*/
WxMenu menuTryMatch(String userid) throws WxErrorException;
/**
* <pre>
* 获取自定义菜单配置接口
* 本接口将会提供公众号当前使用的自定义菜单的配置如果公众号是通过API调用设置的菜单则返回菜单的开发配置而如果公众号是在公众平台官网通过网站功能发布菜单则本接口返回运营者设置的菜单配置。
请注意:
1、第三方平台开发者可以通过本接口在旗下公众号将业务授权给你后立即通过本接口检测公众号的自定义菜单配置并通过接口再次给公众号设置好自动回复规则以提升公众号运营者的业务体验。
2、本接口与自定义菜单查询接口的不同之处在于本接口无论公众号的接口是如何设置的都能查询到接口而自定义菜单查询接口则仅能查询到使用API设置的菜单配置。
3、认证/未认证的服务号/订阅号,以及接口测试号,均拥有该接口权限。
4、从第三方平台的公众号登录授权机制上来说该接口从属于消息与菜单权限集。
5、本接口中返回的图片/语音/视频为临时素材临时素材每次获取都不同3天内有效通过素材管理-获取临时素材接口来获取这些素材),本接口返回的图文消息为永久素材素材(通过素材管理-获取永久素材接口来获取这些素材)。
* 接口调用请求说明:
http请求方式: GET请使用https协议
https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=ACCESS_TOKEN
*</pre>
*/
WxMpGetSelfMenuInfoResult getSelfMenuInfo() throws WxErrorException;
}

View File

@@ -1,12 +1,13 @@
package me.chanjar.weixin.mp.api.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpMenuService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
import me.chanjar.weixin.mp.bean.menu.WxMpSelfMenuInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by Binary Wang on 2016/7/21.
@@ -14,7 +15,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
public class WxMpMenuServiceImpl implements WxMpMenuService {
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/menu";
private static Logger log = LoggerFactory
.getLogger(WxMpMenuServiceImpl.class);
.getLogger(WxMpMenuServiceImpl.class);
private WxMpService wxMpService;
@@ -74,10 +75,17 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
} catch (WxErrorException e) {
// 46003 不存在的菜单数据 46002 不存在的菜单版本
if (e.getError().getErrorCode() == 46003
|| e.getError().getErrorCode() == 46002) {
|| e.getError().getErrorCode() == 46002) {
return null;
}
throw e;
}
}
@Override
public WxMpGetSelfMenuInfoResult getSelfMenuInfo() throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info";
String resultContent = this.wxMpService.get(url, null);
return WxMpGetSelfMenuInfoResult.fromJson(resultContent);
}
}