mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
#252 原有图文素材管理接口增加留言管理所需两个参数:need_open_comment 和 only_fans_can_comment
This commit is contained in:
@@ -13,13 +13,11 @@ public abstract class MaterialVoiceAndImageDownloadRequestExecutor<H, P> impleme
|
||||
protected RequestHttp<H, P> requestHttp;
|
||||
protected File tmpDirFile;
|
||||
|
||||
|
||||
public MaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
|
||||
this.requestHttp = requestHttp;
|
||||
this.tmpDirFile = tmpDirFile;
|
||||
}
|
||||
|
||||
|
||||
public static RequestExecutor<InputStream, String> create(RequestHttp requestHttp, File tmpDirFile) {
|
||||
switch (requestHttp.getRequestType()) {
|
||||
case APACHE_HTTP:
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -23,6 +25,8 @@ import java.util.Map;
|
||||
* Created by ecoolper on 2017/5/5.
|
||||
*/
|
||||
public class ApacheMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<CloseableHttpClient, HttpHost> {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public ApacheMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
|
||||
super(requestHttp);
|
||||
}
|
||||
@@ -40,6 +44,7 @@ public class ApacheMaterialNewsInfoRequestExecutor extends MaterialNewsInfoReque
|
||||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
|
||||
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
this.logger.debug("响应原始数据:{}", responseContent);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -41,10 +42,10 @@ public class ApacheMaterialVoiceAndImageDownloadRequestExecutor extends Material
|
||||
params.put("media_id", materialId);
|
||||
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
|
||||
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
|
||||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
|
||||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
|
||||
// 下载媒体文件出错
|
||||
byte[] responseContent = IOUtils.toByteArray(inputStream);
|
||||
String responseContentString = new String(responseContent, "UTF-8");
|
||||
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
|
||||
if (responseContentString.length() < 100) {
|
||||
try {
|
||||
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
|
||||
|
||||
@@ -12,6 +12,8 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
|
||||
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -19,6 +21,7 @@ import java.io.IOException;
|
||||
* Created by ecoolper on 2017/5/5.
|
||||
*/
|
||||
public class JoddMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<HttpConnectionProvider, ProxyInfo> {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
public JoddMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
|
||||
super(requestHttp);
|
||||
}
|
||||
@@ -36,6 +39,7 @@ public class JoddMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequest
|
||||
response.charset(StringPool.UTF_8);
|
||||
|
||||
String responseContent = response.bodyText();
|
||||
this.logger.debug("响应原始数据:{}", responseContent);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Created by ecoolper on 2017/5/5.
|
||||
@@ -40,7 +41,7 @@ public class JoddMaterialVoiceAndImageDownloadRequestExecutor extends MaterialVo
|
||||
try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
|
||||
// 下载媒体文件出错
|
||||
byte[] responseContent = IOUtils.toByteArray(inputStream);
|
||||
String responseContentString = new String(responseContent, "UTF-8");
|
||||
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
|
||||
if (responseContentString.length() < 100) {
|
||||
try {
|
||||
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
|
||||
|
||||
@@ -8,6 +8,8 @@ import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
|
||||
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import okhttp3.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -15,6 +17,7 @@ import java.io.IOException;
|
||||
* Created by ecoolper on 2017/5/5.
|
||||
*/
|
||||
public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<ConnectionPool, OkHttpProxyInfo> {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
public OkhttpMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
|
||||
super(requestHttp);
|
||||
}
|
||||
@@ -44,6 +47,7 @@ public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoReque
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
String responseContent = response.body().string();
|
||||
this.logger.debug("响应原始数据:{}", responseContent);
|
||||
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Created by ecoolper on 2017/5/5.
|
||||
@@ -50,7 +51,7 @@ public class OkhttpMaterialVoiceAndImageDownloadRequestExecutor extends Material
|
||||
|
||||
// 下载媒体文件出错
|
||||
byte[] responseContent = IOUtils.toByteArray(inputStream);
|
||||
String responseContentString = new String(responseContent, "UTF-8");
|
||||
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
|
||||
if (responseContentString.length() < 100) {
|
||||
try {
|
||||
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
|
||||
|
||||
@@ -11,6 +11,7 @@ package me.chanjar.weixin.mp.util.json;
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@@ -37,6 +38,16 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa
|
||||
if (null != article.getUrl()) {
|
||||
articleJson.addProperty("url", article.getUrl());
|
||||
}
|
||||
|
||||
if (null != article.getNeedOpenComment()) {
|
||||
articleJson.addProperty("need_open_comment",
|
||||
BooleanUtils.toInteger(article.getNeedOpenComment(), 1, 0));
|
||||
}
|
||||
|
||||
if (null != article.getOnlyFansCanComment()) {
|
||||
articleJson.addProperty("only_fans_can_comment",
|
||||
BooleanUtils.toInteger(article.getOnlyFansCanComment(), 1, 0));
|
||||
}
|
||||
return articleJson;
|
||||
}
|
||||
|
||||
@@ -81,6 +92,16 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa
|
||||
if (url != null && !url.isJsonNull()) {
|
||||
article.setUrl(GsonHelper.getAsString(url));
|
||||
}
|
||||
|
||||
JsonElement needOpenComment = articleInfo.get("need_open_comment");
|
||||
if (needOpenComment != null && !needOpenComment.isJsonNull()) {
|
||||
article.setNeedOpenComment(GsonHelper.getAsBoolean(needOpenComment));
|
||||
}
|
||||
|
||||
JsonElement onlyFansCanComment = articleInfo.get("only_fans_can_comment");
|
||||
if (onlyFansCanComment != null && !onlyFansCanComment.isJsonNull()) {
|
||||
article.setOnlyFansCanComment(GsonHelper.getAsBoolean(onlyFansCanComment));
|
||||
}
|
||||
return article;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
|
||||
public class WxMpMaterialNewsGsonAdapter implements JsonSerializer<WxMpMaterialNews>, JsonDeserializer<WxMpMaterialNews> {
|
||||
|
||||
@@ -41,6 +43,17 @@ public class WxMpMaterialNewsGsonAdapter implements JsonSerializer<WxMpMaterialN
|
||||
wxMpMaterialNews.addArticle(article);
|
||||
}
|
||||
}
|
||||
|
||||
if (json.get("create_time") != null && !json.get("create_time").isJsonNull()) {
|
||||
Date createTime = new Date(GsonHelper.getAsLong(json.get("create_time")));
|
||||
wxMpMaterialNews.setCreatedTime(createTime);
|
||||
}
|
||||
|
||||
if (json.get("update_time") != null && !json.get("update_time").isJsonNull()) {
|
||||
Date updateTime = new Date(GsonHelper.getAsLong(json.get("update_time")));
|
||||
wxMpMaterialNews.setUpdatedTime(updateTime);
|
||||
}
|
||||
|
||||
return wxMpMaterialNews;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user