fixed #65
This commit is contained in:
@@ -19,10 +19,11 @@ import com.foxinmy.weixin4j.mp.model.SemQuery;
|
||||
import com.foxinmy.weixin4j.mp.model.SemResult;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.type.ButtonType;
|
||||
|
||||
/**
|
||||
* 辅助相关API
|
||||
*
|
||||
*
|
||||
* @className HelperApi
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年9月26日
|
||||
@@ -39,7 +40,7 @@ public class HelperApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 长链接转短链接
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* 待转换的链接
|
||||
* @return 短链接
|
||||
@@ -62,7 +63,7 @@ public class HelperApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 语义理解
|
||||
*
|
||||
*
|
||||
* @param semQuery
|
||||
* 语义理解协议
|
||||
* @return 语义理解结果
|
||||
@@ -84,7 +85,7 @@ public class HelperApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 获取微信服务器IP地址
|
||||
*
|
||||
*
|
||||
* @return IP地址
|
||||
* @see <a
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140187&token=&lang=zh_CN">获取IP地址</a>
|
||||
@@ -93,8 +94,8 @@ public class HelperApi extends MpApi {
|
||||
public List<String> getWechatServerIp() throws WeixinException {
|
||||
String getcallbackip_uri = getRequestUri("getcallbackip_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(getcallbackip_uri,
|
||||
token.getAccessToken()));
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
getcallbackip_uri, token.getAccessToken()));
|
||||
return JSON.parseArray(response.getAsJson().getString("ip_list"),
|
||||
String.class);
|
||||
}
|
||||
@@ -102,7 +103,7 @@ public class HelperApi extends MpApi {
|
||||
/**
|
||||
* 获取公众号当前使用的自定义菜单的配置,如果公众号是通过API调用设置的菜单,则返回菜单的开发配置,
|
||||
* 而如果公众号是在公众平台官网通过网站功能发布菜单,则本接口返回运营者设置的菜单配置。
|
||||
*
|
||||
*
|
||||
* @return 菜单集合
|
||||
* @see {@link MenuApi#getMenu()}
|
||||
* @see <a
|
||||
@@ -115,10 +116,9 @@ public class HelperApi extends MpApi {
|
||||
public MenuSetting getMenuSetting() throws WeixinException {
|
||||
String menu_get_selfmenu_uri = getRequestUri("menu_get_selfmenu_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(menu_get_selfmenu_uri,
|
||||
token.getAccessToken()));
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
menu_get_selfmenu_uri, token.getAccessToken()));
|
||||
JSONObject result = response.getAsJson();
|
||||
|
||||
JSONArray buttons = result.getJSONObject("selfmenu_info").getJSONArray(
|
||||
"button");
|
||||
List<Button> buttonList = new ArrayList<Button>(buttons.size());
|
||||
@@ -128,6 +128,7 @@ public class HelperApi extends MpApi {
|
||||
if (buttonObj.containsKey("sub_button")) {
|
||||
JSONPath.set(buttonObj, "$.sub_button", buttonObj
|
||||
.getJSONObject("sub_button").getJSONArray("list"));
|
||||
buttonObj.put("type", ButtonType.popups);
|
||||
}
|
||||
buttonList.add(JSON.parseObject(buttonObj.toJSONString(),
|
||||
Button.class, ButtonExtraProcessor.global));
|
||||
@@ -147,9 +148,15 @@ public class HelperApi extends MpApi {
|
||||
if (key.equals("news_info")) {
|
||||
JSONArray news = ((JSONObject) value).getJSONArray("list");
|
||||
List<MpArticle> newsList = new ArrayList<MpArticle>(news.size());
|
||||
JSONObject article = null;
|
||||
for (int i = 0; i < news.size(); i++) {
|
||||
newsList.add(JSON.parseObject(news.getString(i),
|
||||
MpArticle.class, ArticleExtraProcessor.global));
|
||||
article = news.getJSONObject(i);
|
||||
article.put("showCoverPic", article.remove("show_cover"));
|
||||
article.put("coverUrl", article.remove("cover_url"));
|
||||
article.put("contentUrl", article.remove("content_url"));
|
||||
article.put("sourceUrl", article.remove("source_url"));
|
||||
newsList.add(JSON.parseObject(article.toJSONString(),
|
||||
MpArticle.class));
|
||||
}
|
||||
JSONPath.set(object, "$.content", newsList);
|
||||
} else {
|
||||
@@ -158,28 +165,9 @@ public class HelperApi extends MpApi {
|
||||
}
|
||||
};
|
||||
|
||||
private static final class ArticleExtraProcessor implements ExtraProcessor {
|
||||
private static final ArticleExtraProcessor global = new ArticleExtraProcessor();
|
||||
|
||||
private ArticleExtraProcessor() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processExtra(Object object, String key, Object value) {
|
||||
MpArticle mpArticle = (MpArticle) object;
|
||||
if (key.equals("show_cover")) {
|
||||
mpArticle.setShowCoverPic(value.equals("1"));
|
||||
}
|
||||
if (key.equals("source_url")) {
|
||||
mpArticle.setSourceUrl(value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公众号当前使用的自动回复规则,包括关注后自动回复、消息自动回复(60分钟内触发一次)、关键词自动回复。
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.model.AutoReplySetting
|
||||
* @see <a
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751299&token=&lang=zh_CN">获取自动回复规则</a>
|
||||
|
||||
+10
-1
@@ -9,7 +9,16 @@ import org.junit.Test;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.mp.api.HelperApi;
|
||||
|
||||
public class HelpTest extends TokenTest {
|
||||
/**
|
||||
* 辅助API测试
|
||||
*
|
||||
* @className HelperTest
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年5月24日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class HelperTest extends TokenTest {
|
||||
private HelperApi helperApi;
|
||||
|
||||
@Before
|
||||
Reference in New Issue
Block a user