Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用fastjson替换jsonlib #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,18 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>

<!-- json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson-lib.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>

<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>${json-lib.version}</version>
<classifier>jdk15</classifier>
</dependency>
<!-- slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/com/jeecg/qywx/api/conversation/ConversationAPI.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 7 additions & 16 deletions src/main/java/com/jeecg/qywx/api/core/util/WXUpload.java
Original file line number Diff line number Diff line change
@@ -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";
/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -97,8 +97,8 @@ public static List<Department> getAllDepartment(String accessToken) {
int errcode = jsonObject.getIntValue("errcode");
String errmsg = jsonObject.getString("errmsg");
String departmentjson = jsonObject.getString("department");
Gson gson = new Gson();
List<Department> ps = gson.fromJson(departmentjson, new TypeToken<List<Department>>(){}.getType());

List<Department> ps = JSON.parseArray(departmentjson, Department.class);
return ps;
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jeecg/weibo/api/WeiboAccountApi.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jeecg/weibo/api/WeiboSendApi.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jeecg/weibo/dto/WeiboSendDto.java
Original file line number Diff line number Diff line change
@@ -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;

/**
* 发布微博
Expand All @@ -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;
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/com/jeecg/weibo/util/WeiboCommentsUtil.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
Expand All @@ -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();
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/jeecg/weibo/util/WeiboFollowersUtil.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/jeecg/weibo/util/WeiboSendUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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();
Expand Down
Loading