新增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
@@ -4,7 +4,7 @@ import java.io.InputStream;
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;
@@ -259,7 +259,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.qy.message.CustomeMessage
* @throws WeixinException
*/
public JsonResult sendCustomeMessage(CustomeMessage message)
public ApiResult sendCustomeMessage(CustomeMessage message)
throws WeixinException {
return notifyApi.sendCustomeMessage(message);
}
@@ -296,7 +296,7 @@ public class WeixinProxy {
* 创建自定义菜单</a>
* @see com.foxinmy.weixin4j.model.Button
*/
public JsonResult createMenu(int agentid, List<Button> buttons)
public ApiResult createMenu(int agentid, List<Button> buttons)
throws WeixinException {
return menuApi.createMenu(agentid, buttons);
}
@@ -330,7 +330,7 @@ public class WeixinProxy {
* 删除菜单</a>
* @return 处理结果
*/
public JsonResult deleteMenu(int agentid) throws WeixinException {
public ApiResult deleteMenu(int agentid) throws WeixinException {
return menuApi.deleteMenu(agentid);
}
@@ -444,7 +444,7 @@ public class WeixinProxy {
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%A0%E9%99%A4%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">
* 删除永久媒体素材</a>
*/
public JsonResult deleteMaterialMedia(int agentid, String mediaId)
public ApiResult deleteMaterialMedia(int agentid, String mediaId)
throws WeixinException {
return mediaApi.deleteMaterialMedia(agentid, mediaId);
}
@@ -579,7 +579,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult updateParty(Party party) throws WeixinException {
public ApiResult updateParty(Party party) throws WeixinException {
return partyApi.updateParty(party);
}
@@ -612,7 +612,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult deleteParty(int partyId) throws WeixinException {
public ApiResult deleteParty(int partyId) throws WeixinException {
return partyApi.deleteParty(partyId);
}
@@ -648,7 +648,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult createUser(User user) throws WeixinException {
public ApiResult createUser(User user) throws WeixinException {
return userApi.createUser(user);
}
@@ -667,7 +667,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult createUser(User user, InputStream avatar)
public ApiResult createUser(User user, InputStream avatar)
throws WeixinException {
return userApi.createUser(user, avatar);
}
@@ -685,7 +685,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult updateUser(User user) throws WeixinException {
public ApiResult updateUser(User user) throws WeixinException {
return userApi.updateUser(user);
}
@@ -704,7 +704,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult updateUser(User user, InputStream avatar)
public ApiResult updateUser(User user, InputStream avatar)
throws WeixinException {
return userApi.updateUser(user, avatar);
}
@@ -815,7 +815,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult deleteUser(String userid) throws WeixinException {
public ApiResult deleteUser(String userid) throws WeixinException {
return userApi.deleteUser(userid);
}
@@ -831,7 +831,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult batchDeleteUser(List<String> userIds)
public ApiResult batchDeleteUser(List<String> userIds)
throws WeixinException {
return userApi.batchDeleteUser(userIds);
}
@@ -885,7 +885,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult updateTag(Tag tag) throws WeixinException {
public ApiResult updateTag(Tag tag) throws WeixinException {
return tagApi.updateTag(tag);
}
@@ -901,7 +901,7 @@ public class WeixinProxy {
* @see com.foxinmy.weixin4j.qy.api.TagApi
* @throws WeixinException
*/
public JsonResult deleteTag(int tagId) throws WeixinException {
public ApiResult deleteTag(int tagId) throws WeixinException {
return tagApi.deleteTag(tagId);
}
@@ -1026,7 +1026,7 @@ public class WeixinProxy {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult setAgent(AgentSetter agentSet) throws WeixinException {
public ApiResult setAgent(AgentSetter agentSet) throws WeixinException {
return agentApi.setAgent(agentSet);
}
@@ -1270,7 +1270,7 @@ public class WeixinProxy {
* 修改会话信息</a>
* @throws WeixinException
*/
public JsonResult updateChat(ChatInfo chatInfo, String operator,
public ApiResult updateChat(ChatInfo chatInfo, String operator,
List<String> addUsers, List<String> deleteUsers)
throws WeixinException {
return chatApi.updateChat(chatInfo, operator, addUsers, deleteUsers);
@@ -1290,7 +1290,7 @@ public class WeixinProxy {
* 退出会话</a>
* @throws WeixinException
*/
public JsonResult quitChat(String chatId, String operator)
public ApiResult quitChat(String chatId, String operator)
throws WeixinException {
return chatApi.quitChat(chatId, operator);
}
@@ -1311,7 +1311,7 @@ public class WeixinProxy {
* 清除会话未读状态</a>
* @throws WeixinException
*/
public JsonResult clearChatNotify(String targetId, String owner,
public ApiResult clearChatNotify(String targetId, String owner,
ChatType chatType) throws WeixinException {
return chatApi.clearChatNotify(targetId, owner, chatType);
}
@@ -1348,7 +1348,7 @@ public class WeixinProxy {
* 发送消息</a>
* @throws WeixinException
*/
public JsonResult sendChatMessage(ChatMessage message)
public ApiResult sendChatMessage(ChatMessage message)
throws WeixinException {
return chatApi.sendChatMessage(message);
}
@@ -6,7 +6,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.ValueFilter;
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.qy.model.AgentInfo;
@@ -72,13 +72,13 @@ public class AgentApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult setAgent(AgentSetter agentSet) throws WeixinException {
public ApiResult setAgent(AgentSetter agentSet) throws WeixinException {
String agent_set_uri = getRequestUri("agent_set_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(
String.format(agent_set_uri, token.getAccessToken()),
JSON.toJSONString(agentSet, typeFilter));
return response.getAsJsonResult();
return response.getAsResult();
}
public final static ValueFilter typeFilter;
@@ -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.qy.message.ChatMessage;
@@ -96,7 +96,7 @@ public class ChatApi extends QyApi {
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E4.BF.AE.E6.94.B9.E4.BC.9A.E8.AF.9D.E4.BF.A1.E6.81.AF">修改会话信息</a>
* @throws WeixinException
*/
public JsonResult updateChat(ChatInfo chatInfo, String operator,
public ApiResult updateChat(ChatInfo chatInfo, String operator,
List<String> addUsers, List<String> deleteUsers)
throws WeixinException {
JSONObject obj = (JSONObject) JSON.toJSON(chatInfo);
@@ -109,7 +109,7 @@ public class ChatApi extends QyApi {
WeixinResponse response = weixinExecutor.post(
String.format(message_chat_update_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -124,7 +124,7 @@ public class ChatApi extends QyApi {
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E9.80.80.E5.87.BA.E4.BC.9A.E8.AF.9D">退出会话</a>
* @throws WeixinException
*/
public JsonResult quitChat(String chatId, String operator)
public ApiResult quitChat(String chatId, String operator)
throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("chatid", chatId);
@@ -134,7 +134,7 @@ public class ChatApi extends QyApi {
WeixinResponse response = weixinExecutor.post(
String.format(message_chat_quit_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -151,7 +151,7 @@ public class ChatApi extends QyApi {
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E6.B8.85.E9.99.A4.E4.BC.9A.E8.AF.9D.E6.9C.AA.E8.AF.BB.E7.8A.B6.E6.80.81">清除会话未读状态</a>
* @throws WeixinException
*/
public JsonResult clearChatNotify(String targetId, String owner,
public ApiResult clearChatNotify(String targetId, String owner,
ChatType chatType) throws WeixinException {
JSONObject chat = new JSONObject();
chat.put("type", chatType.name());
@@ -163,7 +163,7 @@ public class ChatApi extends QyApi {
token.getAccessToken()),
String.format("{\"op_user\": \"%s\",\"chat\":%s", owner,
chat.toJSONString()));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -203,7 +203,7 @@ public class ChatApi extends QyApi {
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E5.8F.91.E6.B6.88.E6.81.AF">发送消息</a>
* @throws WeixinException
*/
public JsonResult sendChatMessage(ChatMessage message)
public ApiResult sendChatMessage(ChatMessage message)
throws WeixinException {
ChatTuple tuple = message.getChatTuple();
String msgtype = tuple.getMessageType();
@@ -220,6 +220,6 @@ public class ChatApi extends QyApi {
WeixinResponse response = weixinExecutor.post(
String.format(message_chat_send_uri, token.getAccessToken()),
msg.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -22,10 +22,12 @@ 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.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;
@@ -54,8 +56,8 @@ import com.foxinmy.weixin4j.util.StringUtil;
* @author jinyu(foxinmy@gmail.com)
* @date 2014年9月25日
* @since JDK 1.6
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">管理素材文件</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">管理素材文件</a>
* @see com.foxinmy.weixin4j.type.MediaType
*/
public class MediaApi extends QyApi {
@@ -74,13 +76,12 @@ public class MediaApi extends QyApi {
* 图片数据
* @param fileName
* 文件名
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E5%9B%BE%E6%96%87%E6%B6%88%E6%81%AF%E5%86%85%E7%9A%84%E5%9B%BE%E7%89%87">上传图文消息内的图片</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E5%9B%BE%E6%96%87%E6%B6%88%E6%81%AF%E5%86%85%E7%9A%84%E5%9B%BE%E7%89%87">上传图文消息内的图片</a>
* @return 图片url
* @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();
}
@@ -88,11 +89,10 @@ public class MediaApi extends QyApi {
fileName = String.format("%s.jpg", fileName);
}
String media_uploadimg_uri = getRequestUri("media_uploadimg_uri");
MimeType mimeType = new MimeType("image", FileUtil.getFileExtension(fileName));
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(
media_uploadimg_uri, token.getAccessToken()),
new FormBodyPart("media", new InputStreamBody(is,
ContentType.IMAGE_JPG.getMimeType(), fileName)));
WeixinResponse response = weixinExecutor.post(String.format(media_uploadimg_uri, token.getAccessToken()),
new FormBodyPart("media", new InputStreamBody(is, mimeType.toString(), fileName)));
return response.getAsJson().getString("url");
}
@@ -111,14 +111,13 @@ public class MediaApi extends QyApi {
* 文件名
* @return 上传到微信服务器返回的媒体标识
* @see com.foxinmy.weixin4j.model.MediaUploadResult
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%B4%E6%97%B6%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">上传临时素材文件说明</a>
* @see <a
* href="http://http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">上传永久素材文件说明</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%B4%E6%97%B6%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">上传临时素材文件说明</a>
* @see <a href=
* "http://http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">上传永久素材文件说明</a>
* @throws WeixinException
*/
public MediaUploadResult uploadMedia(int agentid, InputStream is,
String fileName) throws WeixinException {
public MediaUploadResult uploadMedia(int agentid, InputStream is, String fileName) throws WeixinException {
byte[] content;
try {
content = IOUtil.toByteArray(is);
@@ -130,19 +129,15 @@ public class MediaApi extends QyApi {
}
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 = MediaType.file;
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;
}
Token token = tokenManager.getCache();
@@ -150,26 +145,20 @@ public class MediaApi extends QyApi {
WeixinResponse response = null;
if (agentid > 0) {
String material_media_upload_uri = getRequestUri("material_media_upload_uri");
response = weixinExecutor.post(String.format(
material_media_upload_uri, token.getAccessToken(),
mediaType.name(), agentid), new FormBodyPart("media",
new ByteArrayBody(content, mediaType.getContentType()
.getMimeType(), fileName)));
response = weixinExecutor.post(
String.format(material_media_upload_uri, token.getAccessToken(), mediaType.name(), agentid),
new FormBodyPart("media",
new ByteArrayBody(content, mediaType.getMimeType().toString(), fileName)));
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 ByteArrayBody(content,
mediaType.getContentType().getMimeType(),
fileName)));
response = weixinExecutor.post(
String.format(media_upload_uri, token.getAccessToken(), mediaType.name()), new FormBodyPart(
"media", new ByteArrayBody(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"));
}
} finally {
if (is != null) {
@@ -191,60 +180,45 @@ public class MediaApi extends QyApi {
* 媒体ID
* @return 媒体下载结果
* @see com.foxinmy.weixin4j.model.MediaDownloadResult
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%B8%B4%E6%97%B6%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">获取临时媒体说明</a>
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">获取永久媒体说明</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%B8%B4%E6%97%B6%E7%B4%A0%E6%9D%90%E6%96%87%E4%BB%B6">获取临时媒体说明</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">获取永久媒体说明</a>
* @throws WeixinException
*/
public MediaDownloadResult downloadMedia(int agentid, String mediaId)
throws WeixinException {
public MediaDownloadResult downloadMedia(int agentid, String mediaId) throws WeixinException {
Token token = tokenManager.getCache();
try {
HttpRequest request = null;
if (agentid > 0) {
String material_media_download_uri = getRequestUri("material_media_download_uri");
request = new HttpRequest(HttpMethod.GET, String.format(
material_media_download_uri, token.getAccessToken(),
mediaId, agentid));
request = new HttpRequest(HttpMethod.GET,
String.format(material_media_download_uri, token.getAccessToken(), mediaId, agentid));
} else {
String media_download_uri = getRequestUri("media_download_uri");
request = new HttpRequest(HttpMethod.GET, String.format(
media_download_uri, token.getAccessToken(), mediaId));
request = new HttpRequest(HttpMethod.GET,
String.format(media_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) {
@@ -265,12 +239,11 @@ public class MediaApi extends QyApi {
* 图文列表
* @return 上传到微信服务器返回的媒体标识
* @throws WeixinException
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">上传永久媒体素材</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">上传永久媒体素材</a>
* @see com.foxinmy.weixin4j.tuple.MpArticle
*/
public String uploadMaterialArticle(int agentid, List<MpArticle> articles)
throws WeixinException {
public String uploadMaterialArticle(int agentid, List<MpArticle> articles) throws WeixinException {
Token token = tokenManager.getCache();
String material_article_upload_uri = getRequestUri("material_article_upload_uri");
JSONObject obj = new JSONObject();
@@ -278,9 +251,8 @@ public class MediaApi extends QyApi {
JSONObject news = new JSONObject();
news.put("articles", articles);
obj.put("mpnews", news);
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");
}
@@ -294,17 +266,15 @@ public class MediaApi extends QyApi {
* 媒体素材的media_id
* @return 处理结果
* @throws WeixinException
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%A0%E9%99%A4%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">删除永久媒体素材</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%A0%E9%99%A4%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">删除永久媒体素材</a>
*/
public JsonResult deleteMaterialMedia(int agentid, String mediaId)
throws WeixinException {
public ApiResult deleteMaterialMedia(int agentid, String mediaId) throws WeixinException {
Token token = tokenManager.getCache();
String material_media_del_uri = getRequestUri("material_media_del_uri");
WeixinResponse response = weixinExecutor.get(String.format(
material_media_del_uri, token.getAccessToken(), mediaId,
agentid));
return response.getAsJsonResult();
WeixinResponse response = weixinExecutor
.get(String.format(material_media_del_uri, token.getAccessToken(), mediaId, agentid));
return response.getAsResult();
}
/**
@@ -319,14 +289,11 @@ public class MediaApi extends QyApi {
* @see {@link #downloadMedia(int, String)}
* @see com.foxinmy.weixin4j.tuple.MpArticle
*/
public List<MpArticle> downloadArticle(int agentid, String mediaId)
throws WeixinException {
public List<MpArticle> downloadArticle(int agentid, String mediaId) throws WeixinException {
MediaDownloadResult result = downloadMedia(agentid, mediaId);
byte[] content = result.getContent();
JSONObject obj = JSON.parseObject(content, 0, content.length,
Consts.UTF_8.newDecoder(), JSONObject.class);
return JSON.parseArray(obj.getJSONObject("mpnews")
.getString("articles"), MpArticle.class);
JSONObject obj = JSON.parseObject(content, 0, content.length, Consts.UTF_8.newDecoder(), JSONObject.class);
return JSON.parseArray(obj.getJSONObject("mpnews").getString("articles"), MpArticle.class);
}
/**
@@ -340,12 +307,11 @@ public class MediaApi extends QyApi {
* 图文列表
* @return 操作结果
* @throws WeixinException
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BF%AE%E6%94%B9%E6%B0%B8%E4%B9%85%E5%9B%BE%E6%96%87%E7%B4%A0%E6%9D%90">修改永久媒体素材</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BF%AE%E6%94%B9%E6%B0%B8%E4%B9%85%E5%9B%BE%E6%96%87%E7%B4%A0%E6%9D%90">修改永久媒体素材</a>
* @see com.foxinmy.weixin4j.tuple.MpArticle
*/
public String updateMaterialArticle(int agentid, String mediaId,
List<MpArticle> articles) throws WeixinException {
public String updateMaterialArticle(int agentid, String mediaId, List<MpArticle> articles) throws WeixinException {
Token token = tokenManager.getCache();
String material_article_update_uri = getRequestUri("material_article_update_uri");
JSONObject obj = new JSONObject();
@@ -354,9 +320,8 @@ public class MediaApi extends QyApi {
news.put("articles", articles);
obj.put("mpnews", news);
obj.put("media_id", mediaId);
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.getAsJson().getString("media_id");
}
@@ -369,14 +334,14 @@ public class MediaApi extends QyApi {
* @return 总数对象
* @throws WeixinException
* @see com.foxinmy.weixin4j.model.MediaCounter
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E6%80%BB%E6%95%B0">获取素材总数</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E6%80%BB%E6%95%B0">获取素材总数</a>
*/
public MediaCounter countMaterialMedia(int agentid) 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(), agentid));
WeixinResponse response = weixinExecutor
.get(String.format(material_media_count_uri, token.getAccessToken(), agentid));
JSONObject result = response.getAsJson();
MediaCounter counter = JSON.toJavaObject(result, MediaCounter.class);
counter.setNewsCount(result.getIntValue("mpnews_count"));
@@ -399,21 +364,18 @@ public class MediaApi extends QyApi {
* @see com.foxinmy.weixin4j.model.MediaItem
* @see com.foxinmy.weixin4j.model.Pageable
* @see com.foxinmy.weixin4j.model.Pagedata
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">获取素材列表</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">获取素材列表</a>
*/
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
Pageable pageable) throws WeixinException {
public MediaRecord listMaterialMedia(int agentid, 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("agentid", agentid);
obj.put("type",
mediaType == MediaType.news ? "mpnews" : mediaType.name());
obj.put("type", mediaType == MediaType.news ? "mpnews" : 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());
obj = response.getAsJson();
@@ -435,15 +397,13 @@ public class MediaApi extends QyApi {
* @see {@link #listMaterialMedia(int,MediaType, Pageable)}
* @throws WeixinException
*/
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType)
throws WeixinException {
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType) throws WeixinException {
Pageable pageable = new Pageable(1, 20);
List<MediaItem> mediaList = new ArrayList<MediaItem>();
MediaRecord mediaRecord = null;
for (;;) {
mediaRecord = listMaterialMedia(agentid, mediaType, pageable);
if (mediaRecord.getItems() == null
|| mediaRecord.getItems().isEmpty()) {
if (mediaRecord.getItems() == null || mediaRecord.getItems().isEmpty()) {
break;
}
mediaList.addAll(mediaRecord.getItems());
@@ -462,8 +422,8 @@ public class MediaApi extends QyApi {
* 成员列表
* @see {@link BatchApi#syncUser(String,Callback)}
* @see {@link BatchApi#replaceUser(String,Callback)}
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E9.80.9A.E8.AE.AF.E5.BD.95.E6.9B.B4.E6.96.B0">批量任务</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E9.80.9A.E8.AE.AF.E5.BD.95.E6.9B.B4.E6.96.B0">批量任务</a>
* @return 上传后的mediaId
* @throws WeixinException
*/
@@ -477,22 +437,19 @@ public class MediaApi extends QyApi {
* @param parties
* 部门列表
* @see {@link BatchApi#replaceParty(String,Callback)}
* @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E9.80.9A.E8.AE.AF.E5.BD.95.E6.9B.B4.E6.96.B0">批量任务</a>
* @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E9.80.9A.E8.AE.AF.E5.BD.95.E6.9B.B4.E6.96.B0">批量任务</a>
* @return 上传后的mediaId
* @throws WeixinException
*/
public String batchUploadParties(List<Party> parties)
throws WeixinException {
public String batchUploadParties(List<Party> parties) throws WeixinException {
return batchUpload("batch_replaceparty.cvs", parties);
}
private <T> String batchUpload(String batchName, List<T> models)
throws WeixinException {
private <T> String batchUpload(String batchName, List<T> models) throws WeixinException {
StringWriter writer = new StringWriter();
try {
JSONObject csvObj = JSON.parseObject(weixinBundle().getString(
batchName));
JSONObject csvObj = JSON.parseObject(weixinBundle().getString(batchName));
JSONArray columns = csvObj.getJSONArray("column");
writer.write(csvObj.getString("header"));
final Map<String, Object> column = new LinkedHashMap<String, Object>();
@@ -503,13 +460,10 @@ public class MediaApi extends QyApi {
for (T model : models) {
JSON.toJSONString(model, new PropertyFilter() {
@Override
public boolean apply(Object object, String name,
Object value) {
public boolean apply(Object object, String name, Object value) {
if (column.containsKey(name)) {
if (value instanceof Collection) {
column.put(name,
StringUtil.join(((Collection<?>) value)
.iterator(), ';'));
column.put(name, StringUtil.join(((Collection<?>) value).iterator(), ';'));
} else {
column.put(name, value);
}
@@ -520,10 +474,8 @@ public class MediaApi extends QyApi {
writer.write(StringUtil.join(column.values(), ','));
writer.write("\r\n");
}
return uploadMedia(
0,
new ByteArrayInputStream(writer.getBuffer().toString()
.getBytes(Consts.UTF_8)), batchName).getMediaId();
return uploadMedia(0, new ByteArrayInputStream(writer.getBuffer().toString().getBytes(Consts.UTF_8)),
batchName).getMediaId();
} finally {
try {
writer.close();
@@ -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;
@@ -49,7 +49,7 @@ public class MenuApi extends QyApi {
* 创建自定义菜单</a>
* @see com.foxinmy.weixin4j.model.Button
*/
public JsonResult createMenu(int agentid, List<Button> buttons) throws WeixinException {
public ApiResult createMenu(int agentid, List<Button> buttons) throws WeixinException {
String menu_create_uri = getRequestUri("menu_create_uri");
Token token = tokenManager.getCache();
JSONObject obj = new JSONObject();
@@ -74,7 +74,7 @@ public class MenuApi extends QyApi {
}
}));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -119,11 +119,11 @@ public class MenuApi extends QyApi {
* 删除菜单</a>
* @return 处理结果
*/
public JsonResult deleteMenu(int agentid) throws WeixinException {
public ApiResult deleteMenu(int agentid) 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(), agentid));
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -8,7 +8,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.qy.message.CustomeMessage;
@@ -138,7 +138,7 @@ public class NotifyApi extends QyApi {
* @see com.foxinmy.weixin4j.qy.message.CustomeMessage
* @throws WeixinException
*/
public JsonResult sendCustomeMessage(CustomeMessage message)
public ApiResult sendCustomeMessage(CustomeMessage message)
throws WeixinException {
NotifyTuple tuple = message.getTuple();
String msgtype = tuple.getMessageType();
@@ -150,7 +150,7 @@ public class NotifyApi extends QyApi {
WeixinResponse response = weixinExecutor.post(
String.format(message_kf_send_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.qy.model.Party;
@@ -67,7 +67,7 @@ public class PartyApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult updateParty(Party party) throws WeixinException {
public ApiResult updateParty(Party party) throws WeixinException {
if (party.getId() < 1) {
throw new WeixinException("department id must gt 1");
}
@@ -83,7 +83,7 @@ public class PartyApi extends QyApi {
WeixinResponse response = weixinExecutor.post(
String.format(department_update_uri, token.getAccessToken()),
obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -119,11 +119,11 @@ public class PartyApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult deleteParty(int partId) throws WeixinException {
public ApiResult deleteParty(int partId) throws WeixinException {
String department_delete_uri = getRequestUri("department_delete_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(
department_delete_uri, token.getAccessToken(), partId));
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -3,7 +3,7 @@ package com.foxinmy.weixin4j.qy.api;
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.qy.model.AgentInfo;
@@ -117,7 +117,7 @@ public class SuiteApi extends QyApi {
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.AE.BE.E7.BD.AE.E6.8E.88.E6.9D.83.E9.85.8D.E7.BD.AE"
* >设置套件授权配置</a>
*/
public JsonResult setSuiteSession(int... appids) throws WeixinException {
public ApiResult setSuiteSession(int... appids) throws WeixinException {
String suite_set_session_uri = getRequestUri("suite_set_session_uri");
JSONObject para = new JSONObject();
para.put("pre_auth_code", preCodeManager.getAccessToken());
@@ -126,7 +126,7 @@ public class SuiteApi extends QyApi {
para.put("session_info", appid);
WeixinResponse response = weixinExecutor
.post(String.format(suite_set_session_uri, tokenManager.getAccessToken()), para.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -232,7 +232,7 @@ public class SuiteApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult setAgent(String authCorpId, AgentSetter agentSet) throws WeixinException {
public ApiResult setAgent(String authCorpId, AgentSetter agentSet) throws WeixinException {
String suite_set_agent_uri = getRequestUri("suite_set_agent_uri");
JSONObject obj = new JSONObject();
obj.put("suite_id", ticketManager.getThirdId());
@@ -241,6 +241,6 @@ public class SuiteApi extends QyApi {
obj.put("agent", agentSet);
WeixinResponse response = weixinExecutor.post(String.format(suite_set_agent_uri, tokenManager.getAccessToken()),
JSON.toJSONString(obj, AgentApi.typeFilter));
return response.getAsJsonResult();
return response.getAsResult();
}
}
@@ -6,7 +6,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.qy.model.Contacts;
@@ -70,13 +70,13 @@ public class TagApi extends QyApi {
* @see com.foxinmy.weixin4j.qy.model.Tag
* @throws WeixinException
*/
public JsonResult updateTag(Tag tag) throws WeixinException {
public ApiResult updateTag(Tag tag) throws WeixinException {
String tag_update_uri = getRequestUri("tag_update_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(
String.format(tag_update_uri, token.getAccessToken()),
JSON.toJSONString(tag));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -90,12 +90,12 @@ public class TagApi extends QyApi {
* 删除标签说明</a>
* @throws WeixinException
*/
public JsonResult deleteTag(int tagId) throws WeixinException {
public ApiResult deleteTag(int tagId) throws WeixinException {
String tag_delete_uri = getRequestUri("tag_delete_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
tag_delete_uri, token.getAccessToken(), tagId));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -8,7 +8,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.qy.model.OUserInfo;
@@ -52,7 +52,7 @@ public class UserApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult createUser(User user) throws WeixinException {
public ApiResult createUser(User user) throws WeixinException {
String user_create_uri = getRequestUri("user_create_uri");
return excute(user_create_uri, user, null);
}
@@ -71,7 +71,7 @@ public class UserApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult createUser(User user, InputStream avatar)
public ApiResult createUser(User user, InputStream avatar)
throws WeixinException {
String user_create_uri = getRequestUri("user_create_uri");
return excute(user_create_uri, user, avatar);
@@ -89,7 +89,7 @@ public class UserApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult updateUser(User user) throws WeixinException {
public ApiResult updateUser(User user) throws WeixinException {
String user_update_uri = getRequestUri("user_update_uri");
return excute(user_update_uri, user, null);
}
@@ -108,13 +108,13 @@ public class UserApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult updateUser(User user, InputStream avatar)
public ApiResult updateUser(User user, InputStream avatar)
throws WeixinException {
String user_update_uri = getRequestUri("user_update_uri");
return excute(user_update_uri, user, avatar);
}
private JsonResult excute(String uri, User user, InputStream avatar)
private ApiResult excute(String uri, User user, InputStream avatar)
throws WeixinException {
JSONObject obj = (JSONObject) JSON.toJSON(user);
Object val = obj.remove("extattr");
@@ -135,7 +135,7 @@ public class UserApi extends QyApi {
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(
String.format(uri, token.getAccessToken()), obj.toJSONString());
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -314,12 +314,12 @@ public class UserApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult deleteUser(String userid) throws WeixinException {
public ApiResult deleteUser(String userid) throws WeixinException {
String user_delete_uri = getRequestUri("user_delete_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
user_delete_uri, token.getAccessToken(), userid));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -333,7 +333,7 @@ public class UserApi extends QyApi {
* @return 处理结果
* @throws WeixinException
*/
public JsonResult batchDeleteUser(List<String> userIds)
public ApiResult batchDeleteUser(List<String> userIds)
throws WeixinException {
JSONObject obj = new JSONObject();
obj.put("useridlist", userIds);
@@ -341,7 +341,7 @@ public class UserApi extends QyApi {
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.post(String.format(
user_delete_uri, token.getAccessToken(), obj.toJSONString()));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -355,12 +355,12 @@ public class UserApi extends QyApi {
* 二次验证说明</a>
* @throws WeixinException
*/
public JsonResult authsucc(String userId) throws WeixinException {
public ApiResult authsucc(String userId) throws WeixinException {
String user_authsucc_uri = getRequestUri("user_authsucc_uri");
Token token = tokenManager.getCache();
WeixinResponse response = weixinExecutor.get(String.format(
user_authsucc_uri, token.getAccessToken(), userId));
return response.getAsJsonResult();
return response.getAsResult();
}
/**
@@ -2,7 +2,7 @@ package com.foxinmy.weixin4j.qy.model;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.message.ApiResult;
import com.foxinmy.weixin4j.qy.type.BatchStatus;
import com.foxinmy.weixin4j.qy.type.BatchType;
@@ -15,7 +15,7 @@ import com.foxinmy.weixin4j.qy.type.BatchType;
* @since JDK 1.6
* @see
*/
public class BatchResult extends JsonResult {
public class BatchResult extends ApiResult {
private static final long serialVersionUID = 4985338631992208903L;
/**
@@ -107,8 +107,7 @@ public class BatchResult extends JsonResult {
@Override
public String toString() {
return "BatchResult [status=" + status + ", type=" + type + ", total="
+ total + ", percentAge=" + percentAge + ", remainTime="
+ remainTime + ", result=" + result + "]";
return "BatchResult [" + super.toString() + ", status=" + status + ", type=" + type + ", total=" + total
+ ", percentAge=" + percentAge + ", remainTime=" + remainTime + ", result=" + result + "]";
}
}
@@ -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.qy.api.AgentApi;
import com.foxinmy.weixin4j.qy.model.AgentInfo;
import com.foxinmy.weixin4j.qy.model.AgentOverview;
@@ -44,8 +44,8 @@ public class AgentTest extends TokenTest {
agentSet.setDescription("test");
agentSet.setRedirectDomain("test.com");
agentSet.setReportLocationType(ReportLocationType.DIALOG);
JsonResult result = agentApi.setAgent(agentSet);
Assert.assertTrue(result.getCode() == 0);
ApiResult result = agentApi.setAgent(agentSet);
Assert.assertEquals("0",result.getReturnCode());
}
@Test
@@ -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.qy.api.MenuApi;
import com.foxinmy.weixin4j.type.ButtonType;
@@ -42,8 +42,8 @@ public class MenuTest extends TokenTest {
btnList.add(b);
b = new Button("photo", "photo", ButtonType.pic_photo_or_album);
btnList.add(b);
JsonResult result = menuApi.createMenu(1, btnList);
Assert.assertEquals(0, result.getCode());
ApiResult result = menuApi.createMenu(1, btnList);
Assert.assertEquals(0, result.getReturnCode());
}
@Test
@@ -57,7 +57,7 @@ public class MenuTest extends TokenTest {
@Test
public void delete() throws WeixinException {
JsonResult result = menuApi.deleteMenu(1);
Assert.assertEquals(0, result.getCode());
ApiResult result = menuApi.deleteMenu(1);
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.qy.api.PartyApi;
import com.foxinmy.weixin4j.qy.model.Party;
@@ -38,8 +38,8 @@ public class PartyTest extends TokenTest {
@Test
public void update() throws WeixinException {
Party Party = new Party(2, "苦逼组111", 1);
JsonResult result = partyApi.updateParty(Party);
Assert.assertEquals("updated", result.getDesc());
ApiResult result = partyApi.updateParty(Party);
Assert.assertEquals("updated", result.getReturnMsg());
}
@Test
@@ -51,7 +51,7 @@ public class PartyTest extends TokenTest {
@Test
public void delete() throws WeixinException {
JsonResult result = partyApi.deleteParty(2);
Assert.assertEquals("deleted", result.getDesc());
ApiResult result = partyApi.deleteParty(2);
Assert.assertEquals("deleted", result.getReturnMsg());
}
}
@@ -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.qy.api.TagApi;
import com.foxinmy.weixin4j.qy.model.Contacts;
import com.foxinmy.weixin4j.qy.model.IdParameter;
@@ -39,8 +39,8 @@ public class TagTest extends TokenTest {
@Test
public void update() throws WeixinException {
JsonResult result = tagApi.updateTag(new Tag(1, "coder456"));
Assert.assertEquals("updated", result.getDesc());
ApiResult result = tagApi.updateTag(new Tag(1, "coder456"));
Assert.assertEquals("updated", result.getReturnMsg());
}
@Test
@@ -73,7 +73,7 @@ public class TagTest extends TokenTest {
@Test
public void delete() throws WeixinException {
JsonResult result = tagApi.deleteTag(3);
Assert.assertEquals("deleted", result.getDesc());
ApiResult result = tagApi.deleteTag(3);
Assert.assertEquals("deleted", result.getReturnMsg());
}
}
@@ -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.qy.api.MediaApi;
import com.foxinmy.weixin4j.qy.api.UserApi;
import com.foxinmy.weixin4j.qy.model.User;
@@ -38,8 +38,8 @@ public class UserTest extends TokenTest {
User user = new User("id", "name");
user.setPartyIds(1);
user.pushExattr("爱好", "code");
JsonResult result = userApi.createUser(user);
Assert.assertEquals("created", result.getDesc());
ApiResult result = userApi.createUser(user);
Assert.assertEquals("created", result.getReturnMsg());
}
@Test
@@ -55,8 +55,8 @@ public class UserTest extends TokenTest {
User user = new User("id", "name");
user.setPartyIds(1);
user.pushExattr("爱好", "code");
JsonResult result = userApi.updateUser(user);
Assert.assertEquals("updated", result.getDesc());
ApiResult result = userApi.updateUser(user);
Assert.assertEquals("updated", result.getReturnMsg());
}
@Test
@@ -75,8 +75,8 @@ public class UserTest extends TokenTest {
@Test
public void delete() throws WeixinException {
JsonResult result = userApi.deleteUser("u001");
Assert.assertEquals("deleted", result.getDesc());
ApiResult result = userApi.deleteUser("u001");
Assert.assertEquals("deleted", result.getReturnMsg());
}
@Test