新增MessageConverter

This commit is contained in:
jinyu
2016-07-21 14:44:28 +08:00
parent f62985f69d
commit 57669927a7
66 changed files with 1210 additions and 968 deletions
@@ -5,7 +5,7 @@ import java.util.Date;
import java.util.List;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.model.Button;
import com.foxinmy.weixin4j.model.MediaCounter;
import com.foxinmy.weixin4j.model.MediaDownloadResult;
@@ -370,7 +370,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738732&token=&lang=zh_CN">
* 更新永久图文素材</a>
*/
public JsonResult updateMaterialArticle(String mediaId, int index,
public ApiResult updateMaterialArticle(String mediaId, int index,
MpArticle article) throws WeixinException {
return mediaApi.updateMaterialArticle(mediaId, index, article);
}
@@ -387,7 +387,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738731&token=&lang=zh_CN">
* 删除永久媒体素材</a>
*/
public JsonResult deleteMaterialMedia(String mediaId)
public ApiResult deleteMaterialMedia(String mediaId)
throws WeixinException {
return mediaApi.deleteMaterialMedia(mediaId);
}
@@ -478,7 +478,7 @@ public class WeixinProxy {
* @see {@link #sendNotify(NotifyMessage,String) }
* @throws WeixinException
*/
public JsonResult sendNotify(NotifyMessage notify) throws WeixinException {
public ApiResult sendNotify(NotifyMessage notify) throws WeixinException {
return notifyApi.sendNotify(notify);
}
@@ -502,7 +502,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.tuple.News
* @see com.foxinmy.weixin4j.mp.api.NotifyApi
*/
public JsonResult sendNotify(NotifyMessage notify, String kfAccount)
public ApiResult sendNotify(NotifyMessage notify, String kfAccount)
throws WeixinException {
return notifyApi.sendNotify(notify, kfAccount);
}
@@ -568,7 +568,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 新增客服账号</a>
*/
public JsonResult createKfAccount(String id, String name, String pwd)
public ApiResult createKfAccount(String id, String name, String pwd)
throws WeixinException {
return customApi.createKfAccount(id, name, pwd);
}
@@ -590,7 +590,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 更新客服账号</a>
*/
public JsonResult updateKfAccount(String id, String name, String pwd)
public ApiResult updateKfAccount(String id, String name, String pwd)
throws WeixinException {
return customApi.updateKfAccount(id, name, pwd);
}
@@ -611,7 +611,7 @@ public class WeixinProxy {
* >邀请绑定客服帐号<a/>
* @throws WeixinException
*/
public JsonResult inviteKfAccount(String kfAccount, String inviteAccount)
public ApiResult inviteKfAccount(String kfAccount, String inviteAccount)
throws WeixinException {
return customApi.inviteKfAccount(kfAccount, inviteAccount);
}
@@ -632,7 +632,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 上传客服头像</a>
*/
public JsonResult uploadKfAvatar(String accountId, InputStream is,
public ApiResult uploadKfAvatar(String accountId, InputStream is,
String fileName) throws WeixinException {
return customApi.uploadKfAvatar(accountId, is, fileName);
}
@@ -649,7 +649,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 删除客服账号</a>
*/
public JsonResult deleteKfAccount(String id) throws WeixinException {
public ApiResult deleteKfAccount(String id) throws WeixinException {
return customApi.deleteKfAccount(id);
}
@@ -673,7 +673,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 创建会话</a>
*/
public JsonResult createKfSession(String userOpenId, String kfAccount,
public ApiResult createKfSession(String userOpenId, String kfAccount,
String text) throws WeixinException {
return customApi.createKfSession(userOpenId, kfAccount, text);
}
@@ -694,7 +694,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044820&token=&lang=zh_CN">
* 关闭会话</a>
*/
public JsonResult closeKfSession(String userOpenId, String kfAccount,
public ApiResult closeKfSession(String userOpenId, String kfAccount,
String text) throws WeixinException {
return customApi.closeKfSession(userOpenId, kfAccount, text);
}
@@ -891,7 +891,7 @@ public class WeixinProxy {
* @see {@link #massByOpenIds(Tuple, String...)
*
*/
*/
public ApiResult deleteMassNews(String msgid) throws WeixinException {
return massApi.deleteMassNews(msgid);
}
@@ -912,7 +912,7 @@ public class WeixinProxy {
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN">
* 预览群发消息</a>
*/
*/
public ApiResult previewMassNews(String toUser, String toWxName,
MassTuple tuple) throws WeixinException {
return massApi.previewMassNews(toUser, toWxName, tuple);
@@ -1109,7 +1109,7 @@ public class WeixinProxy {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140838&token=&lang=zh_CN">
* 设置用户备注名</a>
* @see com.foxinmy.weixin4j.mp.api.UserApi
*/
*/
public ApiResult remarkUserName(String openId, String remark)
throws WeixinException {
return userApi.remarkUserName(openId, remark);
@@ -1178,7 +1178,7 @@ public class WeixinProxy {
* 修改分组名</a>
* @see com.foxinmy.weixin4j.mp.model.Group
* @see com.foxinmy.weixin4j.mp.api.GroupApi
*/
*/
public ApiResult modifyGroup(int groupId, String name)
throws WeixinException {
return groupApi.modifyGroup(groupId, name);
@@ -1197,7 +1197,7 @@ public class WeixinProxy {
* 移动分组</a>
* @see com.foxinmy.weixin4j.mp.model.Group
* @see com.foxinmy.weixin4j.mp.api.GroupApi
*/
*/
public ApiResult moveGroup(int groupId, String openId)
throws WeixinException {
return groupApi.moveGroup(groupId, openId);
@@ -1216,7 +1216,7 @@ public class WeixinProxy {
* 批量移动分组</a>
* @see com.foxinmy.weixin4j.mp.model.Group
* @see com.foxinmy.weixin4j.mp.api.GroupApi
*/
*/
public ApiResult moveGroup(int groupId, String... openIds)
throws WeixinException {
return groupApi.moveGroup(groupId, openIds);
@@ -1233,7 +1233,7 @@ public class WeixinProxy {
* 删除用户分组</a>
* @see com.foxinmy.weixin4j.mp.model.Group
* @see com.foxinmy.weixin4j.mp.api.GroupApi
*/
*/
public ApiResult deleteGroup(int groupId) throws WeixinException {
return groupApi.deleteGroup(groupId);
}
@@ -1250,7 +1250,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.model.Button
* @see com.foxinmy.weixin4j.type.ButtonType
* @see com.foxinmy.weixin4j.mp.api.MenuApi
*/
*/
public ApiResult createMenu(List<Button> buttons) throws WeixinException {
return menuApi.createMenu(buttons);
}
@@ -1298,7 +1298,7 @@ public class WeixinProxy {
* 删除菜单</a>
* @see com.foxinmy.weixin4j.mp.api.MenuApi
* @return 处理结果
*/
*/
public ApiResult deleteMenu() throws WeixinException {
return menuApi.deleteMenu();
}
@@ -1332,7 +1332,7 @@ public class WeixinProxy {
* 删除个性化菜单</a>
* @see com.foxinmy.weixin4j.mp.api.MenuApi
* @return 处理结果
*/
*/
public ApiResult deleteCustomMenu(String menuId) throws WeixinException {
return menuApi.deleteCustomMenu(menuId);
}
@@ -1384,7 +1384,7 @@ public class WeixinProxy {
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">
* 设置所处行业</a>
*/
*/
public ApiResult setTmplIndustry(IndustryType... industryTypes)
throws WeixinException {
return tmplApi.setTmplIndustry(industryTypes);
@@ -1432,7 +1432,7 @@ public class WeixinProxy {
* 删除模板</a>
* @see com.foxinmy.weixin4j.mp.api.TmplApi
* @throws WeixinException
*/
*/
public ApiResult deleteTemplate(String templateId) throws WeixinException {
return tmplApi.deleteTemplate(templateId);
}
@@ -1453,7 +1453,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.mp.message.TemplateMessage
* @seee com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
* @see com.foxinmy.weixin4j.mp.api.TmplApi
*/
*/
public ApiResult sendTmplMessage(TemplateMessage tplMessage)
throws WeixinException {
return tmplApi.sendTmplMessage(tplMessage);
@@ -1518,7 +1518,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.mp.api.HelperApi
* @return 操作结果
* @throws WeixinException
*/
*/
public ApiResult clearQuota() throws WeixinException {
return helperApi.clearQuota(getWeixinAccount().getId());
}
@@ -1687,7 +1687,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.mp.model.Tag
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">更新标签</a>
*/
*/
public ApiResult updateTag(Tag tag) throws WeixinException {
return tagApi.updateTag(tag);
}
@@ -1702,7 +1702,7 @@ public class WeixinProxy {
* @throws WeixinException
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">删除标签</a>
*/
*/
public ApiResult deleteTag(int tagId) throws WeixinException {
return tagApi.deleteTag(tagId);
}
@@ -1719,7 +1719,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.mp.api.TagApi
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">批量为用户打标签</a>
*/
*/
public ApiResult taggingUsers(int tagId, String... openIds)
throws WeixinException {
return tagApi.taggingUsers(tagId, openIds);
@@ -1737,7 +1737,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.mp.api.TagApi
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">批量为用户取消标签</a>
*/
*/
public ApiResult untaggingUsers(int tagId, String... openIds)
throws WeixinException {
return tagApi.untaggingUsers(tagId, openIds);
@@ -7,7 +7,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.mp.component.WeixinComponentPreCodeCreator;
@@ -222,7 +222,7 @@ public class ComponentApi extends MpApi {
* @see com.foxinmy.weixin4j.mp.model.AuthorizerOption
* @throws WeixinException
*/
public JsonResult setAuthorizerOption(String authAppId,
public ApiResult setAuthorizerOption(String authAppId,
AuthorizerOption option) throws WeixinException {
String component_set_authorizer_option_uri = getRequestUri("component_set_authorizer_option_uri");
JSONObject obj = new JSONObject();
@@ -233,6 +233,6 @@ public class ComponentApi extends MpApi {
WeixinResponse response = weixinExecutor.post(
String.format(component_set_authorizer_option_uri,
tokenManager.getAccessToken()), obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -9,10 +9,10 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.ContentType;
import com.foxinmy.weixin4j.http.MimeType;
import com.foxinmy.weixin4j.http.apache.FormBodyPart;
import com.foxinmy.weixin4j.http.apache.InputStreamBody;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Pageable;
import com.foxinmy.weixin4j.model.Token;
@@ -130,7 +130,7 @@ public class CustomApi extends MpApi {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 新增客服账号</a>
*/
public JsonResult createKfAccount(String id, String name, String pwd) throws WeixinException {
public ApiResult createKfAccount(String id, String name, String pwd) throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("kf_account", id);
obj.put("nickname", name);
@@ -139,7 +139,7 @@ public class CustomApi extends MpApi {
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(kf_create_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -158,7 +158,7 @@ public class CustomApi extends MpApi {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 新增客服账号</a>
*/
public JsonResult updateKfAccount(String id, String name, String pwd) throws WeixinException {
public ApiResult updateKfAccount(String id, String name, String pwd) throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("kf_account", id);
obj.put("nickname", name);
@@ -167,7 +167,7 @@ public class CustomApi extends MpApi {
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(kf_update_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -185,7 +185,7 @@ public class CustomApi extends MpApi {
* >邀请绑定客服帐号<a/>
* @throws WeixinException
*/
public JsonResult inviteKfAccount(String kfAccount, String inviteAccount) throws WeixinException {
public ApiResult inviteKfAccount(String kfAccount, String inviteAccount) throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("kf_account", kfAccount);
obj.put("invite_wx", inviteAccount);
@@ -193,7 +193,7 @@ public class CustomApi extends MpApi {
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(kf_invite_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -211,19 +211,20 @@ public class CustomApi extends MpApi {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 上传客服头像</a>
*/
public JsonResult uploadKfAvatar(String accountId, InputStream is, String fileName) throws WeixinException {
public ApiResult uploadKfAvatar(String accountId, InputStream is, String fileName) throws WeixinException {
if (StringUtil.isBlank(fileName)) {
fileName = ObjectId.get().toHexString();
}
if (StringUtil.isBlank(FileUtil.getFileExtension(fileName))) {
fileName = String.format("%s.jpg", fileName);
}
MimeType mimeType = new MimeType("image", FileUtil.getFileExtension(fileName));
Token token = tokenManager.getCache();
String kf_avatar_uri = getRequestUri("kf_avatar_uri");
WeixinResponse response = weixinExecutor.post(String.format(kf_avatar_uri, token.getAccessToken(), accountId),
new FormBodyPart("media", new InputStreamBody(is, ContentType.IMAGE_JPG.getMimeType(), fileName)));
new FormBodyPart("media", new InputStreamBody(is, mimeType.toString(), fileName)));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -237,12 +238,12 @@ public class CustomApi extends MpApi {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">
* 删除客服账号</a>
*/
public JsonResult deleteKfAccount(String id) throws WeixinException {
public ApiResult deleteKfAccount(String id) throws WeixinException {
Token token = tokenManager.getCache();
String kf_delete_uri = getRequestUri("kf_delete_uri");
WeixinResponse response = weixinExecutor.get(String.format(kf_delete_uri, token.getAccessToken(), id));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -264,7 +265,7 @@ public class CustomApi extends MpApi {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044820&token=&lang=zh_CN">
* 创建会话</a>
*/
public JsonResult createKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
public ApiResult createKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
Token token = tokenManager.getCache();
String kfsession_create_uri = getRequestUri("kfsession_create_uri");
JSONObject obj = new JSONObject();
@@ -274,7 +275,7 @@ public class CustomApi extends MpApi {
WeixinResponse response = weixinExecutor.post(String.format(kfsession_create_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -292,7 +293,7 @@ public class CustomApi extends MpApi {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044820&token=&lang=zh_CN">
* 关闭会话</a>
*/
public JsonResult closeKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
public ApiResult closeKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
Token token = tokenManager.getCache();
String kfsession_close_uri = getRequestUri("kfsession_close_uri");
JSONObject obj = new JSONObject();
@@ -302,7 +303,7 @@ public class CustomApi extends MpApi {
WeixinResponse response = weixinExecutor.post(String.format(kfsession_close_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -5,7 +5,7 @@ import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.mp.model.Group;
@@ -104,7 +104,7 @@ public class GroupApi extends MpApi {
* @see com.foxinmy.weixin4j.mp.model.Group
* @see com.foxinmy.weixin4j.mp.model.Group#toModifyJson()
*/
public JsonResult modifyGroup(int groupId, String name)
public ApiResult modifyGroup(int groupId, String name)
throws WeixinException {
String group_modify_uri = getRequestUri("group_modify_uri");
Token token = tokenManager.getCache();
@@ -113,7 +113,7 @@ public class GroupApi extends MpApi {
WeixinResponse response = weixinExecutor.post(
String.format(group_modify_uri, token.getAccessToken()),
group.toModifyJson());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -128,7 +128,7 @@ public class GroupApi extends MpApi {
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">移动分组</a>
* @see com.foxinmy.weixin4j.mp.model.Group
*/
public JsonResult moveGroup(int groupId, String openId)
public ApiResult moveGroup(int groupId, String openId)
throws WeixinException {
String group_move_uri = getRequestUri("group_move_uri");
Token token = tokenManager.getCache();
@@ -136,7 +136,7 @@ public class GroupApi extends MpApi {
token.getAccessToken()), String.format(
"{\"openid\":\"%s\",\"to_groupid\":%d}", openId, groupId));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -151,7 +151,7 @@ public class GroupApi extends MpApi {
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">批量移动分组</a>
* @see com.foxinmy.weixin4j.mp.model.Group
*/
public JsonResult moveGroup(int groupId, String... openIds)
public ApiResult moveGroup(int groupId, String... openIds)
throws WeixinException {
String group_batchmove_uri = getRequestUri("group_batchmove_uri");
Token token = tokenManager.getCache();
@@ -162,7 +162,7 @@ public class GroupApi extends MpApi {
String.format(group_batchmove_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -175,13 +175,13 @@ public class GroupApi extends MpApi {
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">删除用户分组</a>
* @see com.foxinmy.weixin4j.mp.model.Group
*/
public JsonResult deleteGroup(int groupId) throws WeixinException {
public ApiResult deleteGroup(int groupId) throws WeixinException {
String group_delete_uri = getRequestUri("group_delete_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(
String.format(group_delete_uri, token.getAccessToken()),
String.format("{\"group\":{\"id\":%d}}", groupId));
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -10,7 +10,7 @@ import com.alibaba.fastjson.JSONPath;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Button;
import com.foxinmy.weixin4j.model.Token;
@@ -233,12 +233,12 @@ public class HelperApi extends MpApi {
* @return 操作结果
* @throws WeixinException
*/
public JsonResult clearQuota(String appId) throws WeixinException {
public ApiResult clearQuota(String appId) throws WeixinException {
String clearquota_uri = getRequestUri("clearquota_uri");
String body = String.format("{\"appid\":\"%s\"}", appId);
WeixinResponse response = weixinExecutor.post(
String.format(clearquota_uri, tokenManager.getAccessToken()),
body);
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -7,7 +7,7 @@ import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.token.TokenManager;
@@ -224,7 +224,7 @@ public class MassApi extends MpApi {
* @see {@link #massByGroupId(Tuple, int)}
* @see {@link #massByOpenIds(Tuple, String...)
*/
*/
public ApiResult deleteMassNews(String msgid) throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("msgid", msgid);
@@ -233,7 +233,7 @@ public class MassApi extends MpApi {
WeixinResponse response = weixinExecutor.post(
String.format(mass_delete_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsResult();
}
@@ -251,7 +251,7 @@ public class MassApi extends MpApi {
* @see com.foxinmy.weixin4j.tuple.MassTuple
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN">预览群发消息</a>
*/
*/
public ApiResult previewMassNews(String toUser, String toWxName,
MassTuple tuple) throws WeixinException {
String msgtype = tuple.getMessageType();
@@ -265,7 +265,7 @@ public class MassApi extends MpApi {
WeixinResponse response = weixinExecutor.post(
String.format(mass_preview_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsResult();
}
@@ -19,12 +19,14 @@ import com.foxinmy.weixin4j.http.HttpHeaders;
import com.foxinmy.weixin4j.http.HttpMethod;
import com.foxinmy.weixin4j.http.HttpRequest;
import com.foxinmy.weixin4j.http.HttpResponse;
import com.foxinmy.weixin4j.http.MimeType;
import com.foxinmy.weixin4j.http.apache.ByteArrayBody;
import com.foxinmy.weixin4j.http.apache.FormBodyPart;
import com.foxinmy.weixin4j.http.apache.InputStreamBody;
import com.foxinmy.weixin4j.http.apache.StringBody;
import com.foxinmy.weixin4j.http.entity.StringEntity;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.message.JsonMessageConverter;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Consts;
import com.foxinmy.weixin4j.model.MediaCounter;
@@ -71,8 +73,7 @@ public class MediaApi extends MpApi {
* @return 图片URL 可用于群发消息中的图片链接和创建卡券logo链接
* @throws WeixinException
*/
public String uploadImage(InputStream is, String fileName)
throws WeixinException {
public String uploadImage(InputStream is, String fileName) throws WeixinException {
if (StringUtil.isBlank(fileName)) {
fileName = ObjectId.get().toHexString();
}
@@ -80,11 +81,10 @@ public class MediaApi extends MpApi {
fileName = String.format("%s.jpg", fileName);
}
String image_upload_uri = getRequestUri("image_upload_uri");
MimeType mimeType = new MimeType("image", FileUtil.getFileExtension(fileName));
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(
image_upload_uri, token.getAccessToken()),
new FormBodyPart("media", new InputStreamBody(is,
ContentType.IMAGE_JPG.getMimeType(), fileName)));
WeixinResponse response = weixinExecutor.post(String.format(image_upload_uri, token.getAccessToken()),
new FormBodyPart("media", new InputStreamBody(is, mimeType.toString(), fileName)));
return response.getAsJson().getString("url");
}
@@ -101,12 +101,12 @@ public class MediaApi extends MpApi {
* 视频描述 可为空
* @return 群发视频消息对象
* @throws WeixinException
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN">高级群发</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN">高级群发</a>
* @see com.foxinmy.weixin4j.tuple.MpVideo
*/
public MpVideo uploadVideo(InputStream is, String fileName, String title,
String description) throws WeixinException {
public MpVideo uploadVideo(InputStream is, String fileName, String title, String description)
throws WeixinException {
MediaUploadResult uploadResult = uploadMedia(false, is, fileName);
JSONObject obj = new JSONObject();
obj.put("media_id", uploadResult.getMediaId());
@@ -114,8 +114,7 @@ public class MediaApi extends MpApi {
obj.put("description", description);
String video_upload_uri = getRequestUri("video_upload_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(
String.format(video_upload_uri, token.getAccessToken()),
WeixinResponse response = weixinExecutor.post(String.format(video_upload_uri, token.getAccessToken()),
obj.toJSONString());
String mediaId = response.getAsJson().getString("media_id");
@@ -123,8 +122,8 @@ public class MediaApi extends MpApi {
}
/**
* 上传媒体文件:图片(image)、语音(voice)、视频(video)和缩略图(thumb </br> <font
* color="red">此接口只包含图片、语音、缩略图、视频(临时)四种媒体类型的上传</font>
* 上传媒体文件:图片(image)、语音(voice)、视频(video)和缩略图(thumb </br>
* <font color="red">此接口只包含图片、语音、缩略图、视频(临时)四种媒体类型的上传</font>
* <p>
* 正常情况下返回{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789},
* 否则抛出异常.
@@ -137,16 +136,15 @@ public class MediaApi extends MpApi {
* @param fileName
* 文件名
* @return 上传到微信服务器返回的媒体标识
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738726&token=&lang=zh_CN">上传临时素材</a>
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738729&token=&lang=zh_CN">上传永久素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738726&token=&lang=zh_CN">上传临时素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738729&token=&lang=zh_CN">上传永久素材</a>
* @see com.foxinmy.weixin4j.model.MediaUploadResult
* @see com.foxinmy.weixin4j.type.MediaType
* @throws WeixinException
*/
public MediaUploadResult uploadMedia(boolean isMaterial, InputStream is,
String fileName) throws WeixinException {
public MediaUploadResult uploadMedia(boolean isMaterial, InputStream is, String fileName) throws WeixinException {
byte[] content;
try {
content = IOUtil.toByteArray(is);
@@ -158,55 +156,42 @@ public class MediaApi extends MpApi {
}
String suffixName = FileUtil.getFileExtension(fileName);
if (StringUtil.isBlank(suffixName)) {
suffixName = FileUtil
.getFileType(new ByteArrayInputStream(content));
suffixName = FileUtil.getFileType(new ByteArrayInputStream(content));
fileName = String.format("%s.%s", fileName, suffixName);
}
MediaType mediaType;
if (",bmp,png,jpeg,jpg,gif,"
.contains(String.format(",%s,", suffixName))) {
if (",bmp,png,jpeg,jpg,gif,".contains(String.format(",%s,", suffixName))) {
mediaType = MediaType.image;
} else if (",mp3,wma,wav,amr,".contains(String.format(",%s,",
suffixName))) {
} else if (",mp3,wma,wav,amr,".contains(String.format(",%s,", suffixName))) {
mediaType = MediaType.voice;
} else if (",rm,rmvb,wmv,avi,mpg,mpeg,mp4,".contains(String.format(
",%s,", suffixName))) {
} else if (",rm,rmvb,wmv,avi,mpg,mpeg,mp4,".contains(String.format(",%s,", suffixName))) {
mediaType = MediaType.video;
} else {
throw new WeixinException("cannot handle mediaType:" + suffixName);
}
if (mediaType == MediaType.video && isMaterial) {
throw new WeixinException(
"please invoke uploadMaterialVideo method");
throw new WeixinException("please invoke uploadMaterialVideo method");
}
Token token = tokenManager.getCache();
WeixinResponse response = null;
try {
if (isMaterial) {
String material_media_upload_uri = getRequestUri("material_media_upload_uri");
response = weixinExecutor
.post(String.format(material_media_upload_uri,
token.getAccessToken()), new FormBodyPart(
"media", new ByteArrayBody(content, mediaType
.getContentType().getMimeType(),
fileName)), new FormBodyPart("type",
new StringBody(mediaType.name(), Consts.UTF_8)));
response = weixinExecutor.post(String.format(material_media_upload_uri, token.getAccessToken()),
new FormBodyPart("media",
new ByteArrayBody(content, mediaType.getMimeType().toString(), fileName)),
new FormBodyPart("type", new StringBody(mediaType.name(), Consts.UTF_8)));
JSONObject obj = response.getAsJson();
return new MediaUploadResult(obj.getString("media_id"),
mediaType, new Date(), obj.getString("url"));
return new MediaUploadResult(obj.getString("media_id"), mediaType, new Date(), obj.getString("url"));
} else {
String media_upload_uri = getRequestUri("media_upload_uri");
response = weixinExecutor.post(String.format(media_upload_uri,
token.getAccessToken(), mediaType.name()),
new FormBodyPart("media", new InputStreamBody(
new ByteArrayInputStream(content), mediaType
.getContentType().getMimeType(),
fileName)));
response = weixinExecutor.post(
String.format(media_upload_uri, token.getAccessToken(), mediaType.name()),
new FormBodyPart("media", new InputStreamBody(new ByteArrayInputStream(content),
mediaType.getMimeType().toString(), fileName)));
JSONObject obj = response.getAsJson();
return new MediaUploadResult(obj.getString("media_id"),
obj.getObject("type", MediaType.class), new Date(
obj.getLong("created_at") * 1000l),
obj.getString("url"));
return new MediaUploadResult(obj.getString("media_id"), obj.getObject("type", MediaType.class),
new Date(obj.getLong("created_at") * 1000l), obj.getString("url"));
}
} catch (UnsupportedEncodingException e) {
throw new WeixinException(e);
@@ -230,60 +215,45 @@ public class MediaApi extends MpApi {
*
* @throws WeixinException
* @see com.foxinmy.weixin4j.model.MediaDownloadResult
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738727&token=&lang=zh_CN">下载临时媒体素材</a>
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738730&token=&lang=zh_CN">下载永久媒体素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738727&token=&lang=zh_CN">下载临时媒体素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738730&token=&lang=zh_CN">下载永久媒体素材</a>
*/
public MediaDownloadResult downloadMedia(String mediaId, boolean isMaterial)
throws WeixinException {
public MediaDownloadResult downloadMedia(String mediaId, boolean isMaterial) throws WeixinException {
Token token = tokenManager.getCache();
try {
HttpRequest request = null;
if (isMaterial) {
String material_media_download_uri = getRequestUri("material_media_download_uri");
request = new HttpRequest(HttpMethod.POST, String.format(
material_media_download_uri, token.getAccessToken()));
request.setEntity(new StringEntity(String.format(
"{\"media_id\":\"%s\"}", mediaId)));
request = new HttpRequest(HttpMethod.POST,
String.format(material_media_download_uri, token.getAccessToken()));
request.setEntity(new StringEntity(String.format("{\"media_id\":\"%s\"}", mediaId)));
} else {
String meida_download_uri = getRequestUri("meida_download_uri");
request = new HttpRequest(HttpMethod.GET, String.format(
meida_download_uri, token.getAccessToken(), mediaId));
request = new HttpRequest(HttpMethod.GET,
String.format(meida_download_uri, token.getAccessToken(), mediaId));
}
request.setParams(weixinExecutor.getExecuteParams());
logger.info("weixin request >> " + request.getMethod() + " "
+ request.getURI().toString());
HttpResponse response = weixinExecutor.getExecuteClient().execute(
request);
logger.info("weixin request >> " + request.getMethod() + " " + request.getURI().toString());
HttpResponse response = weixinExecutor.getExecuteClient().execute(request);
byte[] content = IOUtil.toByteArray(response.getBody());
HttpHeaders headers = response.getHeaders();
String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE);
String disposition = headers
.getFirst(HttpHeaders.CONTENT_DISPOSITION);
logger.info("weixin response << " + response.getProtocol()
+ response.getStatus().toString() + "[" + contentType
+ "]->" + disposition);
if (contentType.contains(ContentType.TEXT_PLAIN.getMimeType())
|| contentType.contains(ContentType.APPLICATION_JSON
.getMimeType())
|| (disposition != null && disposition.indexOf(".json") > 0)) {
JsonResult jsonResult = JSON.parseObject(content, 0,
content.length, Consts.UTF_8.newDecoder(),
JsonResult.class);
if (jsonResult.getCode() != 0) {
throw new WeixinException(Integer.toString(jsonResult
.getCode()), jsonResult.getDesc());
String disposition = headers.getFirst(HttpHeaders.CONTENT_DISPOSITION);
logger.info("weixin response << " + response.getProtocol() + response.getStatus().toString() + "["
+ contentType + "]->" + disposition);
if (JsonMessageConverter.GLOBAL.canConvert(ApiResult.class, response)) {
ApiResult result = JsonMessageConverter.GLOBAL.convert(ApiResult.class, response);
if (!"0".equals(result.getReturnCode())) {
throw new WeixinException(result.getReturnCode(), result.getReturnMsg());
}
}
String fileName = RegexUtil
.regexFileNameFromContentDispositionHeader(disposition);
String fileName = RegexUtil.regexFileNameFromContentDispositionHeader(disposition);
if (StringUtil.isBlank(fileName)) {
fileName = String.format("%s.%s", mediaId,
contentType.split("/")[1]);
fileName = String.format("%s.%s", mediaId, contentType.split("/")[1]);
}
return new MediaDownloadResult(content,
ContentType.create(contentType), fileName);
return new MediaDownloadResult(content, ContentType.create(contentType), fileName);
} catch (IOException e) {
throw new WeixinException("I/O Error on getBody", e);
} catch (HttpClientException e) {
@@ -302,19 +272,17 @@ public class MediaApi extends MpApi {
* 图文列表
* @return 上传到微信服务器返回的媒体标识
* @throws WeixinException
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738729&token=&lang=zh_CN">上传永久媒体素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738729&token=&lang=zh_CN">上传永久媒体素材</a>
* @see com.foxinmy.weixin4j.tuple.MpArticle
*/
public String uploadMaterialArticle(List<MpArticle> articles)
throws WeixinException {
public String uploadMaterialArticle(List<MpArticle> articles) throws WeixinException {
Token token = tokenManager.getCache();
String material_article_upload_uri = getRequestUri("material_article_upload_uri");
JSONObject obj = new JSONObject();
obj.put("articles", articles);
WeixinResponse response = weixinExecutor.post(
String.format(material_article_upload_uri,
token.getAccessToken()), obj.toJSONString());
WeixinResponse response = weixinExecutor
.post(String.format(material_article_upload_uri, token.getAccessToken()), obj.toJSONString());
return response.getAsJson().getString("media_id");
}
@@ -329,12 +297,10 @@ public class MediaApi extends MpApi {
* @see {@link #downloadMedia(String, boolean)}
* @see com.foxinmy.weixin4j.tuple.MpArticle
*/
public List<MpArticle> downloadArticle(String mediaId)
throws WeixinException {
public List<MpArticle> downloadArticle(String mediaId) throws WeixinException {
MediaDownloadResult result = downloadMedia(mediaId, true);
byte[] content = result.getContent();
JSONObject obj = JSON.parseObject(content, 0, content.length,
Consts.UTF_8.newDecoder(), JSONObject.class);
JSONObject obj = JSON.parseObject(content, 0, content.length, Consts.UTF_8.newDecoder(), JSONObject.class);
return JSON.parseArray(obj.getString("news_item"), MpArticle.class);
}
@@ -350,22 +316,20 @@ public class MediaApi extends MpApi {
* @return 处理结果
* @throws WeixinException
* @see com.foxinmy.weixin4j.tuple.MpArticle
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738732&token=&lang=zh_CN">更新永久图文素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738732&token=&lang=zh_CN">更新永久图文素材</a>
*/
public JsonResult updateMaterialArticle(String mediaId, int index,
MpArticle article) throws WeixinException {
public ApiResult updateMaterialArticle(String mediaId, int index, MpArticle article) throws WeixinException {
Token token = tokenManager.getCache();
String material_article_update_uri = getRequestUri("material_article_update_uri");
JSONObject obj = new JSONObject();
obj.put("articles", article);
obj.put("media_id", mediaId);
obj.put("index", index);
WeixinResponse response = weixinExecutor.post(
String.format(material_article_update_uri,
token.getAccessToken()), obj.toJSONString());
WeixinResponse response = weixinExecutor
.post(String.format(material_article_update_uri, token.getAccessToken()), obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -375,20 +339,18 @@ public class MediaApi extends MpApi {
* 媒体素材的media_id
* @return 处理结果
* @throws WeixinException
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738731&token=&lang=zh_CN">删除永久媒体素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738731&token=&lang=zh_CN">删除永久媒体素材</a>
*/
public JsonResult deleteMaterialMedia(String mediaId)
throws WeixinException {
public ApiResult deleteMaterialMedia(String mediaId) throws WeixinException {
Token token = tokenManager.getCache();
String material_media_del_uri = getRequestUri("material_media_del_uri");
JSONObject obj = new JSONObject();
obj.put("media_id", mediaId);
WeixinResponse response = weixinExecutor.post(
String.format(material_media_del_uri, token.getAccessToken()),
WeixinResponse response = weixinExecutor.post(String.format(material_media_del_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -403,12 +365,12 @@ public class MediaApi extends MpApi {
* @param introduction
* 视频描述
* @return 上传到微信服务器返回的媒体标识
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738729&token=&lang=zh_CN">上传永久媒体素材</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738729&token=&lang=zh_CN">上传永久媒体素材</a>
* @throws WeixinException
*/
public String uploadMaterialVideo(InputStream is, String fileName,
String title, String introduction) throws WeixinException {
public String uploadMaterialVideo(InputStream is, String fileName, String title, String introduction)
throws WeixinException {
if (StringUtil.isBlank(fileName)) {
fileName = ObjectId.get().toHexString();
}
@@ -416,18 +378,16 @@ public class MediaApi extends MpApi {
fileName = String.format("%s.mp4", fileName);
}
String material_media_upload_uri = getRequestUri("material_media_upload_uri");
MimeType mimeType = new MimeType("video", FileUtil.getFileExtension(fileName));
Token token = tokenManager.getCache();
try {
JSONObject description = new JSONObject();
description.put("title", title);
description.put("introduction", introduction);
WeixinResponse response = weixinExecutor.post(
String.format(material_media_upload_uri,
token.getAccessToken()),
new FormBodyPart("media", new InputStreamBody(is,
ContentType.VIDEO_MPEG4.getMimeType(), fileName)),
new FormBodyPart("description", new StringBody(description
.toJSONString(), Consts.UTF_8)));
String.format(material_media_upload_uri, token.getAccessToken()),
new FormBodyPart("media", new InputStreamBody(is, mimeType.toString(), fileName)),
new FormBodyPart("description", new StringBody(description.toJSONString(), Consts.UTF_8)));
return response.getAsJson().getString("media_id");
} catch (UnsupportedEncodingException e) {
throw new WeixinException(e);
@@ -443,19 +403,19 @@ public class MediaApi extends MpApi {
}
/**
* 获取永久媒体素材的总数</br> .图片和图文消息素材(包括单图文和多图文)的总数上限为5000,其他素材的总数上限为1000
* 获取永久媒体素材的总数</br>
* .图片和图文消息素材(包括单图文和多图文)的总数上限为5000,其他素材的总数上限为1000
*
* @return 总数对象
* @throws WeixinException
* @see com.foxinmy.weixin4j.model.MediaCounter
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738733&token=&lang=zh_CN">获取素材总数</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738733&token=&lang=zh_CN">获取素材总数</a>
*/
public MediaCounter countMaterialMedia() throws WeixinException {
Token token = tokenManager.getCache();
String material_media_count_uri = getRequestUri("material_media_count_uri");
WeixinResponse response = weixinExecutor.get(String.format(
material_media_count_uri, token.getAccessToken()));
WeixinResponse response = weixinExecutor.get(String.format(material_media_count_uri, token.getAccessToken()));
return response.getAsObject(new TypeReference<MediaCounter>() {
});
@@ -475,35 +435,29 @@ public class MediaApi extends MpApi {
* @see com.foxinmy.weixin4j.model.MediaItem
* @see com.foxinmy.weixin4j.model.Pageable
* @see com.foxinmy.weixin4j.model.Pagedata
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738734&token=&lang=zh_CN">获取素材列表</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738734&token=&lang=zh_CN">获取素材列表</a>
*/
public MediaRecord listMaterialMedia(MediaType mediaType, Pageable pageable)
throws WeixinException {
public MediaRecord listMaterialMedia(MediaType mediaType, Pageable pageable) throws WeixinException {
Token token = tokenManager.getCache();
String material_media_list_uri = getRequestUri("material_media_list_uri");
JSONObject obj = new JSONObject();
obj.put("type", mediaType.name());
obj.put("offset", pageable.getOffset());
obj.put("count", pageable.getPageSize());
WeixinResponse response = weixinExecutor.post(
String.format(material_media_list_uri, token.getAccessToken()),
WeixinResponse response = weixinExecutor.post(String.format(material_media_list_uri, token.getAccessToken()),
obj.toJSONString());
MediaRecord mediaRecord = null;
if (mediaType == MediaType.news) {
mediaRecord = JSON.parseObject(response.getAsString(),
MediaRecord.class, new ExtraProcessor() {
@Override
public void processExtra(Object object, String key,
Object value) {
if (key.equals("content")) {
((MediaItem) object).setArticles(JSON
.parseArray(((JSONObject) value)
.getString("news_item"),
MpArticle.class));
}
}
});
mediaRecord = JSON.parseObject(response.getAsString(), MediaRecord.class, new ExtraProcessor() {
@Override
public void processExtra(Object object, String key, Object value) {
if (key.equals("content")) {
((MediaItem) object).setArticles(
JSON.parseArray(((JSONObject) value).getString("news_item"), MpArticle.class));
}
}
});
} else {
obj = response.getAsJson();
obj.put("items", obj.remove("itemlist"));
@@ -523,15 +477,13 @@ public class MediaApi extends MpApi {
* @see {@link #listMaterialMedia(MediaType, Pageable)}
* @throws WeixinException
*/
public List<MediaItem> listAllMaterialMedia(MediaType mediaType)
throws WeixinException {
public List<MediaItem> listAllMaterialMedia(MediaType mediaType) throws WeixinException {
Pageable pageable = new Pageable(1, 20);
List<MediaItem> mediaList = new ArrayList<MediaItem>();
MediaRecord mediaRecord = null;
for (;;) {
mediaRecord = listMaterialMedia(mediaType, pageable);
if (mediaRecord.getItems() == null
|| mediaRecord.getItems().isEmpty()) {
if (mediaRecord.getItems() == null || mediaRecord.getItems().isEmpty()) {
break;
}
mediaList.addAll(mediaRecord.getItems());
@@ -11,7 +11,7 @@ import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
import com.alibaba.fastjson.parser.deserializer.ParseProcess;
import com.alibaba.fastjson.serializer.NameFilter;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Button;
import com.foxinmy.weixin4j.model.Token;
@@ -48,11 +48,11 @@ public class MenuApi extends MpApi {
* @see com.foxinmy.weixin4j.model.Button
* @return 处理结果
*/
public JsonResult createMenu(List<Button> buttons) throws WeixinException {
public ApiResult createMenu(List<Button> buttons) throws WeixinException {
String menu_create_uri = getRequestUri("menu_create_uri");
JSONObject obj = new JSONObject();
obj.put("button", buttons);
return createMenu0(menu_create_uri, obj).getAsJsonResult();
return createMenu0(menu_create_uri, obj).getAsResult();
}
private WeixinResponse createMenu0(String url, JSONObject data)
@@ -148,13 +148,13 @@ public class MenuApi extends MpApi {
* 删除菜单</a>
* @return 处理结果
*/
public JsonResult deleteMenu() throws WeixinException {
public ApiResult deleteMenu() throws WeixinException {
String menu_delete_uri = getRequestUri("menu_delete_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
menu_delete_uri, token.getAccessToken()));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -190,7 +190,7 @@ public class MenuApi extends MpApi {
* 删除个性化菜单</a>
* @return 处理结果
*/
public JsonResult deleteCustomMenu(String menuId) throws WeixinException {
public ApiResult deleteCustomMenu(String menuId) throws WeixinException {
String menu_delete_uri = getRequestUri("menu_delete_custom_uri");
Token token = tokenManager.getCache();
JSONObject obj = new JSONObject();
@@ -199,7 +199,7 @@ public class MenuApi extends MpApi {
String.format(menu_delete_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -4,7 +4,7 @@ import java.util.List;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.mp.message.NotifyMessage;
@@ -41,7 +41,7 @@ public class NotifyApi extends MpApi {
* @see {@link #sendNotify(NotifyMessage, String)}
* @throws WeixinException
*/
public JsonResult sendNotify(NotifyMessage notify) throws WeixinException {
public ApiResult sendNotify(NotifyMessage notify) throws WeixinException {
return sendNotify(notify, null);
}
@@ -64,7 +64,7 @@ public class NotifyApi extends MpApi {
* @see com.foxinmy.weixin4j.tuple.News
* @see com.foxinmy.weixin4j.mp.message.NotifyMessage
*/
public JsonResult sendNotify(NotifyMessage notify, String kfAccount)
public ApiResult sendNotify(NotifyMessage notify, String kfAccount)
throws WeixinException {
NotifyTuple tuple = notify.getTuple();
if (tuple instanceof MpNews) {
@@ -94,6 +94,6 @@ public class NotifyApi extends MpApi {
String.format(custom_notify_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -26,7 +26,7 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.http.weixin.WeixinSSLRequestExecutor;
@@ -531,7 +531,7 @@ public class PayOldApi extends MpApi {
* @return 发货处理结果
* @throws WeixinException
*/
public JsonResult deliverNotify(String openId, String transid,
public ApiResult deliverNotify(String openId, String transid,
String outTradeNo, boolean status, String statusMsg)
throws WeixinException {
String delivernotify_uri = getRequestUri("delivernotify_old_uri");
@@ -552,7 +552,7 @@ public class PayOldApi extends MpApi {
WeixinResponse response = weixinExecutor.post(
String.format(delivernotify_uri, token.getAccessToken()),
JSON.toJSONString(map));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -565,12 +565,12 @@ public class PayOldApi extends MpApi {
* @return 维权处理结果
* @throws WeixinException
*/
public JsonResult updateFeedback(String openId, String feedbackId)
public ApiResult updateFeedback(String openId, String feedbackId)
throws WeixinException {
String payfeedback_uri = getRequestUri("payfeedback_old_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
payfeedback_uri, token.getAccessToken(), openId, feedbackId));
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -6,13 +6,12 @@ import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.mp.model.Following;
import com.foxinmy.weixin4j.mp.model.Tag;
import com.foxinmy.weixin4j.mp.model.User;
import com.foxinmy.weixin4j.token.TokenManager;
import com.foxinmy.weixin4j.util.StringUtil;
/**
* 标签相关API
@@ -82,14 +81,14 @@ public class TagApi extends MpApi {
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">更新标签</a>
*/
public JsonResult updateTag(Tag tag) throws WeixinException {
public ApiResult updateTag(Tag tag) throws WeixinException {
String tag_update_uri = getRequestUri("tag_update_uri");
JSONObject obj = new JSONObject();
obj.put("tag", tag);
WeixinResponse response = weixinExecutor.post(
String.format(tag_update_uri, tokenManager.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -102,12 +101,12 @@ public class TagApi extends MpApi {
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">删除标签</a>
*/
public JsonResult deleteTag(int tagId) throws WeixinException {
public ApiResult deleteTag(int tagId) throws WeixinException {
String tag_delete_uri = getRequestUri("tag_delete_uri");
WeixinResponse response = weixinExecutor.post(
String.format(tag_delete_uri, tokenManager.getAccessToken()),
String.format("{\"tagid\":%d}", tagId));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -122,12 +121,12 @@ public class TagApi extends MpApi {
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">批量为用户打标签</a>
*/
public JsonResult taggingUsers(int tagId, String... openIds)
public ApiResult taggingUsers(int tagId, String... openIds)
throws WeixinException {
return batchUsers("tag_tagging_uri", tagId, openIds);
}
private JsonResult batchUsers(String batchType, int tagId,
private ApiResult batchUsers(String batchType, int tagId,
String... openIds) throws WeixinException {
String tag_batch_uri = getRequestUri(batchType);
JSONObject obj = new JSONObject();
@@ -136,7 +135,7 @@ public class TagApi extends MpApi {
WeixinResponse response = weixinExecutor.post(
String.format(tag_batch_uri, tokenManager.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -151,7 +150,7 @@ public class TagApi extends MpApi {
* @see <a
* href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN">批量为用户取消标签</a>
*/
public JsonResult untaggingUsers(int tagId, String... openIds)
public ApiResult untaggingUsers(int tagId, String... openIds)
throws WeixinException {
return batchUsers("tag_untagging_uri", tagId, openIds);
}
@@ -235,11 +234,12 @@ public class TagApi extends MpApi {
Following f = null;
for (;;) {
f = getTagFollowingOpenIds(tagId, nextOpenId);
if (f.getCount() == 0 || StringUtil.isBlank(f.getNextOpenId())) {
break;
if (f.hasContent()) {
openIds.addAll(f.getOpenIds());
nextOpenId = f.getNextOpenId();
continue;
}
openIds.addAll(f.getOpenIds());
nextOpenId = f.getNextOpenId();
break;
}
return openIds;
}
@@ -261,11 +261,12 @@ public class TagApi extends MpApi {
Following f = null;
for (;;) {
f = getTagFollowing(tagId, nextOpenId);
if (f.getCount() == 0 || StringUtil.isBlank(f.getNextOpenId())) {
break;
if (f.hasContent()) {
userList.addAll(f.getUserList());
nextOpenId = f.getNextOpenId();
continue;
}
userList.addAll(f.getUserList());
nextOpenId = f.getNextOpenId();
break;
}
return userList;
}
@@ -6,7 +6,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.NameFilter;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
@@ -43,7 +43,7 @@ public class TmplApi extends MpApi {
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">设置所处行业</a>
*/
public JsonResult setTmplIndustry(IndustryType... industryTypes)
public ApiResult setTmplIndustry(IndustryType... industryTypes)
throws WeixinException {
JSONObject obj = new JSONObject();
for (int i = 0; i < industryTypes.length; i++) {
@@ -56,7 +56,7 @@ public class TmplApi extends MpApi {
template_set_industry_uri, token.getAccessToken()), obj
.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -133,13 +133,13 @@ public class TmplApi extends MpApi {
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">删除模板</a>
* @throws WeixinException
*/
public JsonResult deleteTemplate(String templateId) throws WeixinException {
public ApiResult deleteTemplate(String templateId) throws WeixinException {
Token token = tokenManager.getCache();
String template_del_uri = getRequestUri("template_del_uri");
WeixinResponse response = weixinExecutor.post(
String.format(template_del_uri, token.getAccessToken()),
String.format("{\"template_id\"=\"%s\"}", templateId));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -157,7 +157,7 @@ public class TmplApi extends MpApi {
* @see com.foxinmy.weixin4j.mp.message.TemplateMessage
* @see com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
*/
public JsonResult sendTmplMessage(TemplateMessage tplMessage)
public ApiResult sendTmplMessage(TemplateMessage tplMessage)
throws WeixinException {
Token token = tokenManager.getCache();
String template_send_uri = getRequestUri("template_send_uri");
@@ -174,6 +174,6 @@ public class TmplApi extends MpApi {
}
}));
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -7,14 +7,13 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.mp.model.Following;
import com.foxinmy.weixin4j.mp.model.User;
import com.foxinmy.weixin4j.mp.type.Lang;
import com.foxinmy.weixin4j.token.TokenManager;
import com.foxinmy.weixin4j.util.StringUtil;
/**
* 用户相关API
@@ -68,8 +67,8 @@ public class UserApi extends MpApi {
public User getUser(String openId, Lang lang) throws WeixinException {
String user_info_uri = getRequestUri("api_user_info_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
user_info_uri, token.getAccessToken(), openId, lang.name()));
WeixinResponse response = weixinExecutor
.get(String.format(user_info_uri, token.getAccessToken(), openId, lang.name()));
return response.getAsObject(new TypeReference<User>() {
});
@@ -107,25 +106,21 @@ public class UserApi extends MpApi {
* @see com.foxinmy.weixin4j.mp.model.User
* @throws WeixinException
*/
public List<User> getUsers(Lang lang, String... openIds)
throws WeixinException {
public List<User> getUsers(Lang lang, String... openIds) throws WeixinException {
String api_users_info_uri = getRequestUri("api_users_info_uri");
StringBuilder parameter = new StringBuilder();
parameter.append("{\"user_list\": [");
for (String openId : openIds) {
parameter.append("{\"openid\": \"").append(openId).append("\"");
parameter.append(",\"lang\": \"").append(lang.name()).append("\"")
.append("},");
parameter.append(",\"lang\": \"").append(lang.name()).append("\"").append("},");
}
parameter.delete(parameter.length() - 1, parameter.length());
parameter.append("]}");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(
String.format(api_users_info_uri, token.getAccessToken()),
WeixinResponse response = weixinExecutor.post(String.format(api_users_info_uri, token.getAccessToken()),
parameter.toString());
return JSON.parseArray(
response.getAsJson().getString("user_info_list"), User.class);
return JSON.parseArray(response.getAsJson().getString("user_info_list"), User.class);
}
/**
@@ -149,11 +144,8 @@ public class UserApi extends MpApi {
if (following.getCount() > 0) {
List<User> users = new ArrayList<User>(following.getCount());
for (int i = 1; i <= (int) Math.ceil(following.getCount() / 100d); i++) {
users.addAll(getUsers(following
.getOpenIds()
.subList((i - 1) * 100,
Math.min(i * 100, following.getCount()))
.toArray(new String[] {})));
users.addAll(getUsers(following.getOpenIds()
.subList((i - 1) * 100, Math.min(i * 100, following.getCount())).toArray(new String[] {})));
}
following.setUserList(users);
}
@@ -172,20 +164,17 @@ public class UserApi extends MpApi {
* 获取关注者列表</a>
* @see com.foxinmy.weixin4j.mp.model.Following
*/
public Following getFollowingOpenIds(String nextOpenId)
throws WeixinException {
public Following getFollowingOpenIds(String nextOpenId) throws WeixinException {
String following_uri = getRequestUri("following_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
following_uri, token.getAccessToken(), nextOpenId == null ? ""
: nextOpenId));
WeixinResponse response = weixinExecutor
.get(String.format(following_uri, token.getAccessToken(), nextOpenId == null ? "" : nextOpenId));
JSONObject result = response.getAsJson();
Following following = JSON.toJavaObject(result, Following.class);
if (following.getCount() > 0) {
following.setOpenIds(JSON.parseArray(result.getJSONObject("data")
.getString("openid"), String.class));
following.setOpenIds(JSON.parseArray(result.getJSONObject("data").getString("openid"), String.class));
}
return following;
}
@@ -215,12 +204,12 @@ public class UserApi extends MpApi {
Following f = null;
for (;;) {
f = getFollowing(nextOpenId);
if (f.getCount() == f.getTotal() || f.getCount() == 0
|| StringUtil.isBlank(f.getNextOpenId())) {
break;
if (f.hasContent()) {
userList.addAll(f.getUserList());
nextOpenId = f.getNextOpenId();
continue;
}
userList.addAll(f.getUserList());
nextOpenId = f.getNextOpenId();
break;
}
return userList;
}
@@ -245,12 +234,12 @@ public class UserApi extends MpApi {
Following f = null;
for (;;) {
f = getFollowingOpenIds(nextOpenId);
if (f.getCount() == f.getTotal() || f.getCount() == 0
|| StringUtil.isBlank(f.getNextOpenId())) {
break;
if (f.hasContent()) {
openIds.addAll(f.getOpenIds());
nextOpenId = f.getNextOpenId();
continue;
}
openIds.addAll(f.getOpenIds());
nextOpenId = f.getNextOpenId();
break;
}
return openIds;
}
@@ -267,17 +256,15 @@ public class UserApi extends MpApi {
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140838&token=&lang=zh_CN">
* 设置用户备注名</a>
*/
public JsonResult remarkUserName(String openId, String remark)
throws WeixinException {
public ApiResult remarkUserName(String openId, String remark) throws WeixinException {
String username_remark_uri = getRequestUri("username_remark_uri");
Token token = tokenManager.getCache();
JSONObject obj = new JSONObject();
obj.put("openid", openId);
obj.put("remark", remark);
WeixinResponse response = weixinExecutor.post(
String.format(username_remark_uri, token.getAccessToken()),
WeixinResponse response = weixinExecutor.post(String.format(username_remark_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -82,6 +82,10 @@ public class Following implements Serializable {
this.nextOpenId = nextOpenId;
}
public boolean hasContent() {
return userList != null && !userList.isEmpty();
}
@Override
public String toString() {
return "Following [total=" + total + ", count=" + count + ", openIds=" + openIds + ", nextOpenId=" + nextOpenId
@@ -2,7 +2,7 @@ package com.foxinmy.weixin4j.mp.model;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
/**
* 语义理解结果
@@ -11,10 +11,10 @@ import com.foxinmy.weixin4j.http.weixin.JsonResult;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年11月7日
* @since JDK 1.6
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141241&token=&lang=zh_CN">语义理解</a>
* @see <a href=
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141241&token=&lang=zh_CN">语义理解</a>
*/
public class SemResult extends JsonResult {
public class SemResult extends ApiResult {
private static final long serialVersionUID = 9051214458161068387L;
/**
@@ -92,8 +92,7 @@ public class SemResult extends JsonResult {
@Override
public String toString() {
return "SemResult [query=" + query + ", type=" + type + ", semantic="
+ semantic + ", result=" + result + ", answer=" + answer + ", "
+ super.toString() + "]";
return "SemResult [" + super.toString() + ", query=" + query + ", type=" + type + ", semantic=" + semantic
+ ", result=" + result + ", answer=" + answer + ", " + super.toString() + "]";
}
}
@@ -12,7 +12,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.model.Pageable;
import com.foxinmy.weixin4j.mp.api.CustomApi;
import com.foxinmy.weixin4j.mp.model.KfAccount;
@@ -61,44 +61,44 @@ public class CustomTest extends TokenTest {
@Test
public void createKfAccount() throws WeixinException {
JsonResult result = customApi.createKfAccount("test@test", "test",
ApiResult result = customApi.createKfAccount("test@test", "test",
"123456");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void updateKfAccount() throws WeixinException {
JsonResult result = customApi.updateKfAccount("temp1@canyidianzhang",
ApiResult result = customApi.updateKfAccount("temp1@canyidianzhang",
"temp", "123456");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void uploadKfAvatar() throws WeixinException, IOException {
JsonResult result = customApi.uploadKfAvatar("temp1@canyidianzhang",
ApiResult result = customApi.uploadKfAvatar("temp1@canyidianzhang",
new FileInputStream(new File("/Users/jy/Music/简谱/风动草.jpg")),
"风动草.jpg");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void deleteKfAccount() throws WeixinException, IOException {
JsonResult result = customApi.deleteKfAccount("temp@canyidianzhang");
Assert.assertEquals(0, result.getCode());
ApiResult result = customApi.deleteKfAccount("temp@canyidianzhang");
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void createSession() throws WeixinException {
JsonResult result = customApi.createKfSession(
ApiResult result = customApi.createKfSession(
"opKwyt6IhrqPmTTZshyqH5W9gIVo", "kfAccount", "text");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void closeSession() throws WeixinException {
JsonResult result = customApi.closeKfSession(
ApiResult result = customApi.closeKfSession(
"opKwyt6IhrqPmTTZshyqH5W9gIVo", "kfAccount", "text");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
@@ -7,7 +7,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.mp.api.GroupApi;
import com.foxinmy.weixin4j.mp.model.Group;
@@ -48,27 +48,27 @@ public class GroupTest extends TokenTest {
@Test
public void modify() throws WeixinException {
JsonResult result = groupApi.modifyGroup(100, "my1");
Assert.assertEquals(0, result.getCode());
ApiResult result = groupApi.modifyGroup(100, "my1");
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void move() throws WeixinException {
JsonResult result = groupApi.moveGroup(100,
ApiResult result = groupApi.moveGroup(100,
"owGBft_vbBbOaQOmpEUE4xDLeRSU");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void batchMove() throws WeixinException {
JsonResult result = groupApi.moveGroup(100,
ApiResult result = groupApi.moveGroup(100,
"owGBft_vbBbOaQOmpEUE4xDLeRSU");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void delete() throws WeixinException {
JsonResult result = groupApi.deleteGroup(100);
Assert.assertEquals(0, result.getCode());
ApiResult result = groupApi.deleteGroup(100);
Assert.assertEquals(0, result.getReturnCode());
}
}
@@ -11,7 +11,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.model.MediaUploadResult;
import com.foxinmy.weixin4j.mp.api.MassApi;
import com.foxinmy.weixin4j.mp.api.MediaApi;
@@ -86,15 +86,15 @@ public class MassTest extends TokenTest {
@Test
public void deleteMass() throws WeixinException {
JsonResult result = massApi.deleteMassNews("34182");
Assert.assertEquals(0, result.getCode());
ApiResult result = massApi.deleteMassNews("34182");
Assert.assertEquals(0, result.getReturnCode());
}
@Test
public void previewMass() throws WeixinException {
JsonResult result = massApi.previewMassNews(
ApiResult result = massApi.previewMassNews(
"oyFLst1bqtuTcxK-ojF8hOGtLQao", null, new Text("test"));
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
@Test
@@ -12,7 +12,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.model.MediaCounter;
import com.foxinmy.weixin4j.model.MediaDownloadResult;
import com.foxinmy.weixin4j.model.MediaItem;
@@ -56,7 +56,7 @@ public class MediaTest extends TokenTest {
public void download1() throws WeixinException, IOException {
MediaDownloadResult content = mediaApi
.downloadMedia(
"fbyQZL96sK9evnTgDx21jPZgWAnw6YPgslNzcqLFp0lqPCD-XipoPfkwFU1OM9J_",
"DVWwU0u9ommOTPgyJszpKw5OSL9M-bdRY6gQkax1uuo",
false);
Assert.assertTrue(content != null);
System.err.println(content);
@@ -64,7 +64,7 @@ public class MediaTest extends TokenTest {
@Test
public void upload2() throws IOException, WeixinException {
File file = new File("/Users/jy/Downloads/weixin4j.png");
File file = new File("/root/Pictures/2.jpg");
MediaUploadResult mediaId = mediaApi.uploadMedia(true,
new FileInputStream(file), file.getName());
// 8790403529
@@ -101,7 +101,7 @@ public class MediaTest extends TokenTest {
@Test
public void deleteMaterialMedia() throws WeixinException {
JsonResult result = mediaApi.deleteMaterialMedia("17385064953");
ApiResult result = mediaApi.deleteMaterialMedia("17385064953");
System.err.println(result);
}
@@ -112,7 +112,7 @@ public class MediaTest extends TokenTest {
article.setDigest("digest_update");
article.setShowCoverPic(false);
article.setSourceUrl("http://www.baidu.com");
JsonResult result = mediaApi.updateMaterialArticle("17385064953", 0,
ApiResult result = mediaApi.updateMaterialArticle("17385064953", 0,
article);
System.err.println(result);
// 17385065153
@@ -8,7 +8,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.model.Button;
import com.foxinmy.weixin4j.mp.api.MenuApi;
import com.foxinmy.weixin4j.mp.model.Menu;
@@ -54,8 +54,8 @@ public class MenuTest extends TokenTest {
button.pushSub(new Button("在线客服", "KF", ButtonType.click));
buttons.add(button);
JsonResult result = menuApi.createMenu(buttons);
Assert.assertEquals(0, result.getCode());
ApiResult result = menuApi.createMenu(buttons);
Assert.assertEquals(0, result.getReturnCode());
}
@Test
@@ -69,8 +69,8 @@ public class MenuTest extends TokenTest {
buttons.add(b2);
Button b3 = new Button("最新资讯", "NEWS", ButtonType.click);
buttons.add(b3);
JsonResult result = menuApi.createMenu(buttons);
Assert.assertEquals(0, result.getCode());
ApiResult result = menuApi.createMenu(buttons);
Assert.assertEquals(0, result.getReturnCode());
}
@Test
@@ -92,8 +92,8 @@ public class MenuTest extends TokenTest {
@Test
public void delete() throws WeixinException {
JsonResult result = menuApi.deleteMenu();
Assert.assertEquals(0, result.getCode());
ApiResult result = menuApi.deleteMenu();
Assert.assertEquals(0, result.getReturnCode());
}
@Test
@@ -9,7 +9,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.model.MediaUploadResult;
import com.foxinmy.weixin4j.mp.api.MediaApi;
import com.foxinmy.weixin4j.mp.api.NotifyApi;
@@ -87,8 +87,8 @@ public class NotifyTest extends TokenTest {
NotifyMessage notify = new NotifyMessage(
"owGBft_vbBbOaQOmpEUE4xDLeRSU", new Text(
"this is a notify message!"));
JsonResult result = notifyApi.sendNotify(notify);
Assert.assertEquals(0, result.getCode());
ApiResult result = notifyApi.sendNotify(notify);
Assert.assertEquals(0, result.getReturnCode());
}
@Test
@@ -99,7 +99,7 @@ public class NotifyTest extends TokenTest {
NotifyMessage imageNotify = new NotifyMessage(
"owGBft_vbBbOaQOmpEUE4xDLeRSU", new Image(
mediaResult.getMediaId()));
JsonResult result = notifyApi.sendNotify(imageNotify);
Assert.assertEquals(0, result.getCode());
ApiResult result = notifyApi.sendNotify(imageNotify);
Assert.assertEquals(0, result.getReturnCode());
}
}
@@ -7,7 +7,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.mp.api.TagApi;
import com.foxinmy.weixin4j.mp.model.Tag;
import com.foxinmy.weixin4j.mp.model.User;
@@ -44,19 +44,19 @@ public class TagTest extends TokenTest {
@Test
public void update() throws WeixinException {
JsonResult result = tagApi.updateTag(new Tag(120, "测试12"));
ApiResult result = tagApi.updateTag(new Tag(120, "测试12"));
System.err.println(result);
}
@Test
public void remove() throws WeixinException {
JsonResult result = tagApi.deleteTag(134);
ApiResult result = tagApi.deleteTag(134);
System.err.print(result);
}
@Test
public void batchtagging() throws WeixinException {
JsonResult result = tagApi.taggingUsers(120,
ApiResult result = tagApi.taggingUsers(120,
"owGBft-GyGJuKXBzpkzrfl-RG8TI", "owGBfty5TYNwh-3iUTGtxAHcD310",
"owGBftzXEfBml_bYvbrYxE5lE5U8");
System.err.println(result);
@@ -64,7 +64,7 @@ public class TagTest extends TokenTest {
@Test
public void batchuntagging() throws WeixinException {
JsonResult result = tagApi.taggingUsers(120,
ApiResult result = tagApi.taggingUsers(120,
"owGBftwS5Yr6xKH_Hb9mGv1nbd3o");
System.err.println(result);
}
@@ -5,7 +5,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.mp.api.TmplApi;
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
import com.foxinmy.weixin4j.mp.type.IndustryType;
@@ -39,7 +39,7 @@ public class TemplateTest extends TokenTest {
TemplateMessage tplMessage = new TemplateMessage("touser",
"template_id", "url");
tplMessage.pushHead("head").pushTail("tail").pushItem("key1", "text1");
JsonResult result = tmplApi.sendTmplMessage(tplMessage);
Assert.assertEquals(0, result.getCode());
ApiResult result = tmplApi.sendTmplMessage(tplMessage);
Assert.assertEquals(0, result.getReturnCode());
}
}
@@ -7,7 +7,7 @@ import org.junit.Before;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.mp.api.UserApi;
import com.foxinmy.weixin4j.mp.model.User;
@@ -46,8 +46,8 @@ public class UserTest extends TokenTest {
@Test
public void remark() throws WeixinException {
JsonResult result = userApi.remarkUserName(
ApiResult result = userApi.remarkUserName(
"owGBft_vbBbOaQOmpEUE4xDLeRSU", "foo");
Assert.assertEquals(0, result.getCode());
Assert.assertEquals(0, result.getReturnCode());
}
}