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..7ec6a79 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开放接口 * @@ -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/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..2455bd8 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; + /** * 客户服务- 多客户 * 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..1333ef0 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,17 @@ 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.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; /** * 微信--token信息 @@ -76,7 +64,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; } @@ -97,7 +85,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; } @@ -150,10 +138,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 +175,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 { @@ -218,14 +206,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); } } @@ -242,14 +230,14 @@ public static WxArticlesRespponseByMaterial getArticlesByMaterial(String accesst * @throws WexinReqException */ 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")); } @@ -267,10 +255,10 @@ public static void updateArticlesByMaterial(String accesstoken,WxUpdateArticle w 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")); } @@ -295,11 +283,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; @@ -340,7 +328,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()); } @@ -432,9 +420,9 @@ public static WxArticlesResponse uploadArticlesByMaterialNews(String accesstoken String requestUrl = material_add_news_url.replace("ACCESS_TOKEN", accesstoken); 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()); - if (result.has("errcode")) { + if (result.containsKey("errcode")) { logger.error("新增永久图文素材失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException(result.getString("errcode")); } else { @@ -458,9 +446,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{ @@ -485,13 +473,13 @@ public static List getArticlesByMaterialNews(String accesstoken,S JSONObject obj = new JSONObject(); obj.put("media_id", mediaId); 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(result.getString("errcode")); } else { logger.info("====获取永久素材成功====result:"+result.toString()); JSONArray newsItemJsonArr = result.getJSONArray("news_item"); - wxArticleList = JSONArray.toList(newsItemJsonArr, WxNewsArticle.class); + wxArticleList = newsItemJsonArr.toJavaList(WxNewsArticle.class); } } return wxArticleList; @@ -514,7 +502,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,12 +513,12 @@ 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); + JSONObject newsItemJson = JSONObject.parseObject(JSON.toJSONString(newsItemObj)); JSONArray newsItemJsonArr = newsItemJson.getJSONArray("news_item"); - List wxArticleList = JSONArray.toList(newsItemJsonArr, WxNewsArticle.class); + List wxArticleList = newsItemJsonArr.toJavaList(WxNewsArticle.class); wxItem.setContents(wxArticleList); wxItem.setMedia_id(mediaId); if(itemJson.containsKey("name")){ @@ -555,12 +543,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{ 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..d936a07 100644 --- a/src/main/java/org/jeewx/api/wxmenu/JwPersonalizedMenuAPI.java +++ b/src/main/java/org/jeewx/api/wxmenu/JwPersonalizedMenuAPI.java @@ -1,17 +1,16 @@ 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.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 +49,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){ @@ -91,7 +90,7 @@ public static List testMatchrule(String accessToken,String 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); + List btns = (List)JSONObject.toJavaObject(result, WeixinButton.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(JSON.toJSONString(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);