diff --git a/pom.xml b/pom.xml index 22861b1..210279e 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,11 @@ commons-io ${commons-io.version} + + commons-beanutils + commons-beanutils + 1.9.4 + @@ -86,18 +91,6 @@ fastjson ${fastjson-lib.version} - - com.google.code.gson - gson - ${gson.version} - - - - net.sf.json-lib - json-lib - ${json-lib.version} - jdk15 - org.slf4j diff --git a/src/main/java/com/jeecg/qywx/api/conversation/ConversationAPI.java b/src/main/java/com/jeecg/qywx/api/conversation/ConversationAPI.java index 65c80bb..3526317 100644 --- a/src/main/java/com/jeecg/qywx/api/conversation/ConversationAPI.java +++ b/src/main/java/com/jeecg/qywx/api/conversation/ConversationAPI.java @@ -1,23 +1,17 @@ package com.jeecg.qywx.api.conversation; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.jeecg.qywx.api.base.JwAccessTokenAPI; -import com.jeecg.qywx.api.base.JwParamesAPI; import com.jeecg.qywx.api.conversation.vo.BaseMessage; import com.jeecg.qywx.api.conversation.vo.Conversation; import com.jeecg.qywx.api.conversation.vo.Conversation4Update; import com.jeecg.qywx.api.conversation.vo.Mute; -import com.jeecg.qywx.api.core.common.AccessToken; import com.jeecg.qywx.api.core.common.MsgResponse; import com.jeecg.qywx.api.core.util.HttpUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; /** * * @author SunHaiFeng diff --git a/src/main/java/com/jeecg/qywx/api/core/util/WXUpload.java b/src/main/java/com/jeecg/qywx/api/core/util/WXUpload.java index 8a59f91..7a9afa0 100644 --- a/src/main/java/com/jeecg/qywx/api/core/util/WXUpload.java +++ b/src/main/java/com/jeecg/qywx/api/core/util/WXUpload.java @@ -1,24 +1,15 @@ package com.jeecg.qywx.api.core.util; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; - -import org.apache.commons.lang.StringUtils; - import com.alibaba.fastjson.JSONObject; +import com.alipay.api.internal.util.StringUtils; import com.jeecg.qywx.api.base.JwAccessTokenAPI; import com.jeecg.qywx.api.base.JwParamesAPI; import com.jeecg.qywx.api.core.common.AccessToken; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; + public class WXUpload { private static final String upload_wechat_url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"; /** @@ -154,10 +145,10 @@ public static String getFileName(String fileUrl,String contentType) { public static void writeFile(byte[] data, String dir, String filename, boolean cover) { try { - if (StringUtils.isBlank(dir)) { + if (StringUtils.isEmpty(dir)) { throw new Exception("目录不能为空"); } - if (StringUtils.isBlank(filename)) { + if (StringUtils.isEmpty(filename)) { throw new Exception("文件名称不能为空"); } File dirfile = new File(dir); diff --git a/src/main/java/com/jeecg/qywx/api/department/JwDepartmentAPI.java b/src/main/java/com/jeecg/qywx/api/department/JwDepartmentAPI.java index 6ad340b..b5c1c0f 100644 --- a/src/main/java/com/jeecg/qywx/api/department/JwDepartmentAPI.java +++ b/src/main/java/com/jeecg/qywx/api/department/JwDepartmentAPI.java @@ -1,11 +1,11 @@ package com.jeecg.qywx.api.department; import java.util.List; + +import com.alibaba.fastjson.JSON; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.fastjson.JSONObject; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.jeecg.qywx.api.base.JwAccessTokenAPI; import com.jeecg.qywx.api.base.JwParamesAPI; import com.jeecg.qywx.api.core.common.AccessToken; @@ -97,8 +97,8 @@ public static List getAllDepartment(String accessToken) { int errcode = jsonObject.getIntValue("errcode"); String errmsg = jsonObject.getString("errmsg"); String departmentjson = jsonObject.getString("department"); - Gson gson = new Gson(); - List ps = gson.fromJson(departmentjson, new TypeToken>(){}.getType()); + + List ps = JSON.parseArray(departmentjson, Department.class); return ps; } return null; diff --git a/src/main/java/com/jeecg/weibo/api/WeiboAccountApi.java b/src/main/java/com/jeecg/weibo/api/WeiboAccountApi.java index cc73c9d..3a64331 100644 --- a/src/main/java/com/jeecg/weibo/api/WeiboAccountApi.java +++ b/src/main/java/com/jeecg/weibo/api/WeiboAccountApi.java @@ -1,6 +1,6 @@ package com.jeecg.weibo.api; -import org.apache.commons.lang.StringUtils; +import com.alipay.api.internal.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/jeecg/weibo/api/WeiboSendApi.java b/src/main/java/com/jeecg/weibo/api/WeiboSendApi.java index 9aaaa3a..72a5988 100644 --- a/src/main/java/com/jeecg/weibo/api/WeiboSendApi.java +++ b/src/main/java/com/jeecg/weibo/api/WeiboSendApi.java @@ -1,6 +1,6 @@ package com.jeecg.weibo.api; -import org.apache.commons.lang.StringUtils; +import com.alipay.api.internal.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/jeecg/weibo/dto/WeiboSendDto.java b/src/main/java/com/jeecg/weibo/dto/WeiboSendDto.java index ded51b5..88b2df8 100644 --- a/src/main/java/com/jeecg/weibo/dto/WeiboSendDto.java +++ b/src/main/java/com/jeecg/weibo/dto/WeiboSendDto.java @@ -1,8 +1,8 @@ package com.jeecg.weibo.dto; -import java.net.URLEncoder; +import com.alipay.api.internal.util.StringUtils; -import org.apache.commons.lang.StringUtils; +import java.net.URLEncoder; /** * 发布微博 @@ -27,7 +27,7 @@ public void setAccess_token(String access_token) { } public String getStatus() { String encode = ""; - if(StringUtils.isNotEmpty(status)){ + if(!StringUtils.isEmpty(status)){ encode = URLEncoder.encode(status); } return encode; diff --git a/src/main/java/com/jeecg/weibo/util/WeiboCommentsUtil.java b/src/main/java/com/jeecg/weibo/util/WeiboCommentsUtil.java index 9f49c80..adf24f4 100644 --- a/src/main/java/com/jeecg/weibo/util/WeiboCommentsUtil.java +++ b/src/main/java/com/jeecg/weibo/util/WeiboCommentsUtil.java @@ -1,7 +1,6 @@ package com.jeecg.weibo.util; -import org.apache.commons.lang.StringUtils; - +import com.alipay.api.internal.util.StringUtils; import com.jeecg.weibo.dto.WeiBoMentionsDto; import com.jeecg.weibo.exception.BusinessException; @@ -23,22 +22,22 @@ public static void getBymeParmValidate(WeiBoMentionsDto mentions){ public static String getBymeUrl (String interUrl,WeiBoMentionsDto mentions){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(mentions.getAccess_token())){ + if(!StringUtils.isEmpty(mentions.getAccess_token())){ requestUrl.append("&access_token="+mentions.getAccess_token()); } - if(StringUtils.isNotEmpty(mentions.getSince_id())){ + if(!StringUtils.isEmpty(mentions.getSince_id())){ requestUrl.append("&since_id="+mentions.getSince_id()); } - if(StringUtils.isNotEmpty(mentions.getMax_id())){ + if(!StringUtils.isEmpty(mentions.getMax_id())){ requestUrl.append("&max_id="+mentions.getMax_id()); } - if(StringUtils.isNotEmpty(mentions.getCount())){ + if(!StringUtils.isEmpty(mentions.getCount())){ requestUrl.append("&count="+mentions.getCount()); } - if(StringUtils.isNotEmpty(mentions.getPage())){ + if(!StringUtils.isEmpty(mentions.getPage())){ requestUrl.append("&page="+mentions.getPage()); } - if(StringUtils.isNotEmpty(mentions.getFilter_by_source())){ + if(!StringUtils.isEmpty(mentions.getFilter_by_source())){ requestUrl.append("&filter_by_source="+mentions.getFilter_by_source()); } return requestUrl.toString(); @@ -50,25 +49,25 @@ public static String getBymeUrl (String interUrl,WeiBoMentionsDto mentions){ public static String getTomeUrl (String interUrl,WeiBoMentionsDto mentions){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(mentions.getAccess_token())){ + if(!StringUtils.isEmpty(mentions.getAccess_token())){ requestUrl.append("&access_token="+mentions.getAccess_token()); } - if(StringUtils.isNotEmpty(mentions.getSince_id())){ + if(!StringUtils.isEmpty(mentions.getSince_id())){ requestUrl.append("&since_id="+mentions.getSince_id()); } - if(StringUtils.isNotEmpty(mentions.getMax_id())){ + if(!StringUtils.isEmpty(mentions.getMax_id())){ requestUrl.append("&max_id="+mentions.getMax_id()); } - if(StringUtils.isNotEmpty(mentions.getCount())){ + if(!StringUtils.isEmpty(mentions.getCount())){ requestUrl.append("&count="+mentions.getCount()); } - if(StringUtils.isNotEmpty(mentions.getPage())){ + if(!StringUtils.isEmpty(mentions.getPage())){ requestUrl.append("&page="+mentions.getPage()); } - if(StringUtils.isNotEmpty(mentions.getFilter_by_author())){ + if(!StringUtils.isEmpty(mentions.getFilter_by_author())){ requestUrl.append("&filter_by_author="+mentions.getFilter_by_author()); } - if(StringUtils.isNotEmpty(mentions.getFilter_by_source())){ + if(!StringUtils.isEmpty(mentions.getFilter_by_source())){ requestUrl.append("&filter_by_source="+mentions.getFilter_by_source()); } return requestUrl.toString(); diff --git a/src/main/java/com/jeecg/weibo/util/WeiboFollowersUtil.java b/src/main/java/com/jeecg/weibo/util/WeiboFollowersUtil.java index e4d62f6..50da309 100644 --- a/src/main/java/com/jeecg/weibo/util/WeiboFollowersUtil.java +++ b/src/main/java/com/jeecg/weibo/util/WeiboFollowersUtil.java @@ -1,6 +1,6 @@ package com.jeecg.weibo.util; -import org.apache.commons.lang.StringUtils; +import com.alipay.api.internal.util.StringUtils; import com.jeecg.weibo.dto.WeiboFollowersDto; import com.jeecg.weibo.exception.BusinessException; @@ -26,22 +26,22 @@ public static void getFollowersParmValidate(WeiboFollowersDto followers){ public static String getFollowersUrl (String interUrl,WeiboFollowersDto followers){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(followers.getAccess_token())){ + if(!StringUtils.isEmpty(followers.getAccess_token())){ requestUrl.append("&access_token="+followers.getAccess_token()); } - if(StringUtils.isNotEmpty(followers.getUid())){ + if(!StringUtils.isEmpty(followers.getUid())){ requestUrl.append("&uid="+followers.getUid()); } - if(StringUtils.isNotEmpty(followers.getScreen_name())){ + if(!StringUtils.isEmpty(followers.getScreen_name())){ requestUrl.append("&screen_name="+followers.getScreen_name()); } - if(StringUtils.isNotEmpty(followers.getCount())){ + if(!StringUtils.isEmpty(followers.getCount())){ requestUrl.append("&count="+followers.getCount()); } - if(StringUtils.isNotEmpty(followers.getCursor())){ + if(!StringUtils.isEmpty(followers.getCursor())){ requestUrl.append("&cursor="+followers.getCursor()); } - if(StringUtils.isNotEmpty(followers.getTrim_status())){ + if(!StringUtils.isEmpty(followers.getTrim_status())){ requestUrl.append("&trim_status="+followers.getTrim_status()); } return requestUrl.toString(); @@ -63,19 +63,19 @@ public static void getFollowersIdsParmValidate(WeiboFollowersDto followers){ public static String getFollowersIdsUrl(String interUrl,WeiboFollowersDto followers){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(followers.getAccess_token())){ + if(!StringUtils.isEmpty(followers.getAccess_token())){ requestUrl.append("&access_token="+followers.getAccess_token()); } - if(StringUtils.isNotEmpty(followers.getUid())){ + if(!StringUtils.isEmpty(followers.getUid())){ requestUrl.append("&uid="+followers.getUid()); } - if(StringUtils.isNotEmpty(followers.getScreen_name())){ + if(!StringUtils.isEmpty(followers.getScreen_name())){ requestUrl.append("&screen_name="+followers.getScreen_name()); } - if(StringUtils.isNotEmpty(followers.getCount())){ + if(!StringUtils.isEmpty(followers.getCount())){ requestUrl.append("&count="+followers.getCount()); } - if(StringUtils.isNotEmpty(followers.getCursor())){ + if(!StringUtils.isEmpty(followers.getCursor())){ requestUrl.append("&cursor="+followers.getCursor()); } return requestUrl.toString(); diff --git a/src/main/java/com/jeecg/weibo/util/WeiboSendUtil.java b/src/main/java/com/jeecg/weibo/util/WeiboSendUtil.java index 69dbb9e..1de3a69 100644 --- a/src/main/java/com/jeecg/weibo/util/WeiboSendUtil.java +++ b/src/main/java/com/jeecg/weibo/util/WeiboSendUtil.java @@ -2,7 +2,7 @@ import java.net.URLEncoder; -import org.apache.commons.lang.StringUtils; +import com.alipay.api.internal.util.StringUtils; import com.jeecg.weibo.dto.WeiboSendDto; import com.jeecg.weibo.exception.BusinessException; @@ -29,13 +29,13 @@ public static void getSendParmValidate(WeiboSendDto send){ public static String getSendUrl (String interUrl,WeiboSendDto send){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(send.getAccess_token())){ + if(!StringUtils.isEmpty(send.getAccess_token())){ requestUrl.append("&access_token="+send.getAccess_token()); } - if(StringUtils.isNotEmpty(send.getStatus())){ + if(!StringUtils.isEmpty(send.getStatus())){ requestUrl.append("&status="+send.getStatus()); } - if(StringUtils.isNotEmpty(send.getUrl())){ + if(!StringUtils.isEmpty(send.getUrl())){ String url = URLEncoder.encode(send.getUrl()); requestUrl.append("&url="+url); } @@ -55,10 +55,10 @@ public static void delParmValidate(WeiboSendDto send){ public static String getDelUrl (String interUrl,WeiboSendDto send){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(send.getAccess_token())){ + if(!StringUtils.isEmpty(send.getAccess_token())){ requestUrl.append("&access_token="+send.getAccess_token()); } - if(StringUtils.isNotEmpty(send.getId())){ + if(!StringUtils.isEmpty(send.getId())){ requestUrl.append("&id="+send.getId()); } return requestUrl.toString(); diff --git a/src/main/java/com/jeecg/weibo/util/WeiboStatusesUtil.java b/src/main/java/com/jeecg/weibo/util/WeiboStatusesUtil.java index 589b458..ef8522c 100644 --- a/src/main/java/com/jeecg/weibo/util/WeiboStatusesUtil.java +++ b/src/main/java/com/jeecg/weibo/util/WeiboStatusesUtil.java @@ -1,6 +1,6 @@ package com.jeecg.weibo.util; -import org.apache.commons.lang.StringUtils; +import com.alipay.api.internal.util.StringUtils; import com.jeecg.weibo.dto.WeiBoMentionsDto; import com.jeecg.weibo.dto.WeiboUserTimelineDto; @@ -23,34 +23,34 @@ public static void getUserTimelineParmValidate (WeiboUserTimelineDto userTimelin public static String getUserTimelineUrl (String interUrl,WeiboUserTimelineDto userTimeline){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(userTimeline.getAccess_token())){ + if(!StringUtils.isEmpty(userTimeline.getAccess_token())){ requestUrl.append("&access_token="+userTimeline.getAccess_token()); } - if(StringUtils.isNotEmpty(userTimeline.getUid())){ + if(!StringUtils.isEmpty(userTimeline.getUid())){ requestUrl.append("&uid="+userTimeline.getUid()); } - if(StringUtils.isNotEmpty(userTimeline.getScreen_name())){ + if(!StringUtils.isEmpty(userTimeline.getScreen_name())){ requestUrl.append("&screen_name="+userTimeline.getScreen_name()); } - if(StringUtils.isNotEmpty(userTimeline.getSince_id())){ + if(!StringUtils.isEmpty(userTimeline.getSince_id())){ requestUrl.append("&since_id="+userTimeline.getSince_id()); } - if(StringUtils.isNotEmpty(userTimeline.getMax_id())){ + if(!StringUtils.isEmpty(userTimeline.getMax_id())){ requestUrl.append("&max_id="+userTimeline.getMax_id()); } - if(StringUtils.isNotEmpty(userTimeline.getCount())){ + if(!StringUtils.isEmpty(userTimeline.getCount())){ requestUrl.append("&count="+userTimeline.getCount()); } - if(StringUtils.isNotEmpty(userTimeline.getPage())){ + if(!StringUtils.isEmpty(userTimeline.getPage())){ requestUrl.append("&page="+userTimeline.getPage()); } - if(StringUtils.isNotEmpty(userTimeline.getBase_app())){ + if(!StringUtils.isEmpty(userTimeline.getBase_app())){ requestUrl.append("&base_app="+userTimeline.getBase_app()); } - if(StringUtils.isNotEmpty(userTimeline.getFeature())){ + if(!StringUtils.isEmpty(userTimeline.getFeature())){ requestUrl.append("&feature="+userTimeline.getFeature()); } - if(StringUtils.isNotEmpty(userTimeline.getTrim_user())){ + if(!StringUtils.isEmpty(userTimeline.getTrim_user())){ requestUrl.append("trim_user="+userTimeline.getTrim_user()); } return requestUrl.toString(); @@ -66,7 +66,7 @@ public static void getUserTimelineIdsParmValidate (WeiboUserTimelineDto userTime if(StringUtils.isEmpty(userTimeline.getUid())&&(StringUtils.isEmpty(userTimeline.getScreen_name()))){ throw new BusinessException("uid与screen_name二者不能全为空"); } - if(StringUtils.isNotEmpty(userTimeline.getUid())&&(StringUtils.isNotEmpty(userTimeline.getScreen_name()))){ + if(!StringUtils.isEmpty(userTimeline.getUid())&&(!StringUtils.isEmpty(userTimeline.getScreen_name()))){ throw new BusinessException("uid与screen_name二者只能选其一"); } } @@ -96,10 +96,10 @@ public static void getCountParmValidate(String access_token,String ids){ public static String getCountUrl (String interUrl,String access_token,String ids){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(access_token)){ + if(!StringUtils.isEmpty(access_token)){ requestUrl.append("&access_token="+access_token); } - if(StringUtils.isNotEmpty(ids)){ + if(!StringUtils.isEmpty(ids)){ requestUrl.append("&ids="+ids); } return requestUrl.toString(); @@ -128,10 +128,10 @@ public static void getShowParmValidate(String access_token,String id){ public static String getShowUrl (String interUrl,String access_token,String id){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(access_token)){ + if(!StringUtils.isEmpty(access_token)){ requestUrl.append("&access_token="+access_token); } - if(StringUtils.isNotEmpty(id)){ + if(!StringUtils.isEmpty(id)){ requestUrl.append("&id="+id); } return requestUrl.toString(); @@ -153,28 +153,28 @@ public static void getMentionsParmValidate(WeiBoMentionsDto mentions){ public static String getMentionsUrl (String interUrl,WeiBoMentionsDto mentions){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(mentions.getAccess_token())){ + if(!StringUtils.isEmpty(mentions.getAccess_token())){ requestUrl.append("&access_token="+mentions.getAccess_token()); } - if(StringUtils.isNotEmpty(mentions.getSince_id())){ + if(!StringUtils.isEmpty(mentions.getSince_id())){ requestUrl.append("&since_id="+mentions.getSince_id()); } - if(StringUtils.isNotEmpty(mentions.getMax_id())){ + if(!StringUtils.isEmpty(mentions.getMax_id())){ requestUrl.append("&max_id="+mentions.getMax_id()); } - if(StringUtils.isNotEmpty(mentions.getCount())){ + if(!StringUtils.isEmpty(mentions.getCount())){ requestUrl.append("&count="+mentions.getCount()); } - if(StringUtils.isNotEmpty(mentions.getPage())){ + if(!StringUtils.isEmpty(mentions.getPage())){ requestUrl.append("&page="+mentions.getPage()); } - if(StringUtils.isNotEmpty(mentions.getFilter_by_author())){ + if(!StringUtils.isEmpty(mentions.getFilter_by_author())){ requestUrl.append("&filter_by_author="+mentions.getFilter_by_author()); } - if(StringUtils.isNotEmpty(mentions.getFilter_by_source())){ + if(!StringUtils.isEmpty(mentions.getFilter_by_source())){ requestUrl.append("&filter_by_source="+mentions.getFilter_by_source()); } - if(StringUtils.isNotEmpty(mentions.getFilter_by_type())){ + if(!StringUtils.isEmpty(mentions.getFilter_by_type())){ requestUrl.append("&filter_by_type="+mentions.getFilter_by_type()); } return requestUrl.toString(); diff --git a/src/main/java/com/jeecg/weibo/util/WeiboUsersUtil.java b/src/main/java/com/jeecg/weibo/util/WeiboUsersUtil.java index 58920bc..d12cd13 100644 --- a/src/main/java/com/jeecg/weibo/util/WeiboUsersUtil.java +++ b/src/main/java/com/jeecg/weibo/util/WeiboUsersUtil.java @@ -1,7 +1,6 @@ package com.jeecg.weibo.util; -import org.apache.commons.lang.StringUtils; - +import com.alipay.api.internal.util.StringUtils; import com.jeecg.weibo.exception.BusinessException; public class WeiboUsersUtil { @@ -17,7 +16,7 @@ public static void getShowParmValidate(String access_token,String uid,String scr if(StringUtils.isEmpty(uid)&&StringUtils.isEmpty(screen_name)){ throw new BusinessException("uid与screen_name二者不能全为空"); } - if(StringUtils.isNotEmpty(uid)&&StringUtils.isNotEmpty(screen_name)){ + if(!StringUtils.isEmpty(uid)&&!StringUtils.isEmpty(screen_name)){ throw new BusinessException("uid与screen_name二者只能选其一"); } } @@ -28,13 +27,13 @@ public static void getShowParmValidate(String access_token,String uid,String scr public static String getShowUrl (String interUrl,String access_token,String uid,String screen_name){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(access_token)){ + if(!StringUtils.isEmpty(access_token)){ requestUrl.append("&access_token="+access_token); } - if(StringUtils.isNotEmpty(uid)){ + if(!StringUtils.isEmpty(uid)){ requestUrl.append("&uid="+uid); } - if(StringUtils.isNotEmpty(screen_name)){ + if(!StringUtils.isEmpty(screen_name)){ requestUrl.append("&screen_name="+screen_name); } return requestUrl.toString(); @@ -64,10 +63,10 @@ public static void getCountsParmValidate(String access_token,String uids){ public static String getCountsUrl (String interUrl,String access_token,String uids){ StringBuilder requestUrl=new StringBuilder(); requestUrl.append(interUrl); - if(StringUtils.isNotEmpty(access_token)){ + if(!StringUtils.isEmpty(access_token)){ requestUrl.append("&access_token="+access_token); } - if(StringUtils.isNotEmpty(uids)){ + if(!StringUtils.isEmpty(uids)){ requestUrl.append("&uids="+uids); } return requestUrl.toString(); diff --git a/src/main/java/org/jeewx/api/ai/JwAIApi.java b/src/main/java/org/jeewx/api/ai/JwAIApi.java index 62ba2b1..fe66cbe 100644 --- a/src/main/java/org/jeewx/api/ai/JwAIApi.java +++ b/src/main/java/org/jeewx/api/ai/JwAIApi.java @@ -12,13 +12,12 @@ import java.net.HttpURLConnection; import java.net.URL; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.ai.model.Voice; import org.jeewx.api.core.util.WeiXinConstant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sf.json.JSONObject; - /** * 微信--AI开放接口 * @@ -30,18 +29,18 @@ public class JwAIApi { /** * 提交语音 */ - public static final String ADD_VOICE_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?"; + public static final String ADD_VOICE_URL = "https://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?"; /** * 获取语音翻译结果 */ - public static final String VOICE_RESULT_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext?"; + public static final String VOICE_RESULT_URL = "https://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext?"; /** * 翻译接口 */ - public static final String TRANSLATE_TEXT_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?"; + public static final String TRANSLATE_TEXT_URL = "https://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?"; /** @@ -174,7 +173,7 @@ private static JSONObject uploadVoice(Voice voice){ reader.close(); } } - jsonobject = JSONObject.fromObject(result); + jsonobject = JSONObject.parseObject(result); } catch (Exception e) { logger.info(e.getMessage()); e.printStackTrace(); @@ -266,7 +265,7 @@ private static JSONObject httpRequest(String requestUrl, httpUrlConn.disconnect(); logger.info(buffer.toString()); //jsonObject = JSONObject.parseObject(buffer.toString()); - jsonObject = JSONObject.fromObject(buffer.toString()); + jsonObject = JSONObject.parseObject(buffer.toString()); } catch (ConnectException ce) { ce.printStackTrace(); logger diff --git a/src/main/java/org/jeewx/api/core/common/AccessToken.java b/src/main/java/org/jeewx/api/core/common/AccessToken.java index 6f4b3ad..ce60b5f 100644 --- a/src/main/java/org/jeewx/api/core/common/AccessToken.java +++ b/src/main/java/org/jeewx/api/core/common/AccessToken.java @@ -1,6 +1,6 @@ package org.jeewx.api.core.common; -import net.sf.json.JSONObject; +import com.alibaba.fastjson.JSONObject; public class AccessToken { diff --git a/src/main/java/org/jeewx/api/core/common/JSONHelper.java b/src/main/java/org/jeewx/api/core/common/JSONHelper.java index 26171e9..a71ee23 100644 --- a/src/main/java/org/jeewx/api/core/common/JSONHelper.java +++ b/src/main/java/org/jeewx/api/core/common/JSONHelper.java @@ -6,8 +6,9 @@ import java.util.List; import java.util.Map; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.apache.commons.beanutils.BeanUtils; import org.slf4j.Logger; @@ -21,73 +22,18 @@ public final class JSONHelper { private static final Logger logger = LoggerFactory.getLogger(JSONHelper.class); - // 将数组转换成JSON - public static String array2json(Object object) { - JSONArray jsonArray = JSONArray.fromObject(object); - return jsonArray.toString(); - } - - // 将JSON转换成数组,其中valueClz为数组中存放的对象的Class - public static Object json2Array(String json, Class valueClz) { - JSONArray jsonArray = JSONArray.fromObject(json); - return JSONArray.toArray(jsonArray, valueClz); - } - - // 将Collection转换成JSON - public static String collection2json(Object object) { - JSONArray jsonArray = JSONArray.fromObject(object); - return jsonArray.toString(); - } - - // 将Map转换成JSON - public static String map2json(Object object) { - JSONObject jsonObject = JSONObject.fromObject(object); - return jsonObject.toString(); - } - - // 将JSON转换成Map,其中valueClz为Map中value的Class,keyArray为Map的key - public static Map json2Map(Object[] keyArray, String json, Class valueClz) { - JSONObject jsonObject = JSONObject.fromObject(json); - Map classMap = new HashMap(); - - for (int i = 0; i < keyArray.length; i++) { - classMap.put(keyArray[i], valueClz); - } - - return (Map) JSONObject.toBean(jsonObject, Map.class, classMap); - } // 将POJO转换成JSON public static String bean2json(Object object) { - JSONObject jsonObject = JSONObject.fromObject(object); + JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object)); return jsonObject.toString(); } - // 将JSON转换成POJO,其中beanClz为POJO的Class - public static Object json2Object(String json, Class beanClz) { - return JSONObject.toBean(JSONObject.fromObject(json), beanClz); - } - - // 将String转换成JSON - public static String string2json(String key, String value) { - JSONObject object = new JSONObject(); - object.put(key, value); - return object.toString(); - } - - // 将JSON转换成String - public static String json2String(String json, String key) { - JSONObject jsonObject = JSONObject.fromObject(json); - return jsonObject.get(key).toString(); - } - /*** * 将List对象序列化为JSON文本 */ public static String toJSONString(List list) { - JSONArray jsonArray = JSONArray.fromObject(list); - - return jsonArray.toString(); + return JSON.toJSONString(list); } /*** @@ -97,9 +43,7 @@ public static String toJSONString(List list) { * @return */ public static String toJSONString(Object object) { - JSONArray jsonArray = JSONArray.fromObject(object); - - return jsonArray.toString(); + return JSON.toJSONString(object); } /*** @@ -122,54 +66,6 @@ public static String toJSONString(JSONObject jsonObject) { return jsonObject.toString(); } - /*** - * 将对象转换为List对象 - * - * @param object - * @return - */ - public static List toArrayList(Object object) { - List arrayList = new ArrayList(); - - JSONArray jsonArray = JSONArray.fromObject(object); - - Iterator it = jsonArray.iterator(); - while (it.hasNext()) { - JSONObject jsonObject = (JSONObject) it.next(); - - Iterator keys = jsonObject.keys(); - while (keys.hasNext()) { - Object key = keys.next(); - Object value = jsonObject.get(key); - arrayList.add(value); - } - } - - return arrayList; - } - - /* *//*** - * 将对象转换为Collection对象 - * - * @param object - * @return - */ - /* - * public static Collection toCollection(Object object) { JSONArray - * jsonArray = JSONArray.fromObject(object); - * - * return JSONArray.toCollection(jsonArray); } - */ - - /*** - * 将对象转换为JSON对象数组 - * - * @param object - * @return - */ - public static JSONArray toJSONArray(Object object) { - return JSONArray.fromObject(object); - } /*** * 将对象转换为JSON对象 @@ -178,26 +74,7 @@ public static JSONArray toJSONArray(Object object) { * @return */ public static JSONObject toJSONObject(Object object) { - return JSONObject.fromObject(object); - } - - /*** - * 将对象转换为HashMap - * - * @param object - * @return - */ - public static HashMap toHashMap(Object object) { - HashMap data = new HashMap(); - JSONObject jsonObject = JSONHelper.toJSONObject(object); - Iterator it = jsonObject.keys(); - while (it.hasNext()) { - String key = String.valueOf(it.next()); - Object value = jsonObject.get(key); - data.put(key, value); - } - - return data; + return JSONObject.parseObject(JSON.toJSONString(object)); } /*** @@ -209,11 +86,11 @@ public static HashMap toHashMap(Object object) { // 返回非实体类型(Map)的List public static List> toList(Object object) { List> list = new ArrayList>(); - JSONArray jsonArray = JSONArray.fromObject(object); + JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(object)); for (Object obj : jsonArray) { JSONObject jsonObject = (JSONObject) obj; Map map = new HashMap(); - Iterator it = jsonObject.keys(); + Iterator it = jsonObject.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); Object value = jsonObject.get(key); @@ -233,7 +110,7 @@ public static List> toList(Object object) { * @return */ public static List toList(JSONArray jsonArray, Class objectClass) { - return JSONArray.toList(jsonArray, objectClass); + return jsonArray.toJavaList(objectClass); } /*** @@ -246,9 +123,9 @@ public static List toList(JSONArray jsonArray, Class objectClass) { */ @SuppressWarnings("unchecked") public static List toList(Object object, Class objectClass) { - JSONArray jsonArray = JSONArray.fromObject(object); + JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(object)); - return JSONArray.toList(jsonArray, objectClass); + return jsonArray.toJavaList(objectClass); } /*** @@ -261,7 +138,7 @@ public static List toList(Object object, Class objectClass) { */ @SuppressWarnings("unchecked") public static T toBean(JSONObject jsonObject, Class beanClass) { - return (T) JSONObject.toBean(jsonObject, beanClass); + return jsonObject.toJavaObject(beanClass); } /*** @@ -273,9 +150,9 @@ public static T toBean(JSONObject jsonObject, Class beanClass) { * @return */ public static T toBean(Object object, Class beanClass) { - JSONObject jsonObject = JSONObject.fromObject(object); + JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object)); - return (T) JSONObject.toBean(jsonObject, beanClass); + return jsonObject.toJavaObject(beanClass); } /*** @@ -297,7 +174,7 @@ public static T toBean(Object object, Class beanClass) { */ public static T toBean(String jsonString, Class mainClass, String detailName, Class detailClass) { - JSONObject jsonObject = JSONObject.fromObject(jsonString); + JSONObject jsonObject = JSONObject.parseObject(jsonString); JSONArray jsonArray = (JSONArray) jsonObject.get(detailName); T mainEntity = JSONHelper.toBean(jsonObject, mainClass); @@ -335,7 +212,7 @@ public static T toBean(String jsonString, Class mainClass, public static T toBean(String jsonString, Class mainClass, String detailName1, Class detailClass1, String detailName2, Class detailClass2) { - JSONObject jsonObject = JSONObject.fromObject(jsonString); + JSONObject jsonObject = JSONObject.parseObject(jsonString); JSONArray jsonArray1 = (JSONArray) jsonObject.get(detailName1); JSONArray jsonArray2 = (JSONArray) jsonObject.get(detailName2); @@ -381,7 +258,7 @@ public static T toBean(String jsonString, Class mainClass, String detailName1, Class detailClass1, String detailName2, Class detailClass2, String detailName3, Class detailClass3) { - JSONObject jsonObject = JSONObject.fromObject(jsonString); + JSONObject jsonObject = JSONObject.parseObject(jsonString); JSONArray jsonArray1 = (JSONArray) jsonObject.get(detailName1); JSONArray jsonArray2 = (JSONArray) jsonObject.get(detailName2); JSONArray jsonArray3 = (JSONArray) jsonObject.get(detailName3); @@ -417,7 +294,7 @@ public static T toBean(String jsonString, */ public static T toBean(String jsonString, Class mainClass, HashMap detailClass) { - JSONObject jsonObject = JSONObject.fromObject(jsonString); + JSONObject jsonObject = JSONObject.parseObject(jsonString); T mainEntity = JSONHelper.toBean(jsonObject, mainClass); for (Object key : detailClass.keySet()) { try { diff --git a/src/main/java/org/jeewx/api/core/common/WxstoreUtils.java b/src/main/java/org/jeewx/api/core/common/WxstoreUtils.java index 2a24eaf..b9adffe 100644 --- a/src/main/java/org/jeewx/api/core/common/WxstoreUtils.java +++ b/src/main/java/org/jeewx/api/core/common/WxstoreUtils.java @@ -1,31 +1,20 @@ package org.jeewx.api.core.common; -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; +import com.alibaba.fastjson.JSONObject; +import org.jeewx.api.core.exception.WexinReqException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import java.io.*; import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.URL; import java.security.SecureRandom; import java.util.Base64; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; - -import org.jeewx.api.core.exception.WexinReqException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import net.sf.json.JSONObject; /** * @@ -37,7 +26,7 @@ public class WxstoreUtils { private static Logger logger = LoggerFactory.getLogger(WxstoreUtils.class); public static JSONObject httpRequest(String requestUrl, - String requestMethod, String outputStr) { + String requestMethod, String outputStr) { logger.debug("*********HTTPREQUEST START********"); logger.debug("*********requestUrl is "+ requestUrl+" END AND requestMethod IS" @@ -90,8 +79,8 @@ public static JSONObject httpRequest(String requestUrl, inputStream.close(); inputStream = null; httpUrlConn.disconnect(); - jsonObject = JSONObject.fromObject(buffer.toString()); - if (jsonObject.containsKey("errcode") && jsonObject.getInt("errcode") != 0) { + jsonObject = JSONObject.parseObject(buffer.toString()); + if (jsonObject.containsKey("errcode") && jsonObject.getInteger("errcode") != 0) { logger.debug("********* ERROR********{}",buffer.toString()); logger.debug("*********HTTPREQUEST END********"); throw new WexinReqException("httpRequest Method!errcode=" @@ -157,7 +146,7 @@ public static JSONObject httpRequest2(String requestUrl, inputStream.close(); inputStream = null; httpUrlConn.disconnect(); - jsonObject = JSONObject.fromObject(buffer.toString()); + jsonObject = JSONObject.parseObject(buffer.toString()); } catch (ConnectException ce) { System.out.print("Weixin server connection timed out."); } catch (Exception e) { @@ -280,7 +269,7 @@ public static JSONObject uploadMediaFile(String requestUrl, File file, bufferStr.append(str); } - jsonObject = JSONObject.fromObject(bufferStr.toString()); + jsonObject = JSONObject.parseObject(bufferStr.toString()); // System.out.println("-------------读取URL链接返回字符串--------------" + // bufferStr.toString()); @@ -397,7 +386,7 @@ public static JSONObject uploadMediaFileNews(String requestUrl, File file, reader.close(); } } - jsonObject = JSONObject.fromObject(result); + jsonObject = JSONObject.parseObject(result); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqMenuCreateHandler.java b/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqMenuCreateHandler.java index 9c3f4c6..b075fb0 100644 --- a/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqMenuCreateHandler.java +++ b/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqMenuCreateHandler.java @@ -1,9 +1,6 @@ package org.jeewx.api.core.handler.impl; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.alibaba.fastjson.JSON; import org.jeewx.api.core.annotation.ReqType; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.handler.WeiXinReqHandler; @@ -16,8 +13,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * 菜单创建的处理 @@ -63,13 +61,11 @@ private String getMenuButtonJson(String name,List b){ return json.append("]").toString(); } List sub_button = null; - //解决Gson对网页链接中的转义字符问题,改为不转义字符 - Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); String objJson = ""; for(WeixinButton m : b){ sub_button = m.getSub_button(); m.setSub_button(null); - objJson = gson.toJson(m); + objJson = JSON.toJSONString(m); json.append(objJson); if(sub_button != null && sub_button.size() > 0){ json.setLength(json.length()-1); diff --git a/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqTemplateMessageHandler.java b/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqTemplateMessageHandler.java index cf7bed1..dcd11f5 100644 --- a/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqTemplateMessageHandler.java +++ b/src/main/java/org/jeewx/api/core/handler/impl/WeixinReqTemplateMessageHandler.java @@ -1,8 +1,6 @@ package org.jeewx.api.core.handler.impl; -import java.util.HashMap; -import java.util.Map; - +import com.alibaba.fastjson.JSON; import org.jeewx.api.core.annotation.ReqType; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.handler.WeiXinReqHandler; @@ -15,7 +13,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; +import java.util.HashMap; +import java.util.Map; /** * 模板消息发送 @@ -56,33 +55,32 @@ public String doRequest(WeixinReqParam weixinReqParam) throws WexinReqException{ */ private String getMsgJson(IndustryTemplateMessageSend mc){ StringBuffer json = new StringBuffer(); - Gson gson = new Gson(); TemplateMessage tm = mc.getData(); mc.setData(null); - String objJson = gson.toJson(mc); + String objJson = JSON.toJSONString(mc); mc.setData(tm); json.append(objJson); json.setLength(json.length()-1); json.append(","); json.append("\"data\":{"); - objJson = gson.toJson(tm.getFirst()); + objJson = JSON.toJSONString(tm.getFirst()); json.append(" \"first\":"); json.append(objJson); json.append(","); - objJson = gson.toJson(tm.getKeynote1()); + objJson = JSON.toJSONString(tm.getKeynote1()); json.append(" \"keynote1\":"); json.append(objJson); json.append(","); - objJson = gson.toJson(tm.getKeynote2()); + objJson = JSON.toJSONString(tm.getKeynote2()); json.append(" \"keynote2\":"); json.append(objJson); json.append(","); - objJson = gson.toJson(tm.getKeynote3()); + objJson = JSON.toJSONString(tm.getKeynote3()); json.append(" \"keynote3\":"); json.append(objJson); json.append(","); - objJson = gson.toJson(tm.getRemark()); + objJson = JSON.toJSONString(tm.getRemark()); json.append(" \"remark\":"); json.append(objJson); json.append("}}"); diff --git a/src/main/java/org/jeewx/api/core/req/WeiXinReqService.java b/src/main/java/org/jeewx/api/core/req/WeiXinReqService.java index 49577f9..631b514 100644 --- a/src/main/java/org/jeewx/api/core/req/WeiXinReqService.java +++ b/src/main/java/org/jeewx/api/core/req/WeiXinReqService.java @@ -1,9 +1,6 @@ package org.jeewx.api.core.req; -import java.io.IOException; - -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONObject; import org.jdom.JDOMException; import org.jeewx.api.core.annotation.ReqType; import org.jeewx.api.core.exception.WexinReqException; @@ -14,6 +11,8 @@ import org.jeewx.api.core.util.WeiXinConstant; import org.jeewx.api.core.util.WeiXinReqUtil; +import java.io.IOException; + /** * 获取微信接口的信息 * @@ -83,7 +82,7 @@ public String doWeinxinReq(WeixinReqParam weixinReqParam) */ public JSONObject doWeinxinReqJson(WeixinReqParam weixinReqParam) throws WexinReqException{ String strResult = this.doWeinxinReq(weixinReqParam); - JSONObject result = JSONObject.fromObject(strResult); + JSONObject result = JSONObject.parseObject(strResult); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); if(error !=null && Integer.parseInt(error.toString())!=0){ throw new WexinReqException(result.toString()); diff --git a/src/main/java/org/jeewx/api/core/req/model/menu/WeixinMenuMatchrule.java b/src/main/java/org/jeewx/api/core/req/model/menu/WeixinMenuMatchrule.java index 0ef514a..63cf598 100644 --- a/src/main/java/org/jeewx/api/core/req/model/menu/WeixinMenuMatchrule.java +++ b/src/main/java/org/jeewx/api/core/req/model/menu/WeixinMenuMatchrule.java @@ -5,17 +5,17 @@ public class WeixinMenuMatchrule { private String group_id; - + @Deprecated private String sex; - + @Deprecated private String country; - + @Deprecated private String province; - + @Deprecated private String city; - + @Deprecated private String client_platform_type; - + @Deprecated private String language; public String getGroup_id() { diff --git a/src/main/java/org/jeewx/api/core/test/JsonTest.java b/src/main/java/org/jeewx/api/core/test/JsonTest.java index c74c88b..fd4bc7d 100644 --- a/src/main/java/org/jeewx/api/core/test/JsonTest.java +++ b/src/main/java/org/jeewx/api/core/test/JsonTest.java @@ -1,13 +1,12 @@ package org.jeewx.api.core.test; -import java.util.ArrayList; -import java.util.List; - +import com.alibaba.fastjson.JSON; import org.jeewx.api.core.req.model.kfaccount.KfcustomSend; import org.jeewx.api.core.req.model.kfaccount.MsgArticles; import org.jeewx.api.core.req.model.kfaccount.MsgNews; -import com.google.gson.Gson; +import java.util.ArrayList; +import java.util.List; public class JsonTest { @@ -34,8 +33,7 @@ public static void main(String[] args){ n.setArticles(lst); s.setNews(n); - Gson gson = new Gson(); - String json = gson.toJson(s); + String json = JSON.toJSONString(s); System.out.println(json); } } diff --git a/src/main/java/org/jeewx/api/core/util/WeiXinReqUtil.java b/src/main/java/org/jeewx/api/core/util/WeiXinReqUtil.java index ea6fe2a..c613a4b 100644 --- a/src/main/java/org/jeewx/api/core/util/WeiXinReqUtil.java +++ b/src/main/java/org/jeewx/api/core/util/WeiXinReqUtil.java @@ -1,15 +1,7 @@ package org.jeewx.api.core.util; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; @@ -21,7 +13,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; +import java.util.Map.Entry; /** * 获取微信接口的信息 @@ -142,11 +137,10 @@ public static WeiXinReqHandler getMappingHander(String className){ * @return */ public static Map getWeixinReqParam(WeixinReqParam weixinReqParam) { - Gson gson = new Gson(); Map params = null; try{ - String json = gson.toJson(weixinReqParam); - params = gson.fromJson(json, Map.class); + String json = JSON.toJSONString(weixinReqParam); + params = JSONObject.parseObject(json).toJavaObject(Map.class); }catch(Exception e){ logger.error("处理参数解析出错", e); @@ -163,8 +157,7 @@ public static Map getWeixinReqParam(WeixinReqParam weixinReqParam) { * @return */ public static String getWeixinParamJson(WeixinReqParam weixinReqParam) { - Gson gson = new Gson(); - String json = gson.toJson(weixinReqParam); + String json = JSON.toJSONString(weixinReqParam); return json; } diff --git a/src/main/java/org/jeewx/api/coupon/consume/JwCardConsumeAPI.java b/src/main/java/org/jeewx/api/coupon/consume/JwCardConsumeAPI.java index f20b5db..266da06 100644 --- a/src/main/java/org/jeewx/api/coupon/consume/JwCardConsumeAPI.java +++ b/src/main/java/org/jeewx/api/coupon/consume/JwCardConsumeAPI.java @@ -1,11 +1,9 @@ package org.jeewx.api.coupon.consume; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONObject; +import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.coupon.consume.model.ConsumeRtnInfo; import org.jeewx.api.coupon.consume.model.EncryptRtnInfo; -import org.jeewx.api.core.common.AccessToken; -import org.jeewx.api.core.common.WxstoreUtils; /** * 微信卡券 - 核销接口 @@ -30,7 +28,7 @@ public static ConsumeRtnInfo doConsume(String newAccessToken,String code,String newAccessToken); String json = emptyStrJson("code",code,"card_id",card_id); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - ConsumeRtnInfo consumeRtnInfo = (ConsumeRtnInfo) JSONObject.toBean( + ConsumeRtnInfo consumeRtnInfo = (ConsumeRtnInfo) JSONObject.toJavaObject( result, ConsumeRtnInfo.class); return consumeRtnInfo; } @@ -49,7 +47,7 @@ public static EncryptRtnInfo doDecrypt(String newAccessToken,String encrypt_code newAccessToken); String json = emptyStrJson("encrypt_code",encrypt_code); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - EncryptRtnInfo encryptRtnInfo = (EncryptRtnInfo) JSONObject.toBean( + EncryptRtnInfo encryptRtnInfo = (EncryptRtnInfo) JSONObject.toJavaObject( result, EncryptRtnInfo.class); return encryptRtnInfo; } diff --git a/src/main/java/org/jeewx/api/coupon/location/JwLocationAPI.java b/src/main/java/org/jeewx/api/coupon/location/JwLocationAPI.java index 0f0e9ec..1086723 100644 --- a/src/main/java/org/jeewx/api/coupon/location/JwLocationAPI.java +++ b/src/main/java/org/jeewx/api/coupon/location/JwLocationAPI.java @@ -1,18 +1,9 @@ package org.jeewx.api.coupon.location; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; -import org.jeewx.api.core.common.WxstoreUtils; -import org.jeewx.api.coupon.location.model.Batchadd; -import org.jeewx.api.coupon.location.model.BatchaddRtn; -import org.jeewx.api.coupon.location.model.Batchget; -import org.jeewx.api.coupon.location.model.BatchgetRtn; -import org.jeewx.api.coupon.location.model.CardInfo; -import org.jeewx.api.coupon.location.model.CardInfoRtn; -import org.jeewx.api.coupon.location.model.Getcolors; -import org.jeewx.api.coupon.location.model.GetcolorsRtn; +import org.jeewx.api.coupon.location.model.*; /** @@ -40,7 +31,7 @@ public BatchaddRtn doBatchadd(String accesstoken,Batchadd batchadd) throws Wexin if (accesstoken != null) { batchadd.setAccess_token(accesstoken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(batchadd); - BatchaddRtn batchaddRtn = (BatchaddRtn)JSONObject.toBean(result, BatchaddRtn.class); + BatchaddRtn batchaddRtn = (BatchaddRtn)JSONObject.toJavaObject(result, BatchaddRtn.class); return batchaddRtn; } return null; @@ -53,7 +44,7 @@ public BatchgetRtn doBatchget(String accesstoken,Batchget batchget) throws Wexin if (accesstoken != null) { batchget.setAccess_token(accesstoken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(batchget); - BatchgetRtn batchgetRtn = (BatchgetRtn)JSONObject.toBean(result, BatchgetRtn.class); + BatchgetRtn batchgetRtn = (BatchgetRtn)JSONObject.toJavaObject(result, BatchgetRtn.class); return batchgetRtn; } return null; @@ -67,7 +58,7 @@ public GetcolorsRtn doGetcolors(String accesstoken) throws WexinReqException { Getcolors gk = new Getcolors(); gk.setAccess_token(accesstoken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(gk); - GetcolorsRtn getcolorsRtn = (GetcolorsRtn)JSONObject.toBean(result, GetcolorsRtn.class); + GetcolorsRtn getcolorsRtn = (GetcolorsRtn)JSONObject.toJavaObject(result, GetcolorsRtn.class); return getcolorsRtn; } return null; @@ -80,7 +71,7 @@ public CardInfoRtn doAddCard(String accesstoken,CardInfo cardInfo) throws WexinR if (accesstoken != null) { cardInfo.setAccess_token(accesstoken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(cardInfo); - CardInfoRtn cardInfoRtn = (CardInfoRtn)JSONObject.toBean(result, CardInfoRtn.class); + CardInfoRtn cardInfoRtn = (CardInfoRtn)JSONObject.toJavaObject(result, CardInfoRtn.class); return cardInfoRtn; } return null; diff --git a/src/main/java/org/jeewx/api/coupon/manage/JwCardManageAPI.java b/src/main/java/org/jeewx/api/coupon/manage/JwCardManageAPI.java index e01ec0c..86492d3 100644 --- a/src/main/java/org/jeewx/api/coupon/manage/JwCardManageAPI.java +++ b/src/main/java/org/jeewx/api/coupon/manage/JwCardManageAPI.java @@ -1,15 +1,8 @@ package org.jeewx.api.coupon.manage; -import net.sf.json.JSONObject; - -import org.jeewx.api.coupon.manage.model.BatchGetCardRtnInfo; -import org.jeewx.api.coupon.manage.model.CardUpdate; -import org.jeewx.api.coupon.manage.model.CommCardRtnInfo; -import org.jeewx.api.coupon.manage.model.DelRtnInfo; -import org.jeewx.api.coupon.manage.model.GetCardDetailRtnInfo; -import org.jeewx.api.coupon.manage.model.GetCardRtnInfo; -import org.jeewx.api.core.common.AccessToken; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.WxstoreUtils; +import org.jeewx.api.coupon.manage.model.*; /** @@ -43,7 +36,7 @@ public static DelRtnInfo doDelCard(String newAccessToken,String card_id) { String requestUrl = del_card_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"card_id\": \""+card_id+"\"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - DelRtnInfo delRtnInfo = (DelRtnInfo)JSONObject.toBean(result, DelRtnInfo.class); + DelRtnInfo delRtnInfo = (DelRtnInfo)JSONObject.toJavaObject(result, DelRtnInfo.class); return delRtnInfo; } return null; @@ -57,7 +50,7 @@ public static GetCardRtnInfo doGetCard(String newAccessToken,String code,String String requestUrl = get_card_url.replace("ACCESS_TOKEN", newAccessToken); String json = emptyStrJson("code",code,"card_id",card_id); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - GetCardRtnInfo getCardRtnInfo = (GetCardRtnInfo)JSONObject.toBean(result, GetCardRtnInfo.class); + GetCardRtnInfo getCardRtnInfo = (GetCardRtnInfo)JSONObject.toJavaObject(result, GetCardRtnInfo.class); return getCardRtnInfo; } return null; @@ -72,7 +65,7 @@ public static BatchGetCardRtnInfo doBatchGetCard(String newAccessToken,int offs String requestUrl = batchget_card_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"offset\":"+offset+",\"count\": "+count+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - BatchGetCardRtnInfo batchGetCardRtnInfo = (BatchGetCardRtnInfo)JSONObject.toBean(result, BatchGetCardRtnInfo.class); + BatchGetCardRtnInfo batchGetCardRtnInfo = (BatchGetCardRtnInfo)JSONObject.toJavaObject(result, BatchGetCardRtnInfo.class); return batchGetCardRtnInfo; } return null; @@ -85,7 +78,7 @@ public static GetCardDetailRtnInfo doGetCardDetail(String newAccessToken,String String requestUrl = get_card_detail_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"card_id\":\""+card_id+"\"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - GetCardDetailRtnInfo getCardDetailRtnInfo = (GetCardDetailRtnInfo)JSONObject.toBean(result, GetCardDetailRtnInfo.class); + GetCardDetailRtnInfo getCardDetailRtnInfo = (GetCardDetailRtnInfo)JSONObject.toJavaObject(result, GetCardDetailRtnInfo.class); return getCardDetailRtnInfo; } return null; @@ -104,7 +97,7 @@ public static CommCardRtnInfo doUpdateCode(String newAccessToken,String code,St String requestUrl = update_code_url.replace("ACCESS_TOKEN", newAccessToken); String json = emptyStrJson("code",code,"card_id",card_id,"new_code",new_code); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toBean(result, CommCardRtnInfo.class); + CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toJavaObject(result, CommCardRtnInfo.class); return commCardRtnInfo; } return null; @@ -121,7 +114,7 @@ public static CommCardRtnInfo doUnavailableCode(String newAccessToken,String co String requestUrl = unavailable_code_url.replace("ACCESS_TOKEN", newAccessToken); String json = emptyStrJson("code",code,"card_id",card_id); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toBean(result, CommCardRtnInfo.class); + CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toJavaObject(result, CommCardRtnInfo.class); return commCardRtnInfo; } return null; @@ -136,10 +129,10 @@ public static CommCardRtnInfo doUnavailableCode(String newAccessToken,String co public static CommCardRtnInfo doUpdateCard(String newAccessToken,CardUpdate cardUpdate) { if (newAccessToken != null) { String requestUrl = update_card_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(cardUpdate); + JSONObject obj = JSONObject.parseObject(JSONObject.toJSONString(cardUpdate)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toBean(result, CommCardRtnInfo.class); + CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toJavaObject(result, CommCardRtnInfo.class); return commCardRtnInfo; } return null; @@ -156,7 +149,7 @@ public static CommCardRtnInfo doModifystockCard(String newAccessToken,String ca String requestUrl = modifystock_card_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"card_id\":\""+card_id+"\",\"increase_stock_value\": "+increase_stock_value+",\"reduce_stock_value\": "+reduce_stock_value+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toBean(result, CommCardRtnInfo.class); + CommCardRtnInfo commCardRtnInfo = (CommCardRtnInfo)JSONObject.toJavaObject(result, CommCardRtnInfo.class); return commCardRtnInfo; } return null; diff --git a/src/main/java/org/jeewx/api/coupon/qrcode/JwQrcodeAPI.java b/src/main/java/org/jeewx/api/coupon/qrcode/JwQrcodeAPI.java index 36e016a..8ed05b7 100644 --- a/src/main/java/org/jeewx/api/coupon/qrcode/JwQrcodeAPI.java +++ b/src/main/java/org/jeewx/api/coupon/qrcode/JwQrcodeAPI.java @@ -1,7 +1,6 @@ package org.jeewx.api.coupon.qrcode; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; import org.jeewx.api.coupon.qrcode.model.Getticket; @@ -25,7 +24,7 @@ public static QrcodeRtnInfo doAddQrcode(String accesstoken,QrcodeInfo qrcodeInfo if (accesstoken != null) { qrcodeInfo.setAccess_token(accesstoken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(qrcodeInfo); - QrcodeRtnInfo qrcodeRtnInfo = (QrcodeRtnInfo)JSONObject.toBean(result, QrcodeRtnInfo.class); + QrcodeRtnInfo qrcodeRtnInfo = (QrcodeRtnInfo)JSONObject.toJavaObject(result, QrcodeRtnInfo.class); return qrcodeRtnInfo; } return null; @@ -39,7 +38,7 @@ public static GetticketRtn doGetticket(String accesstoken)throws WexinReqExcepti Getticket gk = new Getticket(); gk.setAccess_token(accesstoken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(gk); - GetticketRtn getticketRtn = (GetticketRtn)JSONObject.toBean(result, GetticketRtn.class); + GetticketRtn getticketRtn = (GetticketRtn)JSONObject.toJavaObject(result, GetticketRtn.class); return getticketRtn; } return null; diff --git a/src/main/java/org/jeewx/api/custservice/multicustservice/JwMultiCustomerAPI.java b/src/main/java/org/jeewx/api/custservice/multicustservice/JwMultiCustomerAPI.java index c6d8617..1750cb2 100644 --- a/src/main/java/org/jeewx/api/custservice/multicustservice/JwMultiCustomerAPI.java +++ b/src/main/java/org/jeewx/api/custservice/multicustservice/JwMultiCustomerAPI.java @@ -1,17 +1,16 @@ package org.jeewx.api.custservice.multicustservice; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.JSONHelper; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.custservice.multicustservice.model.ChatRecord; import org.jeewx.api.custservice.multicustservice.model.CustService; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + /** * 客户服务- 多客户 * @@ -93,9 +92,9 @@ public boolean isOnlineCustServiceAvailable(String accessToken,String kfAccount) for(Iterator it = custServices.iterator();it.hasNext();){ CustService custService = (CustService)it.next(); //不在线、没有开启自动接入或者自动接入已满,都返回不可用 + //不再返回自动接入参数 if (custService != null && custService.getKfAccount().equals(kfAccount) - && custService.getAutoAccept() > 0 - && custService.getAutoAccept()>custService.getAcceptedCase()){ + && custService.getStatus() > 0){ return true; } } diff --git a/src/main/java/org/jeewx/api/extend/CustomJsonConfig.java b/src/main/java/org/jeewx/api/extend/CustomJsonConfig.java index b5c70a0..992f2de 100644 --- a/src/main/java/org/jeewx/api/extend/CustomJsonConfig.java +++ b/src/main/java/org/jeewx/api/extend/CustomJsonConfig.java @@ -1,13 +1,13 @@ package org.jeewx.api.extend; -import net.sf.json.JsonConfig; -import net.sf.json.util.PropertyFilter; +import com.alibaba.fastjson.serializer.PropertyFilter; +import com.alibaba.fastjson.support.config.FastJsonConfig; /** * 过滤不需要转换的属性 * @author luobaoli * */ -public class CustomJsonConfig extends JsonConfig{ +public class CustomJsonConfig extends FastJsonConfig { @SuppressWarnings("rawtypes") private Class clazz; public CustomJsonConfig(){ @@ -16,8 +16,7 @@ public CustomJsonConfig(){ public CustomJsonConfig(Class clazz,final String exclude){ this.clazz = clazz; - setRootClass(clazz); - setJavaPropertyFilter(new PropertyFilter() { + setSerializeFilters(new PropertyFilter() { public boolean apply(Object arg0, String param, Object arg2) { if(param.equals(exclude))return true; return false; @@ -27,8 +26,7 @@ public boolean apply(Object arg0, String param, Object arg2) { public CustomJsonConfig(Class clazz,final String[] excludes){ this.clazz = clazz; - setRootClass(clazz); - setJavaPropertyFilter(new PropertyFilter() { + setSerializeFilters(new PropertyFilter() { public boolean apply(Object arg0, String param, Object arg2) { for(String exclude:excludes){ if(param.equals(exclude))return true; diff --git a/src/main/java/org/jeewx/api/report/datacube/JwDataCubeAPI.java b/src/main/java/org/jeewx/api/report/datacube/JwDataCubeAPI.java index 8353758..34b31ca 100644 --- a/src/main/java/org/jeewx/api/report/datacube/JwDataCubeAPI.java +++ b/src/main/java/org/jeewx/api/report/datacube/JwDataCubeAPI.java @@ -1,27 +1,15 @@ package org.jeewx.api.report.datacube; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -import org.jeewx.api.core.exception.WexinReqException; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamMsgDistMonthParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamMsgDistParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamMsgDistWeekParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamMsgHourParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamMsgMonthParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamMsgParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamMsgWeekParam; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.JSONHelper; import org.jeewx.api.core.common.WxstoreUtils; -import org.jeewx.api.report.datacube.model.WxDataCubeStreamMsgDistInfo; -import org.jeewx.api.report.datacube.model.WxDataCubeStreamMsgDistMonthInfo; -import org.jeewx.api.report.datacube.model.WxDataCubeStreamMsgDistWeekInfo; -import org.jeewx.api.report.datacube.model.WxDataCubeStreamMsgHourInfo; -import org.jeewx.api.report.datacube.model.WxDataCubeStreamMsgInfo; -import org.jeewx.api.report.datacube.model.WxDataCubeStreamMsgMonthInfo; -import org.jeewx.api.report.datacube.model.WxDataCubeStreamMsgWeekInfo; +import org.jeewx.api.core.exception.WexinReqException; +import org.jeewx.api.core.req.model.dataCube.*; +import org.jeewx.api.report.datacube.model.*; + +import java.util.List; /** * 分析数据接口service @@ -63,7 +51,7 @@ public static List getWxDataCubeStreamMsgInfo(String ac msgParam.setEnd_date(eDate); // 调用接口 String requestUrl = GETUPSTREAMMSG_URL.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(msgParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(msgParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get("errcode"); @@ -96,7 +84,7 @@ public static List getWxDataCubeStreamMsgHourInfo(S // 调用接口 String requestUrl = GETUPSTREAMMSGHOUR_URL.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(msgParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(msgParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get("errcode"); @@ -128,7 +116,7 @@ public static List getWxDataCubeStreamMsgWeekInfo(S // 调用接口 String requestUrl = GETUPSTREAMMSGWEEK_URL.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(msgParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(msgParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get("errcode"); @@ -160,7 +148,7 @@ public static List getWxDataCubeStreamMsgMonthInfo // 调用接口 String requestUrl = GETUPSTREAMMSGMONTH_URL.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(msgParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(msgParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get("errcode"); @@ -193,7 +181,7 @@ public static List getWxDataCubeStreamMsgDistInfo(S // 调用接口 String requestUrl = GETUPSTREAMMSGDIST_URL.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(msgParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(msgParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); @@ -227,7 +215,7 @@ public static List getWxDataCubeStreamMsgDistWe // 调用接口 String requestUrl = GETUPSTREAMMSGDISTWEEK_URL.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(msgParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(msgParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get("errcode"); @@ -259,7 +247,7 @@ public static List getWxDataCubeStreamMsgDistM // 调用接口 String requestUrl = GETUPSTREAMMSGDISTMONTH_URL.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(msgParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(msgParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get("errcode"); diff --git a/src/main/java/org/jeewx/api/report/datastatistics/graphicanalysis/JwGraphicAnalysisAPI.java b/src/main/java/org/jeewx/api/report/datastatistics/graphicanalysis/JwGraphicAnalysisAPI.java index 842c12b..e87fc04 100644 --- a/src/main/java/org/jeewx/api/report/datastatistics/graphicanalysis/JwGraphicAnalysisAPI.java +++ b/src/main/java/org/jeewx/api/report/datastatistics/graphicanalysis/JwGraphicAnalysisAPI.java @@ -1,26 +1,18 @@ package org.jeewx.api.report.datastatistics.graphicanalysis; -import java.io.UnsupportedEncodingException; -import java.sql.Date; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamArticleSummaryParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamArticleTotalParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamUserReadHourParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamUserReadParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamUserShareHourParam; -import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamUserShareParam; +import org.jeewx.api.core.req.model.dataCube.*; import org.jeewx.api.report.datastatistics.graphicanalysis.model.GraphicAnalysisRtnInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; +import java.io.UnsupportedEncodingException; +import java.sql.Date; +import java.util.ArrayList; +import java.util.List; /** * @ClassName: JwGraphicAnalysisAPI @@ -67,7 +59,7 @@ public static List getArticleSummary(String accesstoken, array = (JSONArray) result.get("list"); for (Object object : array) { graphicAnalysisRtnInfo = (GraphicAnalysisRtnInfo) JSONObject - .toBean((JSONObject) object, + .toJavaObject((JSONObject) object, GraphicAnalysisRtnInfo.class); graphicAnalysisRtnInfoList.add(graphicAnalysisRtnInfo); } @@ -106,10 +98,9 @@ public static List getArticleTotal(String accesstoken,St JSONArray array = null; GraphicAnalysisRtnInfo graphicAnalysisRtnInfo = null; array = (JSONArray) result.get("list"); - Gson gson = new Gson(); //修复JSONObject不能解析details内容的BUG for (Object object : array) { - graphicAnalysisRtnInfo = gson.fromJson(object.toString(), GraphicAnalysisRtnInfo.class); + graphicAnalysisRtnInfo = JSONObject.parseObject(object.toString(), GraphicAnalysisRtnInfo.class); // graphicAnalysisRtnInfo = (GraphicAnalysisRtnInfo) JSONObject // .toBean((JSONObject) object, // GraphicAnalysisRtnInfo.class); @@ -151,9 +142,7 @@ public static List getUserRead(String accesstoken,String GraphicAnalysisRtnInfo graphicAnalysisRtnInfo = null; array = (JSONArray) result.get("list"); for (Object object : array) { - graphicAnalysisRtnInfo = (GraphicAnalysisRtnInfo) JSONObject - .toBean((JSONObject) object, - GraphicAnalysisRtnInfo.class); + graphicAnalysisRtnInfo = ((JSONObject) object).toJavaObject(GraphicAnalysisRtnInfo.class); graphicAnalysisRtnInfoList.add(graphicAnalysisRtnInfo); } return graphicAnalysisRtnInfoList; @@ -191,10 +180,7 @@ public static List getUserReadHour(String accesstoken,St GraphicAnalysisRtnInfo graphicAnalysisRtnInfo = null; array = (JSONArray) result.get("list"); for (Object object : array) { - graphicAnalysisRtnInfo = (GraphicAnalysisRtnInfo) JSONObject - .toBean((JSONObject) object, - GraphicAnalysisRtnInfo.class); - + graphicAnalysisRtnInfo = ((JSONObject) object).toJavaObject(GraphicAnalysisRtnInfo.class); graphicAnalysisRtnInfoList.add(graphicAnalysisRtnInfo); } return graphicAnalysisRtnInfoList; @@ -232,9 +218,7 @@ public static List getUserShare(String accesstoken,Strin GraphicAnalysisRtnInfo graphicAnalysisRtnInfo = null; array = (JSONArray) result.get("list"); for (Object object : array) { - graphicAnalysisRtnInfo = (GraphicAnalysisRtnInfo) JSONObject - .toBean((JSONObject) object, - GraphicAnalysisRtnInfo.class); + graphicAnalysisRtnInfo = ((JSONObject) object).toJavaObject(GraphicAnalysisRtnInfo.class); graphicAnalysisRtnInfoList.add(graphicAnalysisRtnInfo); } @@ -262,10 +246,7 @@ public static List getUserShareHour(String accesstoken,S GraphicAnalysisRtnInfo graphicAnalysisRtnInfo = null; array = (JSONArray) result.get("list"); for (Object object : array) { - graphicAnalysisRtnInfo = (GraphicAnalysisRtnInfo) JSONObject - .toBean((JSONObject) object, - GraphicAnalysisRtnInfo.class); - + graphicAnalysisRtnInfo = ((JSONObject) object).toJavaObject(GraphicAnalysisRtnInfo.class); graphicAnalysisRtnInfoList.add(graphicAnalysisRtnInfo); } return graphicAnalysisRtnInfoList; diff --git a/src/main/java/org/jeewx/api/report/datastatistics/interfacesummary/JwInterfaceSummary.java b/src/main/java/org/jeewx/api/report/datastatistics/interfacesummary/JwInterfaceSummary.java index d2cc79a..1ae8b13 100644 --- a/src/main/java/org/jeewx/api/report/datastatistics/interfacesummary/JwInterfaceSummary.java +++ b/src/main/java/org/jeewx/api/report/datastatistics/interfacesummary/JwInterfaceSummary.java @@ -1,9 +1,9 @@ package org.jeewx.api.report.datastatistics.interfacesummary; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.WxstoreUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sf.json.JSONObject; public class JwInterfaceSummary { @@ -28,7 +28,7 @@ public class JwInterfaceSummary { *
total_time_cost 总耗时,除以callback_count即为平均耗时 *
max_time_cost 最大耗时 */ - public static JSONObject getinterfacesummary(String accessToken,String beginDate,String endDate){ + public static JSONObject getinterfacesummary(String accessToken, String beginDate, String endDate){ if(accessToken==null){ logger.error("传入的accessToken为空"); return null; diff --git a/src/main/java/org/jeewx/api/report/datastatistics/useranalysis/JwUserAnalysisAPI.java b/src/main/java/org/jeewx/api/report/datastatistics/useranalysis/JwUserAnalysisAPI.java index 4cc4ae3..b306839 100644 --- a/src/main/java/org/jeewx/api/report/datastatistics/useranalysis/JwUserAnalysisAPI.java +++ b/src/main/java/org/jeewx/api/report/datastatistics/useranalysis/JwUserAnalysisAPI.java @@ -1,12 +1,7 @@ package org.jeewx.api.report.datastatistics.useranalysis; -import java.sql.Date; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; import org.jeewx.api.core.req.model.dataCube.WxDataCubeStreamUserCumulateParam; @@ -15,6 +10,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.sql.Date; +import java.util.ArrayList; +import java.util.List; + /** * @ClassName: JwUserAnalysisAPI * @Description: 用户分析数据接口 @@ -56,9 +55,7 @@ public static List getUserSummary(String accesstoken,String UserAnalysisRtnInfo userAnalysisRtnInfo = null; array = (JSONArray) result.get("list"); for (Object object : array) { - userAnalysisRtnInfo = (UserAnalysisRtnInfo) JSONObject - .toBean((JSONObject) object, - UserAnalysisRtnInfo.class); + userAnalysisRtnInfo = ((JSONObject) object).toJavaObject(UserAnalysisRtnInfo.class); userAnalysisRtnInfoList.add(userAnalysisRtnInfo); } return userAnalysisRtnInfoList; @@ -94,9 +91,7 @@ public static List getUserCumulate(String accesstoken,Strin UserAnalysisRtnInfo userAnalysisRtnInfo = null; array = (JSONArray) result.get("list"); for (Object object : array) { - userAnalysisRtnInfo = (UserAnalysisRtnInfo) JSONObject - .toBean((JSONObject) object, - UserAnalysisRtnInfo.class); + userAnalysisRtnInfo = ((JSONObject) object).toJavaObject(UserAnalysisRtnInfo.class); userAnalysisRtnInfoList.add(userAnalysisRtnInfo); } return userAnalysisRtnInfoList; diff --git a/src/main/java/org/jeewx/api/report/interfacesummary/JwInterfaceSummaryAPI.java b/src/main/java/org/jeewx/api/report/interfacesummary/JwInterfaceSummaryAPI.java index 584a93a..cb0bef0 100644 --- a/src/main/java/org/jeewx/api/report/interfacesummary/JwInterfaceSummaryAPI.java +++ b/src/main/java/org/jeewx/api/report/interfacesummary/JwInterfaceSummaryAPI.java @@ -1,17 +1,17 @@ package org.jeewx.api.report.interfacesummary; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -import org.jeewx.api.core.req.model.interfacesummary.InterfaceSummaryParam; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.AccessToken; import org.jeewx.api.core.common.JSONHelper; import org.jeewx.api.core.common.WxstoreUtils; +import org.jeewx.api.core.req.model.interfacesummary.InterfaceSummaryParam; import org.jeewx.api.report.interfacesummary.model.InterfaceSummary; import org.jeewx.api.report.interfacesummary.model.InterfaceSummaryHour; +import java.util.List; + /** * 接口分析数据接口 @@ -33,7 +33,7 @@ public static List getInterfaceSummaryHour(String accessto if (accesstoken != null) { param.setAccess_token(accesstoken); String requestUrl = getinterfacesummaryhour_url.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(param); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(param)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET", obj.toString()); // 正常返回 List list = null; @@ -53,7 +53,7 @@ public static List getInterfaceSummary(String accesstoken,Inte if (accesstoken != null) { param.setAccess_token(accesstoken); String requestUrl = getinterfacesummary_url.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(param); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(param)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET", obj.toString()); // 正常返回 List list = null; diff --git a/src/main/java/org/jeewx/api/third/JwThirdAPI.java b/src/main/java/org/jeewx/api/third/JwThirdAPI.java index 99ddbb6..c73de79 100644 --- a/src/main/java/org/jeewx/api/third/JwThirdAPI.java +++ b/src/main/java/org/jeewx/api/third/JwThirdAPI.java @@ -1,23 +1,17 @@ package org.jeewx.api.third; -import java.util.HashMap; -import java.util.Map; - -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.core.exception.WexinReqException; -import org.jeewx.api.third.model.ApiAuthorizerToken; -import org.jeewx.api.third.model.ApiAuthorizerTokenRet; -import org.jeewx.api.third.model.ApiComponentToken; -import org.jeewx.api.third.model.ApiGetAuthorizer; -import org.jeewx.api.third.model.ApiGetAuthorizerRet; -import org.jeewx.api.third.model.GetPreAuthCodeParam; -import org.jeewx.api.third.model.ReOpenAccessToken; +import org.jeewx.api.third.model.*; import org.jeewx.api.wxstore.order.model.OrderInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; + /** * 微信--token信息 * @@ -51,9 +45,9 @@ public class JwThirdAPI { public static String getAccessToken(ApiComponentToken apiComponentToken) throws WexinReqException{ String component_access_token = ""; String requestUrl = api_component_token_url; - JSONObject obj = JSONObject.fromObject(apiComponentToken); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(apiComponentToken)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - if (result.has("errcode")) { + if (result.containsKey("errcode")) { logger.error("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { @@ -74,9 +68,9 @@ public static String getPreAuthCode(String component_appid, String component_acc String requestUrl = api_create_preauthcode_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token); GetPreAuthCodeParam getPreAuthCodeParam = new GetPreAuthCodeParam(); getPreAuthCodeParam.setComponent_appid(component_appid); - JSONObject obj = JSONObject.fromObject(getPreAuthCodeParam); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(getPreAuthCodeParam)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - if (result.has("errcode")) { + if (result.containsKey("errcode")) { logger.error("获取权限令牌信息!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获取权限令牌信息!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { @@ -97,10 +91,10 @@ public static JSONObject getApiQueryAuthInfo(String component_appid,String autho Map mp = new HashMap(); mp.put("component_appid", component_appid); mp.put("authorization_code", authorization_code); - JSONObject obj = JSONObject.fromObject(mp); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(mp)); System.out.println("-------------------3、使用授权码换取公众号的授权信息---requestUrl------------------------"+requestUrl); JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", obj.toString()); - if (result.has("errcode")) { + if (result.containsKey("errcode")) { logger.error("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } @@ -115,9 +109,9 @@ public static JSONObject getApiQueryAuthInfo(String component_appid,String autho */ public static ApiAuthorizerTokenRet apiAuthorizerToken(ApiAuthorizerToken apiAuthorizerToken,String component_access_token) throws WexinReqException{ String requestUrl = api_authorizer_token_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token); - JSONObject param = JSONObject.fromObject(apiAuthorizerToken); + JSONObject param = JSONObject.parseObject(JSON.toJSONString(apiAuthorizerToken)); JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", param.toString()); - ApiAuthorizerTokenRet apiAuthorizerTokenRet = (ApiAuthorizerTokenRet)JSONObject.toBean(result, ApiAuthorizerTokenRet.class); + ApiAuthorizerTokenRet apiAuthorizerTokenRet = (ApiAuthorizerTokenRet)JSONObject.toJavaObject(result, ApiAuthorizerTokenRet.class); return apiAuthorizerTokenRet; } /** @@ -125,9 +119,9 @@ public static ApiAuthorizerTokenRet apiAuthorizerToken(ApiAuthorizerToken apiAut */ public static ApiGetAuthorizerRet apiGetAuthorizerInfo(ApiGetAuthorizer apiGetAuthorizer,String component_access_token) throws WexinReqException{ String requestUrl = api_get_authorizer_info_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token); - JSONObject param = JSONObject.fromObject(apiGetAuthorizer); + JSONObject param = JSONObject.parseObject(JSON.toJSONString(apiGetAuthorizer)); JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", param.toString()); - ApiGetAuthorizerRet apiGetAuthorizerRet = (ApiGetAuthorizerRet)JSONObject.toBean(result, ApiGetAuthorizerRet.class); + ApiGetAuthorizerRet apiGetAuthorizerRet = (ApiGetAuthorizerRet)JSONObject.toJavaObject(result, ApiGetAuthorizerRet.class); return apiGetAuthorizerRet; } @@ -136,9 +130,9 @@ public static ApiGetAuthorizerRet apiGetAuthorizerInfo(ApiGetAuthorizer apiGetAu */ public static AuthorizerOptionRet apiGetAuthorizerOption(AuthorizerOption authorizerOption,String component_access_token) throws WexinReqException{ String requestUrl = api_get_authorizer_option_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token); - JSONObject param = JSONObject.fromObject(authorizerOption); + JSONObject param = JSONObject.parseObject(JSON.toJSONString(authorizerOption)); JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", param.toString()); - AuthorizerOptionRet authorizerOptionRet = (AuthorizerOptionRet)JSONObject.toBean(result, AuthorizerOptionRet.class); + AuthorizerOptionRet authorizerOptionRet = (AuthorizerOptionRet)JSONObject.toJavaObject(result, AuthorizerOptionRet.class); return authorizerOptionRet; } /** @@ -146,9 +140,9 @@ public static AuthorizerOptionRet apiGetAuthorizerOption(AuthorizerOption author */ public static AuthorizerSetOptionRet apiSetAuthorizerOption(AuthorizerSetOption authorizerSetOption,String component_access_token) throws WexinReqException{ String requestUrl = api_set_authorizer_option_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token); - JSONObject param = JSONObject.fromObject(authorizerSetOption); + JSONObject param = JSONObject.parseObject(JSON.toJSONString(authorizerSetOption)); JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", param.toString()); - AuthorizerSetOptionRet authorizerSetOptionRet = (AuthorizerSetOptionRet)JSONObject.toBean(result, AuthorizerSetOptionRet.class); + AuthorizerSetOptionRet authorizerSetOptionRet = (AuthorizerSetOptionRet)JSONObject.toJavaObject(result, AuthorizerSetOptionRet.class); return authorizerSetOptionRet; } /** @@ -169,8 +163,8 @@ public static AuthorizerSetOptionRet apiSetAuthorizerOption(AuthorizerSetOption public static ReOpenAccessToken getAccessTokenByCode(String appid,String code,String grant_type,String component_appid,String component_access_token) throws WexinReqException{ String requestUrl = get_access_token_bycode_url.replace("COMPONENT_APPID", component_appid).replace("COMPONENT_ACCESS_TOKEN", component_access_token).replace("authorization_code", grant_type).replace("CODE", code).replace("APPID", appid); JSONObject result = WxstoreUtils.httpRequest(requestUrl,"GET", null); - ReOpenAccessToken reOpenAccessToken = (ReOpenAccessToken)JSONObject.toBean(result, OrderInfo.class); - if (result.has("errcode")) { + ReOpenAccessToken reOpenAccessToken = JSONObject.toJavaObject(result, ReOpenAccessToken.class); + if (result.containsKey("errcode")) { logger.error("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } @@ -185,7 +179,7 @@ public static ReOpenAccessToken getAccessTokenByCode(String appid,String code,St * @return */ public static String sendMessage(Map obj,String ACCESS_TOKEN){ - JSONObject json = JSONObject.fromObject(obj); + JSONObject json = JSONObject.parseObject(JSON.toJSONString(obj)); System.out.println("--------发送客服消息---------json-----"+json.toString()); // 调用接口获取access_token String url = send_message_url.replace("ACCESS_TOKEN",ACCESS_TOKEN); diff --git a/src/main/java/org/jeewx/api/wxaccount/JwAccountAPI.java b/src/main/java/org/jeewx/api/wxaccount/JwAccountAPI.java index 1b81e2a..117bc85 100644 --- a/src/main/java/org/jeewx/api/wxaccount/JwAccountAPI.java +++ b/src/main/java/org/jeewx/api/wxaccount/JwAccountAPI.java @@ -1,7 +1,6 @@ package org.jeewx.api.wxaccount; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; import org.jeewx.api.core.req.model.account.QrcodeActionInfo; @@ -59,7 +58,7 @@ public static WxQrcode createQrcode(String accessToken, String scene_str, JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(qrcodeCreate); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); WxQrcode wxQrcode = null; - wxQrcode = (WxQrcode) JSONObject.toBean(result, WxQrcode.class); + wxQrcode = (WxQrcode) JSONObject.toJavaObject(result, WxQrcode.class); return wxQrcode; } diff --git a/src/main/java/org/jeewx/api/wxbase/wxmedia/JwMediaAPI.java b/src/main/java/org/jeewx/api/wxbase/wxmedia/JwMediaAPI.java index 6f91d6e..9eb319b 100644 --- a/src/main/java/org/jeewx/api/wxbase/wxmedia/JwMediaAPI.java +++ b/src/main/java/org/jeewx/api/wxbase/wxmedia/JwMediaAPI.java @@ -1,11 +1,9 @@ package org.jeewx.api.wxbase.wxmedia; -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.apache.commons.lang.StringUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.internal.util.StringUtils; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; @@ -13,27 +11,20 @@ import org.jeewx.api.core.req.model.UploadMedia; import org.jeewx.api.core.util.WeiXinConstant; import org.jeewx.api.core.util.WeiXinReqUtil; -import org.jeewx.api.wxbase.wxmedia.model.WxArticlesRequest; -import org.jeewx.api.wxbase.wxmedia.model.WxArticlesRequestByMaterial; -import org.jeewx.api.wxbase.wxmedia.model.WxArticlesRespponseByMaterial; -import org.jeewx.api.wxbase.wxmedia.model.WxCountResponse; -import org.jeewx.api.wxbase.wxmedia.model.WxDescriptionRequest; -import org.jeewx.api.wxbase.wxmedia.model.WxDwonload; -import org.jeewx.api.wxbase.wxmedia.model.WxItem; -import org.jeewx.api.wxbase.wxmedia.model.WxMediaForMaterial; -import org.jeewx.api.wxbase.wxmedia.model.WxMediaForMaterialResponse; -import org.jeewx.api.wxbase.wxmedia.model.WxNews; -import org.jeewx.api.wxbase.wxmedia.model.WxNewsArticle; -import org.jeewx.api.wxbase.wxmedia.model.WxUpdateArticle; -import org.jeewx.api.wxbase.wxmedia.model.WxUpload; +import org.jeewx.api.wxbase.wxmedia.model.*; import org.jeewx.api.wxsendmsg.JwSendMessageAPI; import org.jeewx.api.wxsendmsg.model.WxArticle; import org.jeewx.api.wxsendmsg.model.WxArticlesResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; /** * 微信--token信息 @@ -44,7 +35,7 @@ public class JwMediaAPI { private static Logger logger = LoggerFactory.getLogger(JwMediaAPI.class); // 新增永久图文素材 - private static String material_add_news_url ="https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=ACCESS_TOKEN"; + private static String material_add_news_url ="https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type=TYPE"; // 新增其他类型永久素材 private static String material_add_material_url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN"; // 获取永久素材 @@ -61,13 +52,14 @@ public class JwMediaAPI { private static String material_del_news_url = "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=ACCESS_TOKEN"; /** - * + * 经测试该方法不可用 * @param accessToke * @param type 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb) * @param fileNamePath 上传的文件目录 * @return * @throws WexinReqException */ + @Deprecated public static WxUpload uploadMedia(String accessToke,String type,String fileNamePath) throws WexinReqException{ UploadMedia uploadMedia = new UploadMedia(); uploadMedia.setAccess_token(accessToke); @@ -76,7 +68,7 @@ public static WxUpload uploadMedia(String accessToke,String type,String fileName JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(uploadMedia); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); WxUpload wxMedia = null; - wxMedia = (WxUpload) JSONObject.toBean(result, WxUpload.class); + wxMedia = (WxUpload) JSONObject.toJavaObject(result, WxUpload.class); return wxMedia; } @@ -89,6 +81,7 @@ public static WxUpload uploadMedia(String accessToke,String type,String fileName * @return * @throws WexinReqException */ + @Deprecated public static WxDwonload downMedia(String accessToke,String media_id,String filePath) throws WexinReqException{ DownloadMedia downloadMedia = new DownloadMedia(); downloadMedia.setAccess_token(accessToke); @@ -97,7 +90,7 @@ public static WxDwonload downMedia(String accessToke,String media_id,String file JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(downloadMedia); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); WxDwonload wxMedia = null; - wxMedia = (WxDwonload) JSONObject.toBean(result, WxDwonload.class); + wxMedia = (WxDwonload) JSONObject.toJavaObject(result, WxDwonload.class); return wxMedia; } @@ -127,6 +120,7 @@ public static void main(String[] args){ * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ + @Deprecated public static WxArticlesResponse uploadArticlesByMaterial(String accesstoken, List wxArticles) throws WexinReqException { WxArticlesResponse wxArticlesResponse = null; if (wxArticles.size() == 0) { @@ -150,10 +144,10 @@ public static WxArticlesResponse uploadArticlesByMaterial(String accesstoken, Li } WxArticlesRequest wxArticlesRequest = new WxArticlesRequest(); wxArticlesRequest.setArticles(wxArticles); - JSONObject obj = JSONObject.fromObject(wxArticlesRequest); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(wxArticlesRequest)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - if (result.has("errcode")) { + if (result.containsKey("errcode")) { logger.error("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { @@ -187,7 +181,7 @@ public static WxCountResponse getMediaCount(String accesstoken) throws WexinReqE JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST",null); //System.out.println("微信返回的结果:" + result.toString()); - if (result.has("errcode")) { + if (result.containsKey("errcode")) { logger.error("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { @@ -211,6 +205,7 @@ public static WxCountResponse getMediaCount(String accesstoken) throws WexinReqE * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ + @Deprecated public static WxArticlesRespponseByMaterial getArticlesByMaterial(String accesstoken,String mediaId) throws WexinReqException { WxArticlesRespponseByMaterial wxArticlesRespponseByMaterial = null; @@ -218,14 +213,14 @@ public static WxArticlesRespponseByMaterial getArticlesByMaterial(String accesst String requestUrl = material_get_material_url.replace("ACCESS_TOKEN", accesstoken); WxArticlesRequestByMaterial wxArticlesRequestByMaterial = new WxArticlesRequestByMaterial(); wxArticlesRequestByMaterial.setMediaId(mediaId); - JSONObject obj = JSONObject.fromObject(wxArticlesRequestByMaterial); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(wxArticlesRespponseByMaterial)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - if (result.has("errcode")) { + if (result.containsKey("errcode")) { logger.error("获得消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获得消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { - wxArticlesRespponseByMaterial = (WxArticlesRespponseByMaterial)JSONObject.toBean(result,WxArticlesRespponseByMaterial.class); + wxArticlesRespponseByMaterial = (WxArticlesRespponseByMaterial)JSONObject.toJavaObject(result,WxArticlesRespponseByMaterial.class); } } @@ -241,15 +236,16 @@ public static WxArticlesRespponseByMaterial getArticlesByMaterial(String accesst * @return WxArticlesRespponseByMaterial 上传图文消息素材返回结果 * @throws WexinReqException */ + @Deprecated public static void deleteArticlesByMaterial(String accesstoken,String mediaId) throws WexinReqException { - if (accesstoken != null&&StringUtils.isNotEmpty(mediaId)) { + if (accesstoken != null&& !StringUtils.isEmpty(mediaId)) { String requestUrl = material_get_material_url.replace("ACCESS_TOKEN", accesstoken); WxArticlesRequestByMaterial wxArticlesRequestByMaterial = new WxArticlesRequestByMaterial(); wxArticlesRequestByMaterial.setMediaId(mediaId); - JSONObject obj = JSONObject.fromObject(wxArticlesRequestByMaterial); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(wxArticlesRequestByMaterial)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - if (result.has("errcode")&&result.get("errcode")!="0") { + if (result.containsKey("errcode")&&result.get("errcode")!="0") { logger.error("删除消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("删除消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } @@ -263,14 +259,15 @@ public static void deleteArticlesByMaterial(String accesstoken,String mediaId) t * @param wxUpdateArticle * @throws WexinReqException */ + @Deprecated public static void updateArticlesByMaterial(String accesstoken,WxUpdateArticle wxUpdateArticle) throws WexinReqException { if (accesstoken != null) { String requestUrl = material_update_news_url.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(wxUpdateArticle); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(wxUpdateArticle)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - if (result.has("errcode")&&result.get("errcode")!="0") { + if (result.containsKey("errcode")&&result.get("errcode")!="0") { logger.error("消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("消息消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } @@ -284,6 +281,7 @@ public static void updateArticlesByMaterial(String accesstoken,WxUpdateArticle w * @param WxNews * @throws WexinReqException */ + @Deprecated public static WxNews queryArticlesByMaterial(String accesstoken,String type,int offset,int count) throws WexinReqException { WxNews wn = null; if (accesstoken != null) { @@ -295,11 +293,11 @@ public static WxNews queryArticlesByMaterial(String accesstoken,String type,int obj.put("count", count); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - if (result.has("errcode")&&result.get("errcode")!="0") { + if (result.containsKey("errcode")&&result.get("errcode")!="0") { logger.error("消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("消息消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else{ - wn = (WxNews) JSONObject.toBean(result, WxNews.class); + wn = (WxNews) JSONObject.toJavaObject(result, WxNews.class); } } return wn; @@ -311,6 +309,7 @@ public static WxNews queryArticlesByMaterial(String accesstoken,String type,int * @return * @throws WexinReqException */ + @Deprecated public static String getMediaIdByMaterial(String accesstoken, List wxArticles) throws WexinReqException { WxArticlesResponse response = uploadArticlesByMaterial(accesstoken, wxArticles); @@ -329,6 +328,7 @@ public static String getMediaIdByMaterial(String accesstoken, List wx * @return * @throws Exception */ + @Deprecated public static WxMediaForMaterialResponse uploadMediaFileByMaterial(String accesstoken, WxMediaForMaterial wx) throws WexinReqException { WxMediaForMaterialResponse mediaResource = null; if (accesstoken != null) { @@ -340,7 +340,7 @@ public static WxMediaForMaterialResponse uploadMediaFileByMaterial(String access if("video"==wx.getType()){ WxDescriptionRequest wr = new WxDescriptionRequest(); wr.setDescription(wx.getWxDescription()); - JSONObject obj = JSONObject.fromObject(wr); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(wr)); WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); } @@ -369,6 +369,7 @@ public static WxMediaForMaterialResponse uploadMediaFileByMaterial(String access * @return * @throws WexinReqException */ + @Deprecated public static String getMediaIdForMaterial(String accesstoken, WxMediaForMaterial wxMediaForMaterial) throws WexinReqException { WxMediaForMaterialResponse response = uploadMediaFileByMaterial(accesstoken, wxMediaForMaterial); @@ -387,6 +388,7 @@ public static String getMediaIdForMaterial(String accesstoken, WxMediaForMateria * @return * @throws WexinReqException */ + @Deprecated public static WxMediaForMaterialResponse addMediaFileByMaterialNews(String accesstoken, String type,String filePath,String fileName) throws WexinReqException { WxMediaForMaterialResponse mediaResource = null; if (accesstoken != null) { @@ -413,34 +415,41 @@ public static WxMediaForMaterialResponse addMediaFileByMaterialNews(String acces } /** - * 上传新增永久图文素材 + * 上传新增素材 * * @param accesstoken * @param wxArticles - * 图文集合,数量不大于10 + * 图文集合,数量不大于100000 * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ - public static WxArticlesResponse uploadArticlesByMaterialNews(String accesstoken, List wxArticles) throws WexinReqException { + public static WxArticlesResponse uploadArticlesByMaterialNews(String accesstoken, List wxArticles,String type) throws WexinReqException { WxArticlesResponse wxArticlesResponse = null; if (wxArticles.size() == 0) { logger.error("没有上传的图文消息"); - } else if (wxArticles.size() > 10) { - logger.error("图文消息最多为10个图文"); } else { if (accesstoken != null) { - String requestUrl = material_add_news_url.replace("ACCESS_TOKEN", accesstoken); - WxArticlesRequest wxArticlesRequest = new WxArticlesRequest(); - wxArticlesRequest.setArticles(wxArticles); - JSONObject obj = JSONObject.fromObject(wxArticlesRequest); - JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - if (result.has("errcode")) { - logger.error("新增永久图文素材失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); - throw new WexinReqException(result.getString("errcode")); - } else { - logger.info("=====新增永久图文素材成功=====result:"+result.toString()); - wxArticlesResponse = new WxArticlesResponse(); - wxArticlesResponse.setMedia_id(result.getString("media_id")); + String requestUrl = material_add_news_url.replace("ACCESS_TOKEN", accesstoken).replace("TYPE",type); + for (WxArticle wxArticle : wxArticles) { + try { + File media = new File(wxArticle.getFilePath()); + String s = uploadPermanentMaterial(media, type, wxArticle.getTitle(), wxArticle.getContent(), requestUrl); + JSONObject jsonObject = JSONObject.parseObject(s); + if (jsonObject.containsKey("errcode")) { + logger.error("新增永久素材失败!errcode=" + jsonObject.getString("errcode") + ",errmsg = " + jsonObject.getString("errmsg")); + throw new WexinReqException(jsonObject.getString("errcode")); + } else { + logger.info("=====新增永久素材成功=====result:"+jsonObject.toString()); + wxArticlesResponse = new WxArticlesResponse(); + wxArticlesResponse.setMedia_id(jsonObject.getString("media_id")); + //只有图片才会存在路径 + if("image".equals(type)){ + wxArticlesResponse.setUrl(jsonObject.getString("url")); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } } } } @@ -448,7 +457,7 @@ public static WxArticlesResponse uploadArticlesByMaterialNews(String accesstoken } /** - * 修改永久素材 + * 修改永久素材 已下线 * * @param accesstoken * @param wxUpdateArticle @@ -458,9 +467,9 @@ public static void updateArticlesByMaterialNews(String accesstoken,WxUpdateArtic if (accesstoken != null) { String requestUrl = material_update_news_url.replace("ACCESS_TOKEN", accesstoken); - JSONObject obj = JSONObject.fromObject(wxUpdateArticle); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(wxUpdateArticle)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - if (result.has("errcode")&&result.getInt("errcode")!=0) { + if (result.containsKey("errcode")&&result.getInteger("errcode")!=0) { logger.error("修改永久素材失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException(result.getString("errcode")); }else{ @@ -471,30 +480,38 @@ public static void updateArticlesByMaterialNews(String accesstoken,WxUpdateArtic /** * 获取永久素材 - * + * 注意 新版本获取指定素材除了 video视频 其余图片、语音 返回的均为文件流。需要将url转成工作流来处理 * @param accesstoken - * @param wxArticles - * 图文集合,数量不大于10 - * @return WxArticlesResponse 上传图文消息素材返回结果 + * @return WxArticlesResponse * @throws WexinReqException */ - public static List getArticlesByMaterialNews(String accesstoken,String mediaId) throws WexinReqException { - List wxArticleList = null; + public static WxNewsArticle getArticlesByMaterialNews(String accesstoken,String mediaId) throws WexinReqException { + WxNewsArticle wxNewsArticle = new WxNewsArticle(); if (accesstoken != null) { String requestUrl = material_get_material_url.replace("ACCESS_TOKEN", accesstoken); JSONObject obj = new JSONObject(); obj.put("media_id", mediaId); - JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - if (result.has("errcode")) { + String s = sendPost(requestUrl, obj.toJSONString()); + if (s.contains("errcode")) { + JSONObject result = JSONObject.parseObject(s); logger.error("获取永久素材 失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException(result.getString("errcode")); } else { - logger.info("====获取永久素材成功====result:"+result.toString()); - JSONArray newsItemJsonArr = result.getJSONArray("news_item"); - wxArticleList = JSONArray.toList(newsItemJsonArr, WxNewsArticle.class); + logger.info("====获取永久素材成功====result:"+ s); + if(s.contains("title")){ + JSONObject jsonObject = JSONObject.parseObject(s); + String title = jsonObject.getString("title"); + String downUrl = jsonObject.getString("down_url"); + String description = jsonObject.getString("description"); + wxNewsArticle.setTitle(title); + wxNewsArticle.setUrl(downUrl); + wxNewsArticle.setContent(description); + }else{ + wxNewsArticle.setUrl(s); + } } } - return wxArticleList; + return wxNewsArticle; } /** @@ -514,7 +531,7 @@ public static WxNews queryArticlesByMaterialNews(String accesstoken,String type, obj.put("offset", offset); obj.put("count", count); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - if (result.has("errcode")&&result.getInt("errcode")!=0) { + if (result.containsKey("errcode")&&result.getInteger("errcode")!=0) { logger.error("=====获取素材列表失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")+"====="); throw new WexinReqException(result.getString("errcode")); } else{ @@ -525,13 +542,15 @@ public static WxNews queryArticlesByMaterialNews(String accesstoken,String type, for (int i = 0; i < itemArr.length; i++) { WxItem wxItem = new WxItem(); Object itemObj = itemArr[i]; - JSONObject itemJson = JSONObject.fromObject(itemObj); + JSONObject itemJson = JSONObject.parseObject(JSON.toJSONString(itemObj)); String mediaId = itemJson.getString("media_id"); Object newsItemObj = itemJson.get("content"); - JSONObject newsItemJson = JSONObject.fromObject(newsItemObj); - JSONArray newsItemJsonArr = newsItemJson.getJSONArray("news_item"); - List wxArticleList = JSONArray.toList(newsItemJsonArr, WxNewsArticle.class); - wxItem.setContents(wxArticleList); + if(null != newsItemObj){ + JSONObject newsItemJson = JSONObject.parseObject(JSON.toJSONString(newsItemObj)); + JSONArray newsItemJsonArr = newsItemJson.getJSONArray("news_item"); + List wxArticleList = newsItemJsonArr.toJavaList(WxNewsArticle.class); + wxItem.setContents(wxArticleList); + } wxItem.setMedia_id(mediaId); if(itemJson.containsKey("name")){ wxItem.setName("name"); @@ -555,12 +574,12 @@ public static WxNews queryArticlesByMaterialNews(String accesstoken,String type, * @throws WexinReqException */ public static void deleteArticlesByMaterialNews(String accesstoken,String mediaId) throws WexinReqException { - if (accesstoken != null&&StringUtils.isNotEmpty(mediaId)) { + if (accesstoken != null&&!StringUtils.isEmpty(mediaId)) { String requestUrl = material_del_news_url.replace("ACCESS_TOKEN", accesstoken); JSONObject obj = new JSONObject(); obj.put("media_id", mediaId); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - if (result.has("errcode")&&result.getInt("errcode")!=0) { + if (result.containsKey("errcode")&&result.getInteger("errcode")!=0) { logger.error("=====删除永久素材失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")+"======"); throw new WexinReqException(result.getString("errcode")); }else{ @@ -569,4 +588,108 @@ public static void deleteArticlesByMaterialNews(String accesstoken,String mediaI } } //-- update-end--Author:gengjiajia Date:2016-11-28 for:TASK #1583 【图文管理】重写管理永久素材的接口 -} + + /** + * 上传永久素材 + * @param file + * @param type + * @param title type为video时需要,其他类型设null + * @param introduction type为video时需要,其他类型设null + * @return {"media_id":MEDIA_ID,"url":URL} + */ + public static String uploadPermanentMaterial(File file, String type, String title, String introduction, String url) { + String result = null; + try { + URL uploadURL = new URL(url); + + HttpURLConnection conn = (HttpURLConnection) uploadURL.openConnection(); + conn.setConnectTimeout(5000); + conn.setReadTimeout(30000); + conn.setDoOutput(true); + conn.setDoInput(true); + conn.setUseCaches(false); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Connection", "Keep-Alive"); + conn.setRequestProperty("Cache-Control", "no-cache"); + String boundary = "-----------------------------" + System.currentTimeMillis(); + conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); + + OutputStream output = conn.getOutputStream(); + output.write(("--" + boundary + "\r\n").getBytes()); + output.write(String.format("Content-Disposition: form-data; name=\"media\"; filename=\"%s\"\r\n", file.getName()).getBytes()); + output.write("Content-Type: video/mp4 \r\n\r\n".getBytes()); + byte[] data = new byte[1024]; + int len = 0; + FileInputStream input = new FileInputStream(file); + while ((len = input.read(data)) > -1) { + output.write(data, 0, len); + } + /*对类型为video的素材进行特殊处理*/ + if ("video".equals(type)) { + output.write(("--" + boundary + "\r\n").getBytes()); + output.write("Content-Disposition: form-data; name=\"description\";\r\n\r\n".getBytes()); + output.write(String.format("{\"title\":\"%s\", \"introduction\":\"%s\"}", title, introduction).getBytes()); + } + output.write(("\r\n--" + boundary + "--\r\n\r\n").getBytes()); + output.flush(); + output.close(); + input.close(); + InputStream resp = conn.getInputStream(); + StringBuffer sb = new StringBuffer(); + while ((len = resp.read(data)) > -1) + sb.append(new String(data, 0, len, "utf-8")); + resp.close(); + result = sb.toString(); + } catch (IOException e) { + logger.error(e.getMessage(),e); + e.printStackTrace(); + } + return result; + } + + /** + * 发送post请求 用于获取素材 + * @param url + * @param param + */ + public static String sendPost(String url, String param) { + PrintWriter out = null; + BufferedReader in = null; + String result = ""; + + try { + URL realUrl = new URL(url); + URLConnection conn = realUrl.openConnection(); + conn.setRequestProperty("accept", "*/*"); + conn.setRequestProperty("connection", "Keep-Alive"); + conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + conn.setDoOutput(true); + conn.setDoInput(true); + out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8")); + out.print(param); + out.flush(); + + String line; + for(in = new BufferedReader(new InputStreamReader(conn.getInputStream())); (line = in.readLine()) != null; result = result + line) { + } + } catch (Exception var16) { + System.out.println("发送 POST 请求出现异常!" + var16); + var16.printStackTrace(); + } finally { + try { + if (out != null) { + out.close(); + } + + if (in != null) { + in.close(); + } + } catch (IOException var15) { + var15.printStackTrace(); + } + + } + logger.info("result:{}"+result); + return result; + } +} \ No newline at end of file diff --git a/src/main/java/org/jeewx/api/wxbase/wxserviceip/JwServiceIpAPI.java b/src/main/java/org/jeewx/api/wxbase/wxserviceip/JwServiceIpAPI.java index 00e5093..723b1b1 100644 --- a/src/main/java/org/jeewx/api/wxbase/wxserviceip/JwServiceIpAPI.java +++ b/src/main/java/org/jeewx/api/wxbase/wxserviceip/JwServiceIpAPI.java @@ -1,16 +1,15 @@ package org.jeewx.api.wxbase.wxserviceip; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; import org.jeewx.api.core.req.model.ServiceIP; import org.jeewx.api.core.util.WeiXinConstant; +import java.util.ArrayList; +import java.util.List; + /** * 微信--token信息 * diff --git a/src/main/java/org/jeewx/api/wxbase/wxtoken/JwTokenAPI.java b/src/main/java/org/jeewx/api/wxbase/wxtoken/JwTokenAPI.java index 3208aed..3a0fe8a 100644 --- a/src/main/java/org/jeewx/api/wxbase/wxtoken/JwTokenAPI.java +++ b/src/main/java/org/jeewx/api/wxbase/wxtoken/JwTokenAPI.java @@ -1,7 +1,6 @@ package org.jeewx.api.wxbase.wxtoken; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; import org.jeewx.api.core.req.model.AccessToken; diff --git a/src/main/java/org/jeewx/api/wxmenu/JwMenuAPI.java b/src/main/java/org/jeewx/api/wxmenu/JwMenuAPI.java index 29c883d..bb8a053 100644 --- a/src/main/java/org/jeewx/api/wxmenu/JwMenuAPI.java +++ b/src/main/java/org/jeewx/api/wxmenu/JwMenuAPI.java @@ -1,25 +1,20 @@ package org.jeewx.api.wxmenu; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; -import net.sf.json.util.JSONUtils; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SimplePropertyPreFilter; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; -import org.jeewx.api.core.req.model.menu.MenuConfigureGet; -import org.jeewx.api.core.req.model.menu.MenuCreate; -import org.jeewx.api.core.req.model.menu.MenuDelete; -import org.jeewx.api.core.req.model.menu.MenuGet; -import org.jeewx.api.core.req.model.menu.WeixinButton; +import org.jeewx.api.core.req.model.menu.*; import org.jeewx.api.core.req.model.menu.config.CustomWeixinButtonConfig; import org.jeewx.api.core.req.model.menu.config.WeixinButtonExtend; import org.jeewx.api.core.util.WeiXinConstant; import org.jeewx.api.extend.CustomJsonConfig; import org.jeewx.api.wxsendmsg.model.WxArticleConfig; +import java.util.ArrayList; +import java.util.List; + /** * 微信--menu * @@ -77,13 +72,13 @@ public static List getAllMenu(String accessToken) throws WexinReqE WeixinButton subBtn = null; List lstSubButton = null; for (int i = 0; i < buttons.size(); i++) { - btn = (WeixinButton) JSONObject.toBean(buttons.getJSONObject(i), + btn = (WeixinButton) JSONObject.toJavaObject(buttons.getJSONObject(i), WeixinButton.class); subButtons = buttons.getJSONObject(i).getJSONArray("sub_button"); if (subButtons != null) { lstSubButton = new ArrayList(); for (int j = 0; j < subButtons.size(); j++) { - subBtn = (WeixinButton) JSONObject.toBean( + subBtn = (WeixinButton) JSONObject.toJavaObject( subButtons.getJSONObject(j), WeixinButton.class); lstSubButton.add(subBtn); } @@ -122,30 +117,39 @@ public static CustomWeixinButtonConfig getAllMenuConfigure(String accessToken) t JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(cmcg); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); - CustomWeixinButtonConfig customWeixinButtonConfig = (CustomWeixinButtonConfig) JSONObject.toBean(result, new CustomJsonConfig(CustomWeixinButtonConfig.class,"selfmenu_info")); +// CustomWeixinButtonConfig customWeixinButtonConfig = (CustomWeixinButtonConfig) JSONObject.toJavaObject(result, new CustomJsonConfig(CustomWeixinButtonConfig.class,"selfmenu_info")); + SimplePropertyPreFilter selfMenuFilter = new SimplePropertyPreFilter(); + selfMenuFilter.getExcludes().add("selfmenu_info"); + CustomWeixinButtonConfig customWeixinButtonConfig = JSONObject.parseObject(JSONObject.toJSONString(result, selfMenuFilter), CustomWeixinButtonConfig.class); JSONObject selfmenuInfo = result.getJSONObject("selfmenu_info"); - if(selfmenuInfo!=null && !JSONUtils.isNull(selfmenuInfo)){ + if(selfmenuInfo!=null && !selfmenuInfo.isEmpty()){ /**处理父类菜单 */ JSONArray buttons = selfmenuInfo.getJSONArray("button"); List listButton = new ArrayList(); for(int i=0;i listSubButton = new ArrayList(); for (int j = 0; j < subButtons.size(); j++) { - WeixinButtonExtend subBtn = (WeixinButtonExtend) JSONObject.toBean(subButtons.getJSONObject(j), new CustomJsonConfig(WeixinButtonExtend.class,"news_info")); +// WeixinButtonExtend subBtn = (WeixinButtonExtend) JSONObject.toJavaObject(subButtons.getJSONObject(j), new CustomJsonConfig(WeixinButtonExtend.class,"news_info")); + SimplePropertyPreFilter newsInfoFilter = new SimplePropertyPreFilter(); + newsInfoFilter.getExcludes().add("news_info"); + WeixinButtonExtend subBtn = JSONObject.parseObject(JSONObject.toJSONString(subButtons.getJSONObject(j), newsInfoFilter), WeixinButtonExtend.class); /**处理菜单关联的图文消息 */ JSONObject newsInfoJsonObj = subButtons.getJSONObject(j).getJSONObject("news_info"); - if(newsInfoJsonObj!=null && !JSONUtils.isNull(newsInfoJsonObj)){ + if(newsInfoJsonObj!=null && !newsInfoJsonObj.isEmpty()){ JSONArray newsInfos = newsInfoJsonObj.getJSONArray("list"); List listNewsInfo = new ArrayList(); for (int k = 0; k < newsInfos.size(); k++) { - WxArticleConfig wxArticleConfig = (WxArticleConfig) JSONObject.toBean(newsInfos.getJSONObject(k), WxArticleConfig.class); + WxArticleConfig wxArticleConfig = (WxArticleConfig) JSONObject.toJavaObject(newsInfos.getJSONObject(k), WxArticleConfig.class); listNewsInfo.add(wxArticleConfig); } subBtn.setNews_info(listNewsInfo); diff --git a/src/main/java/org/jeewx/api/wxmenu/JwPersonalizedMenuAPI.java b/src/main/java/org/jeewx/api/wxmenu/JwPersonalizedMenuAPI.java index 1ca9b85..78c2885 100644 --- a/src/main/java/org/jeewx/api/wxmenu/JwPersonalizedMenuAPI.java +++ b/src/main/java/org/jeewx/api/wxmenu/JwPersonalizedMenuAPI.java @@ -1,17 +1,17 @@ package org.jeewx.api.wxmenu; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.WxstoreUtils; -import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.model.menu.PersonalizedMenu; import org.jeewx.api.core.req.model.menu.WeixinButton; import org.jeewx.api.core.req.model.menu.WeixinMenuMatchrule; import org.jeewx.api.core.util.WeiXinConstant; +import java.util.ArrayList; +import java.util.List; + /** * 微信个性化菜单--menu * @@ -50,7 +50,7 @@ public static String createMenu(String accessToken,PersonalizedMenu menu){ String msg = ""; if (accessToken != null) { String requestUrl = create_menu.replace("ACCESS_TOKEN", accessToken); - JSONObject obj = JSONObject.fromObject(menu); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(menu)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); if(error == null){ @@ -87,11 +87,13 @@ public static String deleteMenu(String accessToken,Integer menu_id){ public static List testMatchrule(String accessToken,String user_id){ if (accessToken != null) { String requestUrl = test_matchrule.replace("ACCESS_TOKEN", accessToken); - String json = "{\"user_id\": "+user_id+"}"; + String json = "{\"user_id\": \""+user_id+"\"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); if(error == null){ - List btns = (List)JSONObject.toBean(result, WeixinButton.class); + JSONObject menu = result.getJSONObject("menu"); + JSONArray button = menu.getJSONArray("button"); + List btns = (List)button.toJavaObject(List.class); return btns; } } diff --git a/src/main/java/org/jeewx/api/wxsendmsg/JwGetAutoReplyRuleAPI.java b/src/main/java/org/jeewx/api/wxsendmsg/JwGetAutoReplyRuleAPI.java index f2c8069..74179cd 100644 --- a/src/main/java/org/jeewx/api/wxsendmsg/JwGetAutoReplyRuleAPI.java +++ b/src/main/java/org/jeewx/api/wxsendmsg/JwGetAutoReplyRuleAPI.java @@ -1,17 +1,12 @@ package org.jeewx.api.wxsendmsg; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; -import net.sf.json.util.JSONUtils; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SimplePropertyPreFilter; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; import org.jeewx.api.core.req.model.message.AutoReplyRuleGet; import org.jeewx.api.core.util.WeiXinConstant; -import org.jeewx.api.extend.CustomJsonConfig; import org.jeewx.api.wxsendmsg.model.WxArticleConfig; import org.jeewx.api.wxsendmsg.model.auto.AutoReplyInfoRule; import org.jeewx.api.wxsendmsg.model.auto.KeyWordAutoReplyInfo; @@ -20,6 +15,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; + /** * 获取自动回复规则 * @author luobaoli @@ -39,21 +37,28 @@ public static AutoReplyInfoRule getAutoReplyInfoRule(String accessToken) throws JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(arr); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); - AutoReplyInfoRule autoReplyInfoRule = (AutoReplyInfoRule) JSONObject.toBean(result,new CustomJsonConfig(AutoReplyInfoRule.class, "keyword_autoreply_info")); +// AutoReplyInfoRule autoReplyInfoRule = (AutoReplyInfoRule) JSONObject.toJavaObject(result,new CustomJsonConfig(AutoReplyInfoRule.class, "keyword_autoreply_info")); + SimplePropertyPreFilter keywordFilter = new SimplePropertyPreFilter(); + keywordFilter.getExcludes().add("keyword_autoreply_info"); + AutoReplyInfoRule autoReplyInfoRule = JSONObject.parseObject(JSONObject.toJSONString(result, keywordFilter), AutoReplyInfoRule.class); JSONObject keywordAutoReplyInfoJsonObj = result.getJSONObject("keyword_autoreply_info"); - if(keywordAutoReplyInfoJsonObj!=null && !JSONUtils.isNull(keywordAutoReplyInfoJsonObj)){ + if(keywordAutoReplyInfoJsonObj!=null && !keywordAutoReplyInfoJsonObj.isEmpty()){ /**关键词自动回复的信息 */ JSONArray keywordAutoReplyInfos = keywordAutoReplyInfoJsonObj.getJSONArray("list"); if(keywordAutoReplyInfos!=null){ List listKeyWordAutoReplyInfo = new ArrayList(); for(int i=0;i listKeywordListInfo = new ArrayList(); for(int j=0;j listReplyListInfo = new ArrayList(); for(int j=0;j listNewsInfo = new ArrayList(); for (int k = 0; k < newsInfos.size(); k++) { - WxArticleConfig wxArticleConfig = (WxArticleConfig) JSONObject.toBean(newsInfos.getJSONObject(k), WxArticleConfig.class); + WxArticleConfig wxArticleConfig = (WxArticleConfig) JSONObject.toJavaObject(newsInfos.getJSONObject(k), WxArticleConfig.class); listNewsInfo.add(wxArticleConfig); } replyListInfo.setNews_info(listNewsInfo); diff --git a/src/main/java/org/jeewx/api/wxsendmsg/JwKfaccountAPI.java b/src/main/java/org/jeewx/api/wxsendmsg/JwKfaccountAPI.java index 807f520..4971c47 100644 --- a/src/main/java/org/jeewx/api/wxsendmsg/JwKfaccountAPI.java +++ b/src/main/java/org/jeewx/api/wxsendmsg/JwKfaccountAPI.java @@ -1,26 +1,18 @@ package org.jeewx.api.wxsendmsg; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; -import org.jeewx.api.core.req.model.kfaccount.KfOnlineAccountList; -import org.jeewx.api.core.req.model.kfaccount.KfaccountAdd; -import org.jeewx.api.core.req.model.kfaccount.KfaccountDel; -import org.jeewx.api.core.req.model.kfaccount.KfaccountList; -import org.jeewx.api.core.req.model.kfaccount.KfaccountUpdate; -import org.jeewx.api.core.req.model.kfaccount.KfaccountUploadheadimg; -import org.jeewx.api.core.req.model.kfaccount.KfcustomSend; +import org.jeewx.api.core.req.model.kfaccount.*; import org.jeewx.api.core.util.WeiXinConstant; -import org.jeewx.api.wxbase.wxtoken.JwTokenAPI; import org.jeewx.api.wxsendmsg.model.WxKfaccount; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; + /** * 微信客服管理处理 * @@ -132,7 +124,7 @@ public static List getAllKfaccount(String accessToken) throws Wexin lstWxKfaccount = new ArrayList(); WxKfaccount kfaccount = null; for(int i = 0; i < kf_list.size() ; i++){ - kfaccount = (WxKfaccount) JSONObject.toBean( kf_list.getJSONObject(i), WxKfaccount.class); + kfaccount = (WxKfaccount) JSONObject.toJavaObject( kf_list.getJSONObject(i), WxKfaccount.class); lstWxKfaccount.add(kfaccount); } return lstWxKfaccount; @@ -181,7 +173,7 @@ public static List getAllOnlineKfaccount(String accessToken) throws lstWxKfaccount = new ArrayList(); WxKfaccount kfaccount = null; for (int i = 0; i < kf_list.size(); i++) { - kfaccount = (WxKfaccount) JSONObject.toBean( + kfaccount = (WxKfaccount) JSONObject.toJavaObject( kf_list.getJSONObject(i), WxKfaccount.class); lstWxKfaccount.add(kfaccount); } diff --git a/src/main/java/org/jeewx/api/wxsendmsg/JwMessageCommentAPI.java b/src/main/java/org/jeewx/api/wxsendmsg/JwMessageCommentAPI.java index d285d96..c79196f 100644 --- a/src/main/java/org/jeewx/api/wxsendmsg/JwMessageCommentAPI.java +++ b/src/main/java/org/jeewx/api/wxsendmsg/JwMessageCommentAPI.java @@ -1,12 +1,11 @@ package org.jeewx.api.wxsendmsg; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.core.exception.WexinReqException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sf.json.JSONObject; - public class JwMessageCommentAPI { private static Logger logger = LoggerFactory.getLogger(JwMessageCommentAPI.class); /** diff --git a/src/main/java/org/jeewx/api/wxsendmsg/JwSendMessageAPI.java b/src/main/java/org/jeewx/api/wxsendmsg/JwSendMessageAPI.java index 9a512dc..5f77606 100644 --- a/src/main/java/org/jeewx/api/wxsendmsg/JwSendMessageAPI.java +++ b/src/main/java/org/jeewx/api/wxsendmsg/JwSendMessageAPI.java @@ -1,13 +1,7 @@ package org.jeewx.api.wxsendmsg; -import java.io.File; -import java.io.StringReader; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import net.sf.json.JSONObject; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import org.jdom.Document; import org.jdom.Element; import org.jdom.input.SAXBuilder; @@ -17,17 +11,20 @@ import org.jeewx.api.core.req.model.user.Group; import org.jeewx.api.core.util.WeiXinReqUtil; import org.jeewx.api.wxbase.wxmedia.model.WxArticlesRequest; -import org.jeewx.api.wxsendmsg.model.SendMessageReport; -import org.jeewx.api.wxsendmsg.model.SendMessageResponse; -import org.jeewx.api.wxsendmsg.model.WxArticle; -import org.jeewx.api.wxsendmsg.model.WxArticlesResponse; -import org.jeewx.api.wxsendmsg.model.WxMedia; -import org.jeewx.api.wxsendmsg.model.WxMediaResponse; +import org.jeewx.api.wxsendmsg.model.*; import org.jeewx.api.wxsendmsg.util.ReadImgUrls; import org.jeewx.api.wxuser.user.model.Wxuser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.StringReader; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + public class JwSendMessageAPI { private static Logger logger = LoggerFactory.getLogger(JwSendMessageAPI.class); // 消息预览URL @@ -100,7 +97,7 @@ public static String uploadImg(String accesstoken, String filePath){ // JSONObject result = WxstoreUtils.uploadMediaFile(requestUrl, file, contentType); HttpPostUtil u = new HttpPostUtil(requestUrl); u.addFileParameter("img", new File(filePath)); - JSONObject result = JSONObject.fromObject(new String(u.send())); + JSONObject result = JSONObject.parseObject(new String(u.send())); if(result!=null){ if(result.containsKey("url")){ return result.getString("url"); @@ -130,7 +127,7 @@ public static JSONObject uploadImgReturnObj(String accesstoken, String filePath) String requestUrl = uploadimg_url.replace("ACCESS_TOKEN", accesstoken); HttpPostUtil u = new HttpPostUtil(requestUrl); u.addFileParameter("img", new File(filePath)); - result = JSONObject.fromObject(new String(u.send())); + result = JSONObject.parseObject(new String(u.send())); if(result!=null){ if(!result.containsKey("url")){ System.err.println(result.toString()); @@ -232,7 +229,7 @@ public static void messagePrivate(String accesstoken, String touser, WxMedia wxM obj.put(wxMedia.getType(), type); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - if (result.getInt("errcode") != 0) { + if (result.getInteger("errcode") != 0) { logger.error("多媒体消息预览失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new Exception("多媒体消息预览失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } @@ -281,7 +278,7 @@ public static SendMessageResponse sendMessageToGroupOrAllWithArticles(String acc obj.put("msgtype", "mpnews"); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - response = (SendMessageResponse) JSONObject.toBean(result, SendMessageResponse.class); + response = (SendMessageResponse) JSONObject.toJavaObject(result, SendMessageResponse.class); } catch (Exception e) { throw new WexinReqException(e); @@ -329,7 +326,7 @@ public static SendMessageResponse sendMessageToGroupOrAllWithText(String accesst JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - response = (SendMessageResponse) JSONObject.toBean(result, SendMessageResponse.class); + response = (SendMessageResponse) JSONObject.toJavaObject(result, SendMessageResponse.class); } catch (Exception e) { throw new WexinReqException(e); @@ -380,7 +377,7 @@ public static SendMessageResponse sendMessageToGroupOrAllWithMedia(String access JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - response = (SendMessageResponse) JSONObject.toBean(result, SendMessageResponse.class); + response = (SendMessageResponse) JSONObject.toJavaObject(result, SendMessageResponse.class); } catch (Exception e) { throw new WexinReqException(e); @@ -423,7 +420,7 @@ public static SendMessageResponse sendMessageToOpenidsWithArticles(String access obj.put("msgtype", "mpnews"); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - response = (SendMessageResponse) JSONObject.toBean(result, SendMessageResponse.class); + response = (SendMessageResponse) JSONObject.toJavaObject(result, SendMessageResponse.class); } catch (Exception e) { throw new WexinReqException(e); @@ -468,7 +465,7 @@ public static SendMessageResponse sendMessageToOpenidsWithText(String accesstoke JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - response = (SendMessageResponse) JSONObject.toBean(result, SendMessageResponse.class); + response = (SendMessageResponse) JSONObject.toJavaObject(result, SendMessageResponse.class); } catch (Exception e) { throw new WexinReqException(e); @@ -515,7 +512,7 @@ public static SendMessageResponse sendMessageToOpenidsWithMedia(String accesstok JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); - response = (SendMessageResponse) JSONObject.toBean(result, SendMessageResponse.class); + response = (SendMessageResponse) JSONObject.toJavaObject(result, SendMessageResponse.class); } catch (Exception e) { throw new WexinReqException(e); @@ -710,10 +707,10 @@ public static WxArticlesResponse uploadArticles(String accesstoken, List getshops(String newAccessToken, BusinessReq businessReq) { if (newAccessToken != null) { String requestUrl = search_shop_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(businessReq); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(businessReq)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); // 正常返回 List baseInfos = null; @@ -147,7 +147,7 @@ public static String uploadImg(String newAccessToken, String filePath, String fi try { fileByte = fileData(filePath+fileName); JSONObject result = WxstoreUtils.httpRequest2(requestUrl, "POST", fileByte); - if (result.getInt("errcode") == 0) { + if (result.getInteger("errcode") == 0) { return result.getString("url"); } return ""; diff --git a/src/main/java/org/jeewx/api/wxstore/deliveryMoney/JwDeliveryMoneyAPI.java b/src/main/java/org/jeewx/api/wxstore/deliveryMoney/JwDeliveryMoneyAPI.java index 5724ef0..c564a41 100644 --- a/src/main/java/org/jeewx/api/wxstore/deliveryMoney/JwDeliveryMoneyAPI.java +++ b/src/main/java/org/jeewx/api/wxstore/deliveryMoney/JwDeliveryMoneyAPI.java @@ -1,14 +1,14 @@ package org.jeewx.api.wxstore.deliveryMoney; -import java.util.List; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.JSONHelper; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.wxstore.deliveryMoney.model.DeliveryMoney; import org.jeewx.api.wxstore.deliveryMoney.model.DeliveryMoneyRtnInfo; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; +import java.util.List; /** @@ -36,9 +36,9 @@ public class JwDeliveryMoneyAPI { public static DeliveryMoneyRtnInfo doAddExpress(String newAccessToken, DeliveryMoney postage) { if (newAccessToken != null) { String requestUrl = create_postage_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(postage); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(postage)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - DeliveryMoneyRtnInfo postageRtnInfo = (DeliveryMoneyRtnInfo)JSONObject.toBean(result, DeliveryMoneyRtnInfo.class); + DeliveryMoneyRtnInfo postageRtnInfo = (DeliveryMoneyRtnInfo)JSONObject.toJavaObject(result, DeliveryMoneyRtnInfo.class); return postageRtnInfo; } return null; @@ -54,7 +54,7 @@ public static DeliveryMoneyRtnInfo doDelExpress(String newAccessToken, Integer t String requestUrl = del_postage_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"template_id\": "+template_id+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - DeliveryMoneyRtnInfo postageRtnInfo = (DeliveryMoneyRtnInfo)JSONObject.toBean(result, DeliveryMoneyRtnInfo.class); + DeliveryMoneyRtnInfo postageRtnInfo = (DeliveryMoneyRtnInfo)JSONObject.toJavaObject(result, DeliveryMoneyRtnInfo.class); return postageRtnInfo; } return null; @@ -68,9 +68,9 @@ public static DeliveryMoneyRtnInfo doDelExpress(String newAccessToken, Integer t public static DeliveryMoneyRtnInfo doUpdateExpress(String newAccessToken, DeliveryMoney postage) { if (newAccessToken != null) { String requestUrl = update_postage_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(postage); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(postage)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - DeliveryMoneyRtnInfo postageRtnInfo = (DeliveryMoneyRtnInfo)JSONObject.toBean(result, DeliveryMoneyRtnInfo.class); + DeliveryMoneyRtnInfo postageRtnInfo = (DeliveryMoneyRtnInfo)JSONObject.toJavaObject(result, DeliveryMoneyRtnInfo.class); return postageRtnInfo; } return null; diff --git a/src/main/java/org/jeewx/api/wxstore/group/JwGroupManangerAPI.java b/src/main/java/org/jeewx/api/wxstore/group/JwGroupManangerAPI.java index 423a8de..9180118 100644 --- a/src/main/java/org/jeewx/api/wxstore/group/JwGroupManangerAPI.java +++ b/src/main/java/org/jeewx/api/wxstore/group/JwGroupManangerAPI.java @@ -1,7 +1,8 @@ package org.jeewx.api.wxstore.group; -import java.util.List; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.JSONHelper; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.wxstore.group.model.Group; @@ -9,9 +10,7 @@ import org.jeewx.api.wxstore.group.model.GroupProductInfo; import org.jeewx.api.wxstore.group.model.GroupRtnInfo; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; +import java.util.List; /** * 微信小店 - 分组 @@ -40,9 +39,9 @@ public class JwGroupManangerAPI { public static GroupRtnInfo doAddGroupManager(String newAccessToken, Group group) { if (newAccessToken != null) { String requestUrl = create_group_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(group); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(group)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toBean(result, GroupRtnInfo.class); + GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toJavaObject(result, GroupRtnInfo.class); return groupRtnInfo; } return null; @@ -58,7 +57,7 @@ public static GroupRtnInfo doDelGroupManager(String newAccessToken, Integer grou String requestUrl = del_group_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"group_id\": "+group_id+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toBean(result, GroupRtnInfo.class); + GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toJavaObject(result, GroupRtnInfo.class); return groupRtnInfo; } return null; @@ -72,9 +71,9 @@ public static GroupRtnInfo doDelGroupManager(String newAccessToken, Integer grou public static GroupRtnInfo doUpdateGroupManagerProperties(String newAccessToken, Group group) { if (newAccessToken != null) { String requestUrl = update_group_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(group); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(group)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toBean(result, GroupRtnInfo.class); + GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toJavaObject(result, GroupRtnInfo.class); return groupRtnInfo; } return null; @@ -88,9 +87,9 @@ public static GroupRtnInfo doUpdateGroupManagerProperties(String newAccessToken, public static GroupRtnInfo doUpdateGroupManagerProduct(String newAccessToken, GroupProductInfo groupProductInfo) { if (newAccessToken != null) { String requestUrl = update_productmod_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(groupProductInfo); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(groupProductInfo)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toBean(result, GroupRtnInfo.class); + GroupRtnInfo groupRtnInfo = (GroupRtnInfo)JSONObject.toJavaObject(result, GroupRtnInfo.class); return groupRtnInfo; } return null; @@ -125,7 +124,7 @@ public static GroupDetailInfo getByGroupId(String newAccessToken, Integer group_ // 正常返回 GroupDetailInfo groupDetailInfo = null; JSONObject info = result.getJSONObject("group_detail"); - groupDetailInfo = (GroupDetailInfo)JSONObject.toBean(info, GroupDetailInfo.class); + groupDetailInfo = (GroupDetailInfo)JSONObject.toJavaObject(info, GroupDetailInfo.class); return groupDetailInfo; } return null; diff --git a/src/main/java/org/jeewx/api/wxstore/order/JwOrderManagerAPI.java b/src/main/java/org/jeewx/api/wxstore/order/JwOrderManagerAPI.java index 4fb476b..e9f38c2 100644 --- a/src/main/java/org/jeewx/api/wxstore/order/JwOrderManagerAPI.java +++ b/src/main/java/org/jeewx/api/wxstore/order/JwOrderManagerAPI.java @@ -1,7 +1,8 @@ package org.jeewx.api.wxstore.order; -import java.util.List; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.JSONHelper; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.wxstore.order.model.OrderDelivery; @@ -9,8 +10,7 @@ import org.jeewx.api.wxstore.order.model.OrderPara; import org.jeewx.api.wxstore.order.model.OrderRtnInfo; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; +import java.util.List; /** @@ -41,7 +41,7 @@ public static OrderInfo getByOrderId(String newAccessToken, String order_id) { // 正常返回 OrderInfo orderInfo = null; JSONObject info = result.getJSONObject("order"); - orderInfo = (OrderInfo)JSONObject.toBean(info, OrderInfo.class); + orderInfo = (OrderInfo)JSONObject.toJavaObject(info, OrderInfo.class); return orderInfo; } return null; @@ -55,7 +55,7 @@ public static OrderInfo getByOrderId(String newAccessToken, String order_id) { public static List getByFilter(String newAccessToken, OrderPara orderPara) { if (newAccessToken != null) { String requestUrl = getfilter_order_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(orderPara); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(orderPara)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET", obj.toString()); // 正常返回 List orderInfos = null; @@ -74,9 +74,9 @@ public static List getByFilter(String newAccessToken, OrderPara order public static OrderRtnInfo doDelivery(String newAccessToken, OrderDelivery orderDelivery) { if (newAccessToken != null) { String requestUrl = setdelivery_order_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(orderDelivery); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(orderDelivery)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - OrderRtnInfo orderRtnInfo = (OrderRtnInfo)JSONObject.toBean(result, OrderRtnInfo.class); + OrderRtnInfo orderRtnInfo = (OrderRtnInfo)JSONObject.toJavaObject(result, OrderRtnInfo.class); return orderRtnInfo; } return null; @@ -92,7 +92,7 @@ public static OrderRtnInfo doCloseOrder(String newAccessToken, String order_id) String requestUrl = close_order_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"order_id\": \""+order_id+"\"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - OrderRtnInfo orderRtnInfo = (OrderRtnInfo)JSONObject.toBean(result, OrderRtnInfo.class); + OrderRtnInfo orderRtnInfo = (OrderRtnInfo)JSONObject.toJavaObject(result, OrderRtnInfo.class); return orderRtnInfo; } return null; diff --git a/src/main/java/org/jeewx/api/wxstore/product/JwProductAPI.java b/src/main/java/org/jeewx/api/wxstore/product/JwProductAPI.java index a6cb415..542a3cb 100644 --- a/src/main/java/org/jeewx/api/wxstore/product/JwProductAPI.java +++ b/src/main/java/org/jeewx/api/wxstore/product/JwProductAPI.java @@ -1,24 +1,20 @@ package org.jeewx.api.wxstore.product; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.io.IOUtils; +import org.jeewx.api.core.common.JSONHelper; +import org.jeewx.api.core.common.WxstoreUtils; +import org.jeewx.api.core.common.util.WeixinUtil; +import org.jeewx.api.wxstore.product.model.*; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -import org.apache.commons.io.IOUtils; -import org.jeewx.api.core.common.JSONHelper; -import org.jeewx.api.core.common.WxstoreUtils; -import org.jeewx.api.core.common.util.WeixinUtil; -import org.jeewx.api.wxstore.product.model.CateInfo; -import org.jeewx.api.wxstore.product.model.CommodityRtnInfo; -import org.jeewx.api.wxstore.product.model.Product; -import org.jeewx.api.wxstore.product.model.PropertiesInfo; -import org.jeewx.api.wxstore.product.model.SkuInfo; - /** * 微信小店 - 商品 @@ -53,9 +49,9 @@ public class JwProductAPI { public static CommodityRtnInfo doAddCommodity(String newAccessToken, Product product) { if (newAccessToken != null) { String requestUrl = WeixinUtil.parseWeiXinHttpUrl(create_commodity_url, newAccessToken); - JSONObject obj = JSONObject.fromObject(product); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(product)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toBean(result, CommodityRtnInfo.class); + CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toJavaObject(result, CommodityRtnInfo.class); return commodityRtnInfo; } return null; @@ -69,7 +65,7 @@ public static CommodityRtnInfo doDelCommodity(String newAccessToken, String prod String requestUrl = del_commodity_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"product_id\": \""+product_id+"\"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toBean(result, CommodityRtnInfo.class); + CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toJavaObject(result, CommodityRtnInfo.class); return commodityRtnInfo; } return null; @@ -81,9 +77,9 @@ public static CommodityRtnInfo doDelCommodity(String newAccessToken, String prod public static CommodityRtnInfo doUpdateCommodity(String newAccessToken, Product product, String accountid) { if (newAccessToken != null) { String requestUrl = update_commodity_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(product); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(product)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toBean(result, CommodityRtnInfo.class); + CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toJavaObject(result, CommodityRtnInfo.class); return commodityRtnInfo; } return null; @@ -100,7 +96,7 @@ public static Product getCommodity(String newAccessToken, String product_id) { // 正常返回 Product product = null; JSONObject info = result.getJSONObject("product_info"); - product = (Product)JSONObject.toBean(info, Product.class); + product = (Product)JSONObject.toJavaObject(info, Product.class); return product; } return null; @@ -115,7 +111,7 @@ public static CommodityRtnInfo getByStatus(String newAccessToken, Integer status String requestUrl = getbystatus_commodity_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"status\": "+status+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toBean(result, CommodityRtnInfo.class); + CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toJavaObject(result, CommodityRtnInfo.class); return commodityRtnInfo; } return null; @@ -136,7 +132,7 @@ public static String uploadImg(String newAccessToken, String filePath, String fi try { fileByte = fileData(filePath+fileName); JSONObject result = WxstoreUtils.httpRequest2(requestUrl, "POST", fileByte); - if (result.getInt("errcode") == 0) { + if (result.getInteger("errcode") == 0) { return result.getString("image_url"); } return ""; @@ -165,7 +161,7 @@ public static CommodityRtnInfo doModproductstatus(String newAccessToken, String String requestUrl = modproductstatus_commodity_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"product_id\":\""+product_id+"\",\"status\": "+status+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toBean(result, CommodityRtnInfo.class); + CommodityRtnInfo commodityRtnInfo = (CommodityRtnInfo)JSONObject.toJavaObject(result, CommodityRtnInfo.class); return commodityRtnInfo; } return null; diff --git a/src/main/java/org/jeewx/api/wxstore/shelf/JwShelfAPI.java b/src/main/java/org/jeewx/api/wxstore/shelf/JwShelfAPI.java index 6c99794..11862c5 100644 --- a/src/main/java/org/jeewx/api/wxstore/shelf/JwShelfAPI.java +++ b/src/main/java/org/jeewx/api/wxstore/shelf/JwShelfAPI.java @@ -1,15 +1,15 @@ package org.jeewx.api.wxstore.shelf; -import java.util.List; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.JSONHelper; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.wxstore.shelf.model.Shelf; import org.jeewx.api.wxstore.shelf.model.ShelfRInfo; import org.jeewx.api.wxstore.shelf.model.ShelfRtnInfo; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; +import java.util.List; @@ -44,9 +44,9 @@ public class JwShelfAPI { public static ShelfRtnInfo doAddExpress(String newAccessToken, Shelf shelf) { if (newAccessToken != null) { String requestUrl = create_shelf_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(shelf); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(shelf)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - ShelfRtnInfo shelfRtnInfo = (ShelfRtnInfo)JSONObject.toBean(result, ShelfRtnInfo.class); + ShelfRtnInfo shelfRtnInfo = (ShelfRtnInfo)JSONObject.toJavaObject(result, ShelfRtnInfo.class); return shelfRtnInfo; } return null; @@ -60,9 +60,9 @@ public static ShelfRtnInfo doAddExpress(String newAccessToken, Shelf shelf) { public static ShelfRtnInfo doUpdateExpress(String newAccessToken, Shelf shelf) { if (newAccessToken != null) { String requestUrl = update_shelf_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(shelf); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(shelf)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - ShelfRtnInfo shelfRtnInfo = (ShelfRtnInfo)JSONObject.toBean(result, ShelfRtnInfo.class); + ShelfRtnInfo shelfRtnInfo = (ShelfRtnInfo)JSONObject.toJavaObject(result, ShelfRtnInfo.class); return shelfRtnInfo; } return null; @@ -78,7 +78,7 @@ public static ShelfRtnInfo doDelShelfManager(String newAccessToken, Integer shel String requestUrl = del_shelf_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"shelf_id\": "+shelf_id+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); - ShelfRtnInfo shelfRtnInfo = (ShelfRtnInfo)JSONObject.toBean(result, ShelfRtnInfo.class); + ShelfRtnInfo shelfRtnInfo = (ShelfRtnInfo)JSONObject.toJavaObject(result, ShelfRtnInfo.class); return shelfRtnInfo; } return null; @@ -96,7 +96,7 @@ public static ShelfRInfo getByShelfId(String newAccessToken, Integer shelf_id) { JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); // 正常返回 ShelfRInfo shelfRInfo = null; - shelfRInfo = (ShelfRInfo)JSONObject.toBean(result, ShelfRInfo.class); + shelfRInfo = (ShelfRInfo)JSONObject.toJavaObject(result, ShelfRInfo.class); return shelfRInfo; } return null; diff --git a/src/main/java/org/jeewx/api/wxstore/stock/JwStockAPI.java b/src/main/java/org/jeewx/api/wxstore/stock/JwStockAPI.java index 9380fc7..aa26a88 100644 --- a/src/main/java/org/jeewx/api/wxstore/stock/JwStockAPI.java +++ b/src/main/java/org/jeewx/api/wxstore/stock/JwStockAPI.java @@ -1,11 +1,11 @@ package org.jeewx.api.wxstore.stock; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.wxstore.stock.model.StockInfo; import org.jeewx.api.wxstore.stock.model.StockRtnInfo; -import net.sf.json.JSONObject; - /** * 微信小店 - 库存 @@ -24,9 +24,9 @@ public class JwStockAPI { public static StockRtnInfo doAddStock(String newAccessToken, StockInfo stockInfo) { if (newAccessToken != null) { String requestUrl = add_stock_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(stockInfo); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(stockInfo)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - StockRtnInfo stockRtnInfo = (StockRtnInfo)JSONObject.toBean(result, StockRtnInfo.class); + StockRtnInfo stockRtnInfo = (StockRtnInfo)JSONObject.toJavaObject(result, StockRtnInfo.class); return stockRtnInfo; } return null; @@ -38,9 +38,9 @@ public static StockRtnInfo doAddStock(String newAccessToken, StockInfo stockInfo public static StockRtnInfo doSubStock(String newAccessToken, StockInfo stockInfo) { if (newAccessToken != null) { String requestUrl = sub_stock_url.replace("ACCESS_TOKEN", newAccessToken); - JSONObject obj = JSONObject.fromObject(stockInfo); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(stockInfo)); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); - StockRtnInfo stockRtnInfo = (StockRtnInfo)JSONObject.toBean(result, StockRtnInfo.class); + StockRtnInfo stockRtnInfo = (StockRtnInfo)JSONObject.toJavaObject(result, StockRtnInfo.class); return stockRtnInfo; } return null; diff --git a/src/main/java/org/jeewx/api/wxuser/group/JwGroupAPI.java b/src/main/java/org/jeewx/api/wxuser/group/JwGroupAPI.java index ca49eca..32862b0 100644 --- a/src/main/java/org/jeewx/api/wxuser/group/JwGroupAPI.java +++ b/src/main/java/org/jeewx/api/wxuser/group/JwGroupAPI.java @@ -1,25 +1,15 @@ package org.jeewx.api.wxuser.group; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -import org.jeewx.api.core.common.AccessToken; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; -import org.jeewx.api.core.req.model.user.BatchGroupMembersUpdate; -import org.jeewx.api.core.req.model.user.Group; -import org.jeewx.api.core.req.model.user.GroupCreate; -import org.jeewx.api.core.req.model.user.GroupDelete; -import org.jeewx.api.core.req.model.user.GroupGet; -import org.jeewx.api.core.req.model.user.GroupGetId; -import org.jeewx.api.core.req.model.user.GroupMembersUpdate; -import org.jeewx.api.core.req.model.user.GroupUpdate; +import org.jeewx.api.core.req.model.user.*; import org.jeewx.api.core.util.WeiXinConstant; import org.jeewx.api.wxbase.wxtoken.JwTokenAPI; -import org.jeewx.api.wxuser.user.JwUserAPI; + +import java.util.ArrayList; +import java.util.List; /** * 微信--用户 @@ -49,7 +39,7 @@ public static GroupCreate createGroup(String accesstoken ,String groupName ) thr JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(c); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); GroupCreate groupCreate = null; - groupCreate = (GroupCreate) JSONObject.toBean(result, GroupCreate.class); + groupCreate = (GroupCreate) JSONObject.toJavaObject(result, GroupCreate.class); return groupCreate; } @@ -68,7 +58,7 @@ public static List getAllGroup(String accesstoken) throws WexinReqExcepti JSONArray infoArray = result.getJSONArray(RETURN_INFO_NAME); lstGroup = new ArrayList(infoArray.size()); for(int i=0;i getTags(String accessToken){ Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); if(error == null){ String tags = result.getString("tags"); - JSONArray jsonArray = JSONArray.fromObject(tags); - list = JSONArray.toList(jsonArray, WxTag.class); + JSONArray jsonArray = JSONArray.parseArray(tags); + list = jsonArray.toJavaList(WxTag.class); return list; } logger.info("获取标签方法执行后json参数 : "+result.toString()); @@ -135,7 +135,7 @@ public static WxTagUser getTagUser(String accessToken,int tagid,String next_open Map data = new HashMap(); data.put("tagid", tagid); data.put("next_openid", next_openid); - JSONObject obj = JSONObject.fromObject(data); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(data)); logger.info("获取标签下粉丝列表方法执行前json参数---obj: "+obj.toString()); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET", obj.toString()); Integer error = (Integer) result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); @@ -150,7 +150,7 @@ public static WxTagUser getTagUser(String accessToken,int tagid,String next_open tagUser.setCount(count); tagUser.setData(users); tagUser.setNext_openid(nextOpenid);*/ - tagUser = (WxTagUser) JSONObject.toBean(result, WxTagUser.class); + tagUser = (WxTagUser) JSONObject.toJavaObject(result, WxTagUser.class); } logger.info("获取标签下粉丝列表方法执行后json参数 : "+result.toString()); } @@ -170,7 +170,7 @@ public static JSONObject batchtagging(String accessToken,List openid_lis Map data = new HashMap(); data.put("openid_list", openid_list); data.put("tagid", tagid); - JSONObject obj = JSONObject.fromObject(data); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(data)); logger.info("批量为用户打标签 方法执行前json参数---obj: "+obj.toString()); result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); logger.info("批量为用户打标签 方法执行后json参数 : "+result.toString()); @@ -188,7 +188,7 @@ public static JSONObject batchuntagging(String accessToken,List openid_l Map data = new HashMap(); data.put("openid_list", openid_list); data.put("tagid", tagid); - JSONObject obj = JSONObject.fromObject(data); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(data)); logger.info("批量为用户取消标签 方法执行前json参数---obj: "+obj.toString()); result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); logger.info("批量为用户取消标签 方法执行后json参数 : "+result.toString()); @@ -205,13 +205,13 @@ public static List getidlist(String accessToken,String openid){ String requestUrl = getidlist.replace("ACCESS_TOKEN", accessToken); Map data = new HashMap(); data.put("openid", openid); - JSONObject obj = JSONObject.fromObject(data); + JSONObject obj = JSONObject.parseObject(JSON.toJSONString(data)); logger.info("获取用户身上的标签列表 方法执行前json参数---obj: "+obj.toString()); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); if(error == null){ JSONArray jsonArray = result.getJSONArray("tagid_list"); - list = JSONArray.toList(jsonArray, Integer.class); + list = jsonArray.toJavaList(Integer.class); } logger.info("获取用户身上的标签列表 方法执行后json参数 : "+result.toString()); } diff --git a/src/main/java/org/jeewx/api/wxuser/user/JwUserAPI.java b/src/main/java/org/jeewx/api/wxuser/user/JwUserAPI.java index b9a5bf9..bebb854 100644 --- a/src/main/java/org/jeewx/api/wxuser/user/JwUserAPI.java +++ b/src/main/java/org/jeewx/api/wxuser/user/JwUserAPI.java @@ -1,11 +1,7 @@ package org.jeewx.api.wxuser.user; -import java.util.ArrayList; -import java.util.List; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.jeewx.api.core.common.WxstoreUtils; import org.jeewx.api.core.exception.WexinReqException; import org.jeewx.api.core.req.WeiXinReqService; @@ -14,6 +10,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; + /** * 微信--用户 * @@ -41,7 +40,7 @@ public static Wxuser getWxuser(String accesstoken,String user_openid) throws We // 正常返回 Wxuser wxuser = null; Object error = result.get("errcode"); - wxuser = (Wxuser) JSONObject.toBean(result, Wxuser.class); + wxuser = (Wxuser) JSONObject.toJavaObject(result, Wxuser.class); return wxuser; } return null; @@ -62,8 +61,8 @@ public static List getAllWxuser(String accesstoken,String next_openid) t Object error = result.get("errcode"); List lstUser = null; Wxuser mxuser = null; - int total = result.getInt("total"); - int count = result.getInt("count"); + int total = result.getInteger("total"); + int count = result.getInteger("count"); String strNextOpenId = result.getString("next_openid"); JSONObject data = result.getJSONObject("data"); lstUser = new ArrayList(total); diff --git a/src/test/java/org/jeewx/api/prtest/DingDingTest.java b/src/test/java/org/jeewx/api/prtest/DingDingTest.java new file mode 100644 index 0000000..6741dc0 --- /dev/null +++ b/src/test/java/org/jeewx/api/prtest/DingDingTest.java @@ -0,0 +1,70 @@ +package org.jeewx.api.prtest; + +import com.alibaba.fastjson.JSONObject; +import com.jeecg.dingtalk.api.base.JdtBaseAPI; +import com.jeecg.dingtalk.api.core.response.Response; +import com.jeecg.dingtalk.api.core.vo.AccessToken; +import com.jeecg.dingtalk.api.core.vo.PageResult; +import com.jeecg.dingtalk.api.department.JdtDepartmentAPI; +import com.jeecg.dingtalk.api.department.vo.Department; +import com.jeecg.dingtalk.api.message.JdtMessageAPI; +import com.jeecg.dingtalk.api.message.vo.Message; +import com.jeecg.dingtalk.api.message.vo.TextMessage; +import com.jeecg.dingtalk.api.user.JdtUserAPI; +import com.jeecg.dingtalk.api.user.body.GetUserListBody; +import com.jeecg.dingtalk.api.user.vo.User; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +/** +* @Description: 钉钉第三方测试类 +* +* @author: wangshuai +* @date: 2024/9/11 上午10:45 +*/ +public class DingDingTest { + + private static final org.slf4j.Logger log = LoggerFactory.getLogger(DingDingTest.class); + + /** + * 获取部门下的用户 + */ + @Test + public void getUserList() { + String accessToken = this.getAccessToken(); + log.info("accessToken====="+accessToken); + Response department = JdtDepartmentAPI.getDepartmentById(1, accessToken); + //获取部门信息 + if(department.isSuccess()){ + Department departmentResult = department.getResult(); + log.info("~~~~~~~~~~~~部门id~~~~~~~~~~~~~~"+ departmentResult.getDept_id()); + log.info("~~~~~~~~~~~~部门名称~~~~~~~~~~~~~~"+ departmentResult.getName()); + log.info("获取部门下的用户"); + GetUserListBody getUserListBody = new GetUserListBody(departmentResult.getDept_id(), 0, 100); + Response> response = JdtUserAPI.getUserListByDeptId(getUserListBody, accessToken); + if(response.isSuccess()){ + PageResult result = response.getResult(); + log.info("~~~~~~~~~~~用户列表~~~~~~~~~~"+ JSONObject.toJSONString(result.getList())); + } + } + } + + /** + * 发送模板消息 到钉钉 + */ + @Test + public void sendMessageToDing() { + String accessToken = this.getAccessToken(); + Message textMessage = new Message<>("2820902354", new TextMessage("测试钉钉消息")); + textMessage.setTo_all_user(true); + Response response = JdtMessageAPI.sendTextMessage(textMessage, accessToken); + if(response.isSuccess()){ + log.info("钉钉消息发送状态:" + response.getResult()); + } + } + + public String getAccessToken() { + AccessToken accessToken = JdtBaseAPI.getAccessToken("dingdbgpfnv56wtdpli9", "??"); + return accessToken.getAccessToken(); + } +} diff --git a/src/test/java/org/jeewx/api/prtest/QywxTest.java b/src/test/java/org/jeewx/api/prtest/QywxTest.java new file mode 100644 index 0000000..e43c2e4 --- /dev/null +++ b/src/test/java/org/jeewx/api/prtest/QywxTest.java @@ -0,0 +1,98 @@ +package org.jeewx.api.prtest; + + +import com.alibaba.fastjson.JSONObject; +import com.jeecg.qywx.api.base.JwAccessTokenAPI; +import com.jeecg.qywx.api.core.common.AccessToken; +import com.jeecg.qywx.api.core.util.WXUpload; +import com.jeecg.qywx.api.department.JwDepartmentAPI; +import com.jeecg.qywx.api.department.vo.Department; +import com.jeecg.qywx.api.message.JwMessageAPI; +import com.jeecg.qywx.api.message.vo.Text; +import com.jeecg.qywx.api.message.vo.TextEntity; +import com.jeecg.qywx.api.user.JwUserAPI; +import com.jeecg.qywx.api.user.vo.User; +import org.apache.commons.collections.CollectionUtils; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.nio.file.Files; +import java.util.Collections; +import java.util.List; + +/** +* @Description: 企业微信第三方测试类 +* +* @author: wangshuai +* @date: 2024/9/11 上午10:45 +*/ +public class QywxTest { + + private static final org.slf4j.Logger log = LoggerFactory.getLogger(QywxTest.class); + + /** + * 获取部门下的用户 + */ + @Test + public void getUserList() { + String accessToken = this.getAccessToken(); + log.info("accessToken====="+accessToken); + List allDepartment = JwDepartmentAPI.getAllDepartment(accessToken); + //获取部门信息 + if(!CollectionUtils.isEmpty(allDepartment)){ + log.info("allDepartment====="+ JSONObject.toJSONString(allDepartment)); + log.info("~~~~~~~~~~~~其中一个部门id~~~~~~~~~~~~~~"+ allDepartment.get(0).getId()); + log.info("~~~~~~~~~~~~其中一个部门名称~~~~~~~~~~~~~~"+ allDepartment.get(0).getName()); + log.info("获取部门下的用户"); + List usersByDepartid = JwUserAPI.getUsersByDepartid(allDepartment.get(0).getId(), "1", null, accessToken); + if(!CollectionUtils.isEmpty(usersByDepartid)){ + log.info("~~~~~~~~~~~用户列表~~~~~~~~~~"+ JSONObject.toJSONString(usersByDepartid)); + } + } + } + + /** + * 发送模板消息 到企业微信 + */ + @Test + public void sendMessageToQywx() { + String accessToken = this.getAccessToken(); + Text text = new Text(); + text.setMsgtype("text"); + text.setTouser("@all"); + TextEntity entity = new TextEntity(); + entity.setContent("测试企业微信消息"); + text.setText(entity); + text.setAgentid(Integer.parseInt("1000009")); + JSONObject jsonObject = JwMessageAPI.sendTextMessage(text, accessToken); + log.info("=========返回系统消息====="+jsonObject); + } + + /** + * 复制文件到指定目录 + */ + @Test + public void writeFile() { + try (FileInputStream fileInputStream = new FileInputStream("D://images/gdbt.jpg"); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { + + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = fileInputStream.read(buffer)) != -1) { + byteArrayOutputStream.write(buffer, 0, bytesRead); + } + + byte[] byteArray = byteArrayOutputStream.toByteArray(); + WXUpload.writeFile(byteArray,"D://images","2.jpg",false); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public String getAccessToken() { + AccessToken accessToken = JwAccessTokenAPI.getAccessToken("??", "??"); + return accessToken.getAccesstoken(); + } +} diff --git a/src/test/java/org/jeewx/api/prtest/WeChatAccountTest.java b/src/test/java/org/jeewx/api/prtest/WeChatAccountTest.java new file mode 100644 index 0000000..27decd5 --- /dev/null +++ b/src/test/java/org/jeewx/api/prtest/WeChatAccountTest.java @@ -0,0 +1,283 @@ +package org.jeewx.api.prtest; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.jeecg.dingtalk.api.base.JdtBaseAPI; +import org.jeewx.api.core.common.AccessToken; +import org.jeewx.api.core.exception.WexinReqException; +import org.jeewx.api.core.req.model.menu.PersonalizedMenu; +import org.jeewx.api.core.req.model.menu.WeixinButton; +import org.jeewx.api.core.req.model.menu.WeixinMenuMatchrule; +import org.jeewx.api.core.req.model.menu.config.CustomWeixinButtonConfig; +import org.jeewx.api.core.req.model.user.Group; +import org.jeewx.api.core.req.model.user.GroupCreate; +import org.jeewx.api.wxbase.wxtoken.JwTokenAPI; +import org.jeewx.api.wxmenu.JwMenuAPI; +import org.jeewx.api.wxmenu.JwPersonalizedMenuAPI; +import org.jeewx.api.wxuser.group.JwGroupAPI; +import org.jeewx.api.wxuser.tag.JwTagAPI; +import org.jeewx.api.wxuser.tag.model.WxTag; +import org.jeewx.api.wxuser.tag.model.WxTagUser; +import org.jeewx.api.wxuser.user.JwUserAPI; +import org.jeewx.api.wxuser.user.model.Wxuser; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** +* @Description: 公众号测试 +* 测试用例 敲敲云公众号 +* @author: wangshuai +* @date: 2024/9/11 上午10:45 +*/ +public class WeChatAccountTest { + + private static final org.slf4j.Logger log = LoggerFactory.getLogger(WeChatAccountTest.class); + private static String appid = "??"; + private static String appscret = "??"; + + //============= 获取粉丝 =========================================== + /** + * 获取粉丝 + * + * @throws WexinReqException + */ + @Test + public void getUserInfo() throws WexinReqException { + String accessToken = this.getAccessToken(); + Wxuser wxusers = JwUserAPI.getWxuser(accessToken, "oKMOd6TU0cOqlQalYtGCPD5jWfY8"); + log.info("~~~~~~~获取粉丝~~~~~~~~~"+JSONObject.toJSONString(wxusers)); + log.info(accessToken); + } + + /** + * 获取所有粉丝(一个一个获取,特别慢) + * + * @throws WexinReqException + */ + @Test + public void getAllUserInfo() throws WexinReqException { + String accessToken = this.getAccessToken(); + List allWxuser = JwUserAPI.getAllWxuser(accessToken, null); + log.info("~~~~~~~获取粉丝列表~~~~~~~~~"+JSONObject.toJSONString(allWxuser)); + log.info(accessToken); + } + + //============= 用户分组 =========================================== + /** + * 获取所有分组信息 + * + * @throws WexinReqException + */ + @Test + public void getAllGroup() throws WexinReqException { + List allGroup = JwGroupAPI.getAllGroup(this.getAccessToken()); + System.out.println("~~~~~~~获取所有的分组信息~~~~~~~" + JSONObject.toJSONString(allGroup)); + } + + /** + * 添加分组 + * @throws WexinReqException + */ + @Test + public void addGroup() throws WexinReqException { + GroupCreate group = JwGroupAPI.createGroup(this.getAccessToken(), "2024分组测试"); + System.out.println("~~~~~~~获取所有的分组信息~~~~~~~" + JSONObject.toJSONString(group)); + } + + /** + * 更新分组 + * @throws WexinReqException + */ + @Test + public void updateGroup() throws WexinReqException { + String s = JwGroupAPI.updateGroup(this.getAccessToken(), "100", "2024分组测试-更新"); + System.out.println("~~~~~~~更新分组信息~~~~~~~" + s); + } + + /** + * 删除分组 + * @throws WexinReqException + */ + @Test + public void deleteGroup() throws WexinReqException { + String s = JwGroupAPI.groupDelete(this.getAccessToken(), "100"); + System.out.println("~~~~~~~删除分组信息~~~~~~~" + s); + } + + + //============= 标签 =========================================== + /** + * 创建标签 + * + * @throws WexinReqException + */ + @Test + public void createTag() throws WexinReqException { + JSONObject object = JwTagAPI.createTag(this.getAccessToken(), "测试标签"); + System.out.println("~~~~~~~新增标签~~~~~~~" + object.toJSONString()); + } + + /** + * 获取标签 + * @throws WexinReqException + */ + @Test + public void getTag() { + List tags = JwTagAPI.getTags(this.getAccessToken()); + System.out.println("~~~~~~~标签列表~~~~~~~" + JSONObject.toJSONString(tags)); + } + + /** + * 获取标签 + * @throws WexinReqException + */ + @Test + public void updateTag(){ + JSONObject jsonObject = JwTagAPI.updateTag(this.getAccessToken(), 102, "20240911标签页"); + System.out.println("~~~~~~~更新标签~~~~~~~" + jsonObject.toJSONString()); + } + + /** + * 根据标签页的id获取用户 + */ + @Test + public void getTagUser() { + WxTagUser tagUser = JwTagAPI.getTagUser(this.getAccessToken(), 2,""); + System.out.println("~~~~~~~根据标签页的id获取用户~~~~~~~" + JSONObject.toJSONString(tagUser)); + } + + /** + * 批量设置标签 + */ + @Test + public void batchtagging() { + List list = new ArrayList<>(); + list.add("oKMOd6TU0cOqlQalYtGCPD5jWfY8"); + JSONObject batchtagging = JwTagAPI.batchtagging(this.getAccessToken(), list, 102); + System.out.println("~~~~~~~批量设置标签~~~~~~~" + JSONObject.toJSONString(batchtagging)); + } + + /** + * 批量取消标签 + */ + @Test + public void batchuntagging() { + List list = new ArrayList<>(); + list.add("oKMOd6TU0cOqlQalYtGCPD5jWfY8"); + JSONObject batchtagging = JwTagAPI.batchuntagging(this.getAccessToken(), list, 102); + System.out.println("~~~~~~~批量设置标签~~~~~~~" + JSONObject.toJSONString(batchtagging)); + } + + /** + * 获取用户身上的标签列表 + */ + @Test + public void getidlist() { + List list = JwTagAPI.getidlist(this.getAccessToken(), "oKMOd6TU0cOqlQalYtGCPD5jWfY8"); + System.out.println("~~~~~~~批量设置标签~~~~~~~" + JSONObject.toJSONString(list)); + } + + //============= 菜单接口 =========================================== + + /** + * 获取全部菜单 + * + * @throws WexinReqException + */ + @Test + public void getAllMenu() throws WexinReqException { + List allMenu = JwMenuAPI.getAllMenu(getAccessToken()); + log.info("~~~~~~~~~~~菜单列表~~~~~~~~~~~"+ JSONObject.toJSONString(allMenu)); + } + + /** + * 获取自定义菜单配置 + * + * @throws WexinReqException + */ + @Test + public void getAllMenuConfigure() throws WexinReqException { + CustomWeixinButtonConfig allMenuConfigure = JwMenuAPI.getAllMenuConfigure(getAccessToken()); + log.info("~~~~~~~~~~~自定义菜单配置~~~~~~~~~~~"+ JSONObject.toJSONString(allMenuConfigure)); + } + + /** + * 添加菜单 注意:此步骤会创建一个影响其他菜单 + * + * @throws WexinReqException + */ + @Test + public void createMenu() throws WexinReqException { + List list = new LinkedList<>(); + List subList = new LinkedList<>(); + WeixinButton subButton = new WeixinButton(); + subButton.setName("JimuReport积木报表"); + subButton.setType("view"); + subButton.setUrl("http://jimureport.com"); + subButton.setKey("jimureport"); + WeixinButton subButton1 = new WeixinButton(); + subButton1.setName("JEECG低代码平台"); + subButton1.setType("view"); + subButton1.setUrl("http://boot3.jeecg.com/"); + subButton1.setKey("JeecgBoot"); + subList.add(subButton); + subList.add(subButton1); + WeixinButton weixinButton2 = new WeixinButton(); + weixinButton2.setName("APP版本"); + weixinButton2.setType("view"); + weixinButton2.setUrl("https://jeecgos.oss-cn-beijing.aliyuncs.com/app/jeecg20240903.apk"); + weixinButton2.setKey("app"); + list.add(weixinButton2); + WeixinButton weixinButton1 = new WeixinButton(); + weixinButton1.setName("敲敲云官网"); + weixinButton1.setType("view"); + weixinButton1.setUrl("https://app.qiaoqiaoyun.com/"); + weixinButton1.setKey("qiaoqiaoyun"); + list.add(weixinButton1); + WeixinButton weixinButton = new WeixinButton(); + weixinButton.setName("更多功能"); + weixinButton.setSub_button(subList); + list.add(weixinButton); + String menu = JwMenuAPI.createMenu(getAccessToken(), list); + log.info("~~~~~~~~~~~添加菜单~~~~~~~~~~~" + menu); + } + + /** + * 创建个性化菜单 sex已被废弃 目前只能用标签 + */ + @Test + public void PersonalizedMenu(){ + WeixinMenuMatchrule matchrule = new WeixinMenuMatchrule(); + matchrule.setGroup_id("2"); + List testsUb = new ArrayList(); + WeixinButton w = new WeixinButton(); + w.setName("测试菜单"); + w.setType("click"); + w.setKey("V1001_TODAY_MUSIC"); + testsUb.add(w); + PersonalizedMenu menu = new PersonalizedMenu(); + menu.setButton(testsUb); + menu.setMatchrule(matchrule); + //个性化菜单创建 + String s = JwPersonalizedMenuAPI.createMenu(getAccessToken(),menu); + log.info("个性化菜单创建结果"+ JSONObject.toJSONString(s)); + //个性化菜单匹配 + List s3 = JwPersonalizedMenuAPI.testMatchrule(getAccessToken(),"oKMOd6TU0cOqlQalYtGCPD5jWfY8"); + log.info("个性化菜单匹配结果"+ JSONObject.toJSONString(s3)); + //删除个性化菜单 +// String deleteMenu = JwPersonalizedMenuAPI.deleteMenu(getAccessToken(), Integer.valueOf(s)); +// log.info("个性化菜单删除结果"+ deleteMenu); + } + public String getAccessToken() { + return new AccessToken(appid, appscret).getNewAccessToken(); + } + + public String getAccessTokenCx() { + return JdtBaseAPI.getAccessToken("??","??").getAccessToken(); + } + +} diff --git a/src/test/java/org/jeewx/api/prtest/WeChatAccountTest2.java b/src/test/java/org/jeewx/api/prtest/WeChatAccountTest2.java new file mode 100644 index 0000000..107510a --- /dev/null +++ b/src/test/java/org/jeewx/api/prtest/WeChatAccountTest2.java @@ -0,0 +1,386 @@ +package org.jeewx.api.prtest; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.jeecg.dingtalk.api.base.JdtBaseAPI; +import com.jeecg.dingtalk.api.user.vo.User; +import com.jeecg.qywx.api.menu.vo.Menu; +import org.jeewx.api.ai.JwAIApi; +import org.jeewx.api.ai.model.Voice; +import org.jeewx.api.core.common.AccessToken; +import org.jeewx.api.core.common.JSONHelper; +import org.jeewx.api.core.exception.WexinReqException; +import org.jeewx.api.core.req.model.WeixinReqParam; +import org.jeewx.api.core.req.model.menu.PersonalizedMenu; +import org.jeewx.api.core.req.model.menu.WeixinButton; +import org.jeewx.api.core.req.model.menu.WeixinMenuMatchrule; +import org.jeewx.api.core.req.model.menu.config.CustomWeixinButtonConfig; +import org.jeewx.api.core.req.model.message.IndustryTemplateMessageSend; +import org.jeewx.api.core.req.model.message.TemplateData; +import org.jeewx.api.core.req.model.message.TemplateMessage; +import org.jeewx.api.core.req.model.user.Group; +import org.jeewx.api.core.req.model.user.GroupCreate; +import org.jeewx.api.core.util.WeiXinReqUtil; +import org.jeewx.api.wxaccount.JwAccountAPI; +import org.jeewx.api.wxaccount.model.WxQrcode; +import org.jeewx.api.wxbase.wxmedia.JwMediaAPI; +import org.jeewx.api.wxbase.wxmedia.model.*; +import org.jeewx.api.wxbase.wxserviceip.JwServiceIpAPI; +import org.jeewx.api.wxmenu.JwMenuAPI; +import org.jeewx.api.wxmenu.JwPersonalizedMenuAPI; +import org.jeewx.api.wxsendmsg.JwSendMessageAPI; +import org.jeewx.api.wxsendmsg.JwTemplateMessageAPI; +import org.jeewx.api.wxsendmsg.model.WxArticle; +import org.jeewx.api.wxsendmsg.model.WxArticlesResponse; +import org.jeewx.api.wxsendmsg.model.WxMediaResponse; +import org.jeewx.api.wxuser.group.JwGroupAPI; +import org.jeewx.api.wxuser.tag.JwTagAPI; +import org.jeewx.api.wxuser.tag.model.WxTag; +import org.jeewx.api.wxuser.tag.model.WxTagUser; +import org.jeewx.api.wxuser.user.JwUserAPI; +import org.jeewx.api.wxuser.user.model.Wxuser; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +import java.util.*; + +/** +* @Description: 公众号测试 +* 测试用例 敲敲云公众号 +* +* @author: wangshuai +* @date: 2024/9/11 上午10:45 +*/ +public class WeChatAccountTest2 { + + private static final org.slf4j.Logger log = LoggerFactory.getLogger(WeChatAccountTest2.class); + private static String appid = "??"; + private static String appscret = "??"; + + //============= 发送模板消息 =========================================== + + /** + * 添加模板消息 (此接口已经废弃) + */ + @Test + public void addTemplateMessageSend(){ + try { + String s = JwTemplateMessageAPI.addTemplate(getAccessToken(), "4m3vrpiSA-CPyL9YqHw2jKDlZSX6Sz65SoMKvA9BV1s"); + log.info("~~~~~~~~~~添加模板消息~~~~~~~~~~"+s); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + /** + * 发送模板消息 + */ + @Test + public void sendTemplateMessageSend(){ + IndustryTemplateMessageSend industryTemplateMessageSend = new IndustryTemplateMessageSend(); + industryTemplateMessageSend.setAccess_token(getAccessToken()); + industryTemplateMessageSend.setTemplate_id("4m3vrpiSA-CPyL9YqHw2jKDlZSX6Sz65SoMKvA9BV1s"); + industryTemplateMessageSend.setTouser("oKMOd6TU0cOqlQalYtGCPD5jWfY8"); + industryTemplateMessageSend.setUrl("www.baidu.com"); + industryTemplateMessageSend.setTopcolor("#ffAADD"); + TemplateMessage data = new TemplateMessage(); + TemplateData first = new TemplateData(); + first.setColor("#173177"); + first.setValue("恭喜你购买成2323功!"); + TemplateData keynote1= new TemplateData(); + keynote1.setColor("#173177"); + keynote1.setValue("巧克22力"); + + TemplateData keynote2= new TemplateData(); + keynote2.setColor("39.8元"); + keynote2.setValue("恭喜你购买成功!"); + + TemplateData keynote3= new TemplateData(); + keynote3.setColor("#173177"); + keynote3.setValue("2014年9月16日"); + + TemplateData remark= new TemplateData(); + remark.setColor("#173177"); + remark.setValue("欢迎再次购买!"); + data.setFirst(first); + data.setKeynote1(keynote1); + data.setKeynote2(keynote2); + data.setKeynote3(keynote3); + data.setRemark(remark); + industryTemplateMessageSend.setData(data); + + try { + String s = JwTemplateMessageAPI.sendTemplateMsg(industryTemplateMessageSend); + log.info("~~~~~~~~~~发送模板消息~~~~~~~~~~"+s); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + @Test + public void getToken(){ + System.out.println(getAccessToken()); + } + + public String getAccessToken() { + return new AccessToken(appid, appscret).getNewAccessToken(); + } + + /** + * 创建二维码 + */ + @Test + public void createQrcode(){ + try { + WxQrcode qrScene = JwAccountAPI.createQrcode(getAccessToken(), "", "QR_SCENE", "1800"); + log.info("~~~~~~~~~~创建二维码~~~~~~~~~~" + qrScene.getUrl()); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + //=============================== 智能语音翻译 ========================== + @Test + public void tranVoiceText(){ + String file = "C:\\Users\\Administrator\\Desktop\\image\\1.mp3"; + String accessToken = getAccessToken(); + String voice_id = "ceshi1230981fr4"; + String lang = "zh_CN"; + Voice voice = new Voice(accessToken, "mp3",voice_id, lang, file); + String voiceContent = JwAIApi.translateVoice(voice); + log.info("~~~~~翻译语音~~~~~"+voiceContent); + } + + @Test + public void tranText(){ + String accessToken = getAccessToken(); + String lfrom = "zh_CN",lto = "en_US"; + String text = "我是中国人啊"; + String s = JwAIApi.translateText(accessToken, lfrom, lto, text); + log.info("~~~~~翻译文本~~~~~"+s); + } + + @Test + public void getServiceIpList(){ + try { + List serviceIpList = JwServiceIpAPI.getServiceIpList(getAccessToken()); + log.info("ip集合:::" + JSONObject.toJSONString(serviceIpList)); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + //=============================== 素材 ================================= + + /** + * 获取素材数量 + */ + @Test + public void getMediaCount(){ + try { + WxCountResponse mediaCount = JwMediaAPI.getMediaCount(getAccessToken()); + log.info("~~~~~~~~~~~~获取素材数量~~~~~~~~~~~"+JSONObject.toJSONString(mediaCount)); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + /** + * 上传临时素材 + */ + @Test + public void uploadMedia(){ + try { + WxMediaResponse wxMediaResponse = JwSendMessageAPI.uploadMediaFile(getAccessToken(), "C://Users/Administrator/Desktop/image/", "logo.png", "image"); + log.info("~~~~~~~~~~~~临时素材返回结果~~~~~~~~~~~"+JSONObject.toJSONString(wxMediaResponse)); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + /** + * 下载素材 + */ + @Test + public void downMedia(){ + try { + WxDwonload wxDwonload = JwMediaAPI.downMedia(getAccessToken(), "Vdok_lDhoEEqi49K73_ul98p8mvRf6ijiR6OLGRSQYlKaydksfKUJ4ILL439b43E", "C://Users/Administrator/Desktop/image/"); + log.info("~~~~~~~~~~~~临时素材下载结果~~~~~~~~~~~"+JSONObject.toJSONString(wxDwonload)); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + /** + * 获取着指定素材 + */ + @Test + public void getArticlesByMaterial(){ + try { + //图片 + //WxNewsArticle wxNewsArticle = JwMediaAPI.getArticlesByMaterialNews(getAccessToken(), "69fCQC8lI3S1aU3solmpeB5hnqXu3r5OlQCHeUiE-0j2dnG6jALBLhpQIT6g1FQk"); + //视频 + WxNewsArticle wxNewsArticle = JwMediaAPI.getArticlesByMaterialNews(getAccessToken(), "69fCQC8lI3S1aU3solmpeJ8UacWsBRjyuztecwynv7UnH8-K14g67LmuSvoirB2l"); + //语音 + //WxNewsArticle wxNewsArticle = JwMediaAPI.getArticlesByMaterialNews(getAccessToken(), "69fCQC8lI3S1aU3solmpeOF4BnQlr-B0pSjPxnooPpxuFfAMgB4HlzuIxQzm4t4x"); + log.info("~~~~~~~~~~~~获取指定素材~~~~~~~~~~~"+JSONObject.toJSONString(wxNewsArticle)); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + /** + * 获取素材列表 + */ + @Test + public void queryArticlesByMaterialNews(){ + try { + WxNews image = JwMediaAPI.queryArticlesByMaterialNews(getAccessToken(), "video", 0, 10); + log.info("~~~~~~~~~~~~获取素材列表~~~~~~~~~~~"+JSONObject.toJSONString(image)); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + /** + * 新增永久素材图片 + */ + @Test + public void uploadImages() throws WexinReqException { + List wxArticles = new ArrayList<>(); + WxArticle wxArticle = new WxArticle(); + wxArticle.setFileName("敲敲云"); + wxArticle.setFilePath("C:\\Users\\Administrator\\Desktop\\image\\jeecg.jpg"); + wxArticles.add(wxArticle); + WxArticlesResponse wxArticlesResponse = JwMediaAPI.uploadArticlesByMaterialNews(getAccessToken(), wxArticles,"image"); + log.info("~~~~~~~~~~~~上传永久素材图片~~~~~~~~~~~"+JSONObject.toJSONString(wxArticlesResponse)); + } + + /** + * 新增永久素材视频 + */ + @Test + public void uploadVideo() throws WexinReqException { + List wxArticles = new ArrayList<>(); + WxArticle wxArticle = new WxArticle(); + wxArticle.setTitle("测试"); + wxArticle.setFilePath("C:\\Users\\Administrator\\Desktop\\image\\1.mp4"); + wxArticle.setContent("测试"); + wxArticles.add(wxArticle); + WxArticlesResponse wxArticlesResponse = JwMediaAPI.uploadArticlesByMaterialNews(getAccessToken(), wxArticles,"video"); + log.info("~~~~~~~~~~~~上传永久素材视频~~~~~~~~~~~"+JSONObject.toJSONString(wxArticlesResponse)); + } + + /** + * 新增永久素材语音 + */ + @Test + public void uploadVoice() throws WexinReqException { + List wxArticles = new ArrayList<>(); + WxArticle wxArticle = new WxArticle(); + wxArticle.setTitle("测试"); + wxArticle.setFilePath("C:\\Users\\Administrator\\Desktop\\image\\1.mp3"); + wxArticle.setContent("测试"); + wxArticles.add(wxArticle); + WxArticlesResponse wxArticlesResponse = JwMediaAPI.uploadArticlesByMaterialNews(getAccessToken(), wxArticles,"voice"); + log.info("~~~~~~~~~~~~上传永久素材语音~~~~~~~~~~~"+JSONObject.toJSONString(wxArticlesResponse)); + } + + /** + * 删除永久素材 + */ + @Test + public void deleteArticlesByMaterialNews(){ + try { + log.info("~~~~~~~~~~~~删除永久素材~~~~~~~~~~~"); + JwMediaAPI.deleteArticlesByMaterialNews(getAccessToken(), "69fCQC8lI3S1aU3solmpeCVf32ajWHDG0E-5faBWG51V-_F8sl7IPacA1iiTuYMV"); + } catch (WexinReqException e) { + throw new RuntimeException(e); + } + } + + + + //=========================微信转换参数工具类================================= + @Test + public void WeiXinToParam(){ + WeixinReqParam reqParam = new WeixinReqParam(); + Map weixinReqParam = WeiXinReqUtil.getWeixinReqParam(reqParam); + log.info("~~~~~~~~~~转成map~~~~~~~~~~~~~~"+JSONObject.toJSONString(weixinReqParam)); + String str = WeiXinReqUtil.getWeixinParamJson(reqParam); + log.info("~~~~~~~~~~str~~~~~~~~~~~~~~"+str); + } + //=========================JSON 转换工具类================================= + @Test + public void toJson(){ + Map map = new HashMap<>(); + map.put("name","张三"); + log.info(JSONHelper.bean2json(map)); + List list = new ArrayList<>(); + list.add("list集合1"); + list.add("list集合2"); + log.info("list转json:"+JSONHelper.toJSONString(list)); + log.info("map转json:"+JSONHelper.toJSONString(map)); + log.info("map转JSONObject:"+JSONHelper.toJSONObject(map)); + List menuList = new ArrayList<>(); + User user = new User(); + user.setName("李四"); + menuList.add(user); + log.info("将对象转换为List>:"+JSONHelper.toList(menuList)); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name","张三"); + jsonArray.add(jsonObject); + log.info("将JSON对象转换为传入类型的对象:"+JSONHelper.toList(jsonArray,User.class)); + log.info("将对象转换为传入类型的List:"+JSONHelper.toList(menuList,User.class)); + log.info("将JSONObject转换为传入类型的List:"+JSONHelper.toBean(jsonObject,User.class)); + log.info("将map转换为传入类型的List:"+JSONHelper.toBean(map,User.class)); + + } + + /** + * 将JSON文本反序列化为主从关系的实体 + */ + @Test + public void jsonToEntity(){ + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name","张三"); + jsonObject.put("mobile","17610623333"); + jsonArray.add(jsonObject); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("name",jsonArray); + String user = jsonObject1.toJSONString(); + User name = JSONHelper.toBean(user, User.class, "name", User.class); + log.info(JSONHelper.toJSONString(name)); + JSONArray jsonArrayTwo = new JSONArray(); + JSONObject jsonObjectTwoa = new JSONObject(); + jsonObjectTwoa.put("name","张三"); + jsonArrayTwo.add(jsonObjectTwoa); + JSONArray jsonArrayTwo1 = new JSONArray(); + JSONObject jsonObjectTwoa1 = new JSONObject(); + jsonObjectTwoa1.put("mobile","17777777777"); + jsonArrayTwo1.add(jsonObjectTwoa1); + JSONObject jsonObjectTwo = new JSONObject(); + jsonObjectTwo.put("name",jsonArrayTwo); + jsonObjectTwo.put("mobile",jsonArrayTwo1); + String userTwo = jsonObjectTwo.toJSONString(); + User bean = JSONHelper.toBean(userTwo, User.class, "name", User.class, "mobile", User.class); + log.info(JSONHelper.toJSONString(bean)); + } + + @Test + public void jsonToEntity1(){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name","张三"); + jsonObject.put("mobile","17610623333"); + String user = jsonObject.toJSONString(); + HashMap detailClass = new HashMap<>(); + detailClass.put("user",User.class); + User bean = JSONHelper.toBean(user, User.class, detailClass); + log.info(JSONHelper.toJSONString(detailClass)); + log.info(JSONHelper.toJSONString(bean)); + } + public String getAccessTokenCx() { + return JdtBaseAPI.getAccessToken("??","??").getAccessToken(); + } + +} diff --git a/src/test/java/org/jeewx/api/prtest/WeChatAccountTest3.java b/src/test/java/org/jeewx/api/prtest/WeChatAccountTest3.java new file mode 100644 index 0000000..d738840 --- /dev/null +++ b/src/test/java/org/jeewx/api/prtest/WeChatAccountTest3.java @@ -0,0 +1,194 @@ +package org.jeewx.api.prtest; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.jeecg.dingtalk.api.base.JdtBaseAPI; +import com.jeecg.dingtalk.api.user.vo.User; +import org.jeewx.api.ai.JwAIApi; +import org.jeewx.api.ai.model.Voice; +import org.jeewx.api.core.common.AccessToken; +import org.jeewx.api.core.common.JSONHelper; +import org.jeewx.api.core.exception.WexinReqException; +import org.jeewx.api.core.req.model.WeixinReqParam; +import org.jeewx.api.core.req.model.interfacesummary.InterfaceSummaryParam; +import org.jeewx.api.core.req.model.message.IndustryTemplateMessageSend; +import org.jeewx.api.core.req.model.message.TemplateData; +import org.jeewx.api.core.req.model.message.TemplateMessage; +import org.jeewx.api.core.util.WeiXinReqUtil; +import org.jeewx.api.custservice.multicustservice.JwMultiCustomerAPI; +import org.jeewx.api.custservice.multicustservice.model.ChatRecord; +import org.jeewx.api.extend.CustomJsonConfig; +import org.jeewx.api.report.datastatistics.graphicanalysis.JwGraphicAnalysisAPI; +import org.jeewx.api.report.datastatistics.graphicanalysis.model.GraphicAnalysisRtnInfo; +import org.jeewx.api.report.datastatistics.interfacesummary.JwInterfaceSummary; +import org.jeewx.api.report.datastatistics.useranalysis.JwUserAnalysisAPI; +import org.jeewx.api.report.datastatistics.useranalysis.model.UserAnalysisRtnInfo; +import org.jeewx.api.report.interfacesummary.JwInterfaceSummaryAPI; +import org.jeewx.api.report.interfacesummary.model.InterfaceSummary; +import org.jeewx.api.report.interfacesummary.model.InterfaceSummaryHour; +import org.jeewx.api.wxaccount.JwAccountAPI; +import org.jeewx.api.wxaccount.model.WxQrcode; +import org.jeewx.api.wxbase.wxmedia.JwMediaAPI; +import org.jeewx.api.wxbase.wxmedia.model.WxCountResponse; +import org.jeewx.api.wxbase.wxmedia.model.WxDwonload; +import org.jeewx.api.wxbase.wxmedia.model.WxNews; +import org.jeewx.api.wxbase.wxmedia.model.WxNewsArticle; +import org.jeewx.api.wxbase.wxserviceip.JwServiceIpAPI; +import org.jeewx.api.wxsendmsg.JwSendMessageAPI; +import org.jeewx.api.wxsendmsg.JwTemplateMessageAPI; +import org.jeewx.api.wxsendmsg.model.WxArticle; +import org.jeewx.api.wxsendmsg.model.WxArticlesResponse; +import org.jeewx.api.wxsendmsg.model.WxMediaResponse; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** +* @Description: 公众号测试 +* 测试用例 敲敲云公众号 +* +* @author: wangshuai +* @date: 2024/9/11 上午10:45 +*/ +public class WeChatAccountTest3 { + + private static final org.slf4j.Logger log = LoggerFactory.getLogger(WeChatAccountTest3.class); + private static String appid = "??"; + private static String appscret = "??"; + private static String openId = "oKMOd6TU0cOqlQalYtGCPD5jWfY8"; + + + + @Test + public void getToken(){ + System.out.println(getAccessToken()); + } + + //============= 过滤不需要转换的属性 =========================================== + @Test + public void filterTr(){ + CustomJsonConfig customJsonConfig = new CustomJsonConfig(); + } + + //=================== 客服 ================== + @Test + public void kefu(){ + JwMultiCustomerAPI api = new JwMultiCustomerAPI(); + boolean a = api.isOnlineCustServiceAvailable(getAccessToken(), "kf2001@qiaoqiaoyun1"); + log.info("~~~~~判断指定客服是否在线可用~~~~~"+a); + String servcieMessage = api.getMultiCustServcieMessage(openId, appid); + log.info("~~~~~获取转发多客服的响应消息~~~~~"+servcieMessage); + String specCustServcie = api.getSpecCustServcie(getAccessToken(), openId, appid, "kf2001@qiaoqiaoyun1"); + log.info("~~~~~获取指定客服的响应消息~~~~~"+specCustServcie); + List custServiceRecordList = api.getCustServiceRecordList(getAccessToken(), openId, 1726134970276L, 1726134963000L, 10, 0); + log.info("~~~~~获取客服消息~~~~~"+JSONObject.toJSONString(custServiceRecordList)); + } + //====================获取报表信息==================================== + + /** + * 获取接口分析分时数据 + */ + @Test + public void getInterfaceSummaryHour(){ + JwInterfaceSummaryAPI s = new JwInterfaceSummaryAPI(); + InterfaceSummaryParam param=new InterfaceSummaryParam(); + param.setBegin_date("2024-09-11"); + param.setEnd_date("2024-09-11"); + //小时 + List list = s.getInterfaceSummaryHour(getAccessToken(),param); + log.info("~~~~~~~~~~获取接口分析分时数据~~~~~~~~~~~~"+JSONObject.toJSONString(list)); + //全天 + List interfaceSummary = s.getInterfaceSummary(getAccessToken(), param); + log.info("~~~~~~~~~~获取接口分析数据~~~~~~~~~~~~"+JSONObject.toJSONString(interfaceSummary)); + } + + + /** + * 用户分析数据接口 + */ + @Test + public void getUserCumulate() throws WexinReqException { + JwUserAnalysisAPI jua = new JwUserAnalysisAPI(); + List userAnalysisList = jua.getUserSummary(getAccessToken(), "2024-09-08", "2024-09-11"); + log.info("~~~~~~~~~~获取用户增减数据~~~~~~~~~~~~"+JSONObject.toJSONString(userAnalysisList)); + + List userCumulate = jua.getUserCumulate(getAccessToken(), "2024-09-08", "2024-09-11"); + log.info("~~~~~~~~~~获取累计用户数据~~~~~~~~~~~~"+JSONObject.toJSONString(userCumulate)); + } + + + /** + * 图文分析数据接口 + */ + @Test + public void getinterfacesummary() throws WexinReqException, UnsupportedEncodingException { + JwGraphicAnalysisAPI jua = new JwGraphicAnalysisAPI(); + List articleSummary = jua.getArticleSummary(getAccessToken(), "2024-09-10", "2024-09-10"); + log.info("~~~~~~~~~~获取图文群发每日数据~~~~~~~~~~~~"+JSONObject.toJSONString(articleSummary)); + } + + /** + * 获取文章阅读数量 + */ + @Test + public void getArticleTotal() throws WexinReqException, UnsupportedEncodingException { + JwGraphicAnalysisAPI jua = new JwGraphicAnalysisAPI(); + List articleSummary = jua.getArticleTotal(getAccessToken(), "2024-09-10", "2024-09-10"); + log.info("~~~~~~~~~~获取文章数量~~~~~~~~~~~~"+JSONObject.toJSONString(articleSummary)); + } + + /** + * 获取用户阅读 + */ + @Test + public void getUserRead() throws WexinReqException, UnsupportedEncodingException { + JwGraphicAnalysisAPI jua = new JwGraphicAnalysisAPI(); + List articleSummary = jua.getUserRead(getAccessToken(), "2024-09-10", "2024-09-10"); + log.info("~~~~~~~~~~获取用户阅读~~~~~~~~~~~~"+JSONObject.toJSONString(articleSummary)); + } + + /** + * 获取用户小时阅读 + */ + @Test + public void getUserReadHour() throws WexinReqException, UnsupportedEncodingException { + JwGraphicAnalysisAPI jua = new JwGraphicAnalysisAPI(); + List articleSummary = jua.getUserReadHour(getAccessToken(), "2024-09-10", "2024-09-10"); + log.info("~~~~~~~~~~获取用户小时~~~~~~~~~~~~"+JSONObject.toJSONString(articleSummary)); + } + + /** + * 获取用户分享 + */ + @Test + public void getUserShare() throws WexinReqException, UnsupportedEncodingException { + JwGraphicAnalysisAPI jua = new JwGraphicAnalysisAPI(); + List articleSummary = jua.getUserShare(getAccessToken(), "2024-09-10", "2024-09-10"); + log.info("~~~~~~~~~~获取用户分享~~~~~~~~~~~~"+JSONObject.toJSONString(articleSummary)); + } + + /** + * 获取用户小时分享 + */ + @Test + public void getUserShareHour() throws WexinReqException, UnsupportedEncodingException { + JwGraphicAnalysisAPI jua = new JwGraphicAnalysisAPI(); + List articleSummary = jua.getUserShareHour(getAccessToken(), "2024-09-10", "2024-09-10"); + log.info("~~~~~~~~~~获取用户小时分享~~~~~~~~~~~~"+JSONObject.toJSONString(articleSummary)); + } + + + public String getAccessToken() { + return new AccessToken(appid, appscret).getNewAccessToken(); + } + + public String getAccessTokenCx() { + return JdtBaseAPI.getAccessToken("??","??").getAccessToken(); + } + +}