mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
实现永久素材相关接口
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package me.chanjar.weixin.mp.util.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
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 java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialDeleteRequestExecutor implements RequestExecutor<Boolean, String> {
|
||||
|
||||
|
||||
public MaterialDeleteRequestExecutor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Boolean execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
if (httpProxy != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||
httpPost.setConfig(config);
|
||||
}
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("media_id", materialId);
|
||||
httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
|
||||
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.chanjar.weixin.mp.util.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
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 java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialNewsInfoRequestExecutor implements RequestExecutor<WxMpMaterialNews, String> {
|
||||
|
||||
public MaterialNewsInfoRequestExecutor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WxMpMaterialNews execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
if (httpProxy != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||
httpPost.setConfig(config);
|
||||
}
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("media_id", materialId);
|
||||
httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
|
||||
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
} else {
|
||||
return WxMpGsonBuilder.create().fromJson(responseContent, WxMpMaterialNews.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package me.chanjar.weixin.mp.util.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterial;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.entity.mime.content.InputStreamBody;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> {
|
||||
|
||||
public WxMpMaterialUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, WxMpMaterial material) throws WxErrorException, ClientProtocolException, IOException {
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
if (httpProxy != null) {
|
||||
RequestConfig response = RequestConfig.custom().setProxy(httpProxy).build();
|
||||
httpPost.setConfig(response);
|
||||
}
|
||||
|
||||
if (material != null) {
|
||||
File file = material.getFile();
|
||||
if (file == null || !file.exists()) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
|
||||
multipartEntityBuilder.addPart("media", new InputStreamBody(bufferedInputStream, material.getName()));
|
||||
Map<String, String> form = material.getForm();
|
||||
if (material.getForm() != null) {
|
||||
multipartEntityBuilder.addTextBody("description", new Gson().toJson(form));
|
||||
}
|
||||
httpPost.setEntity(multipartEntityBuilder.build());
|
||||
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
} else {
|
||||
return WxMpMaterialUploadResult.fromJson(responseContent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package me.chanjar.weixin.mp.util.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
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 java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialVideoInfoRequestExecutor implements RequestExecutor<WxMpMaterialVideoInfoResult, String> {
|
||||
|
||||
public MaterialVideoInfoRequestExecutor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WxMpMaterialVideoInfoResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
if (httpProxy != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||
httpPost.setConfig(config);
|
||||
}
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("media_id", materialId);
|
||||
httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
|
||||
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
} else {
|
||||
return WxMpMaterialVideoInfoResult.fromJson(responseContent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package me.chanjar.weixin.mp.util.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.InputStreamResponseHandler;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
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 java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExecutor<InputStream, String> {
|
||||
|
||||
private File tmpDirFile;
|
||||
|
||||
public MaterialVoiceAndImageDownloadRequestExecutor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MaterialVoiceAndImageDownloadRequestExecutor(File tmpDirFile) {
|
||||
super();
|
||||
this.tmpDirFile = tmpDirFile;
|
||||
}
|
||||
|
||||
public InputStream execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
if (httpProxy != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||
httpPost.setConfig(config);
|
||||
}
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("media_id", materialId);
|
||||
httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
|
||||
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||
// 下载媒体文件出错
|
||||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
|
||||
byte[] responseContent = IOUtils.toByteArray(inputStream);
|
||||
String responseContentString = new String(responseContent, "UTF-8");
|
||||
if (responseContentString.length() < 100) {
|
||||
try {
|
||||
WxError wxError = new Gson().fromJson(responseContentString, WxError.class);
|
||||
if (wxError.getErrorCode() != 0) {
|
||||
throw new WxErrorException(wxError);
|
||||
}
|
||||
} catch (com.google.gson.JsonSyntaxException ex) {
|
||||
return new ByteArrayInputStream(responseContent);
|
||||
}
|
||||
}
|
||||
return new ByteArrayInputStream(responseContent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import me.chanjar.weixin.mp.bean.result.*;
|
||||
public class WxMpGsonBuilder {
|
||||
|
||||
public static final GsonBuilder INSTANCE = new GsonBuilder();
|
||||
|
||||
|
||||
static {
|
||||
INSTANCE.disableHtmlEscaping();
|
||||
INSTANCE.registerTypeAdapter(WxMpCustomMessage.class, new WxMpCustomMessageGsonAdapter());
|
||||
@@ -27,10 +27,21 @@ public class WxMpGsonBuilder {
|
||||
INSTANCE.registerTypeAdapter(WxMpOAuth2AccessToken.class, new WxMpOAuth2AccessTokenAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpUserSummary.class, new WxMpUserSummaryGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpUserCumulate.class, new WxMpUserCumulateGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialUploadResult.class, new WxMpMaterialUploadResultAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialVideoInfoResult.class, new WxMpMaterialVideoInfoResultAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMassNews.WxMpMassNewsArticle.class, new WxMpMassNewsArticleGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialArticleUpdate.class, new WxMpMaterialArticleUpdateGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialCountResult.class, new WxMpMaterialCountResultAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialNews.class, new WxMpMaterialNewsGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialNews.WxMpMaterialNewsArticle.class, new WxMpMaterialNewsArticleGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialNewsBatchGetResult.class, new WxMpMaterialNewsBatchGetGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class, new WxMpMaterialNewsBatchGetGsonItemAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialFileBatchGetResult.class, new WxMpMaterialFileBatchGetGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem.class, new WxMpMaterialFileBatchGetGsonItemAdapter());
|
||||
}
|
||||
|
||||
|
||||
public static Gson create() {
|
||||
return INSTANCE.create();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.WxMpMassNews;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class WxMpMassNewsArticleGsonAdapter implements JsonSerializer<WxMpMassNews.WxMpMassNewsArticle>, JsonDeserializer<WxMpMassNews.WxMpMassNewsArticle> {
|
||||
|
||||
public JsonElement serialize(WxMpMassNews.WxMpMassNewsArticle article, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject articleJson = new JsonObject();
|
||||
|
||||
articleJson.addProperty("thumb_media_id", article.getThumbMediaId());
|
||||
articleJson.addProperty("title", article.getTitle());
|
||||
articleJson.addProperty("content", article.getContent());
|
||||
if (null != article.getAuthor()) {
|
||||
articleJson.addProperty("author", article.getAuthor());
|
||||
}
|
||||
if (null != article.getContentSourceUrl()) {
|
||||
articleJson.addProperty("content_source_url", article.getContentSourceUrl());
|
||||
}
|
||||
if (null != article.getDigest()) {
|
||||
articleJson.addProperty("digest", article.getDigest());
|
||||
}
|
||||
articleJson.addProperty("show_cover_pic", article.isShowCoverPic() ? "1" : "0");
|
||||
return articleJson;
|
||||
}
|
||||
|
||||
public WxMpMassNews.WxMpMassNewsArticle deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
JsonObject articleInfo = jsonElement.getAsJsonObject();
|
||||
WxMpMassNews.WxMpMassNewsArticle article = new WxMpMassNews.WxMpMassNewsArticle();
|
||||
|
||||
JsonElement title = articleInfo.get("title");
|
||||
if (title != null && !title.isJsonNull()) {
|
||||
article.setTitle(GsonHelper.getAsString(title));
|
||||
}
|
||||
JsonElement content = articleInfo.get("content");
|
||||
if (content != null && !content.isJsonNull()) {
|
||||
article.setContent(GsonHelper.getAsString(content));
|
||||
}
|
||||
JsonElement contentSourceUrl = articleInfo.get("content_source_url");
|
||||
if (contentSourceUrl != null && !contentSourceUrl.isJsonNull()) {
|
||||
article.setContentSourceUrl(GsonHelper.getAsString(contentSourceUrl));
|
||||
}
|
||||
JsonElement author = articleInfo.get("author");
|
||||
if (author != null && !author.isJsonNull()) {
|
||||
article.setAuthor(GsonHelper.getAsString(author));
|
||||
}
|
||||
JsonElement digest = articleInfo.get("digest");
|
||||
if (digest != null && !digest.isJsonNull()) {
|
||||
article.setDigest(GsonHelper.getAsString(digest));
|
||||
}
|
||||
JsonElement thumbMediaId = articleInfo.get("thumb_media_id");
|
||||
if (thumbMediaId != null && !thumbMediaId.isJsonNull()) {
|
||||
article.setThumbMediaId(GsonHelper.getAsString(thumbMediaId));
|
||||
}
|
||||
JsonElement showCoverPic = articleInfo.get("show_cover_pic");
|
||||
if (showCoverPic != null && !showCoverPic.isJsonNull()) {
|
||||
article.setShowCoverPic(GsonHelper.getAsBoolean(showCoverPic));
|
||||
}
|
||||
return article;
|
||||
}
|
||||
}
|
||||
@@ -13,33 +13,32 @@ import me.chanjar.weixin.mp.bean.WxMpMassNews;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class WxMpMassNewsGsonAdapter implements JsonSerializer<WxMpMassNews> {
|
||||
public class WxMpMassNewsGsonAdapter implements JsonSerializer<WxMpMassNews>, JsonDeserializer<WxMpMassNews> {
|
||||
|
||||
public JsonElement serialize(WxMpMassNews message, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject newsJson = new JsonObject();
|
||||
|
||||
|
||||
JsonArray articleJsonArray = new JsonArray();
|
||||
for (WxMpMassNews.WxMpMassNewsArticle article : message.getArticles()) {
|
||||
JsonObject articleJson = new JsonObject();
|
||||
articleJson.addProperty("thumb_media_id", article.getThumbMediaId());
|
||||
articleJson.addProperty("title", article.getTitle());
|
||||
articleJson.addProperty("content", article.getContent());
|
||||
|
||||
if (null != article.getAuthor()) {
|
||||
articleJson.addProperty("author", article.getAuthor());
|
||||
}
|
||||
if (null != article.getContentSourceUrl()) {
|
||||
articleJson.addProperty("content_source_url", article.getContentSourceUrl());
|
||||
}
|
||||
if (null != article.getDigest()) {
|
||||
articleJson.addProperty("digest", article.getDigest());
|
||||
}
|
||||
articleJson.addProperty("show_cover_pic", article.isShowCoverPic() ? "1" : "0");
|
||||
JsonObject articleJson = WxMpGsonBuilder.create().toJsonTree(article, WxMpMassNews.WxMpMassNewsArticle.class).getAsJsonObject();
|
||||
articleJsonArray.add(articleJson);
|
||||
}
|
||||
newsJson.add("articles", articleJsonArray);
|
||||
|
||||
|
||||
return newsJson;
|
||||
}
|
||||
|
||||
public WxMpMassNews deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpMassNews wxMpMassNews = new WxMpMassNews();
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
if (json.get("media_id") != null && !json.get("media_id").isJsonNull()) {
|
||||
JsonArray articles = json.getAsJsonArray("articles");
|
||||
for (JsonElement article1 : articles) {
|
||||
JsonObject articleInfo = article1.getAsJsonObject();
|
||||
WxMpMassNews.WxMpMassNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMassNews.WxMpMassNewsArticle.class);
|
||||
wxMpMassNews.addArticle(article);
|
||||
}
|
||||
}
|
||||
return wxMpMassNews;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class WxMpMaterialArticleUpdateGsonAdapter implements JsonSerializer<WxMpMaterialArticleUpdate> {
|
||||
|
||||
public JsonElement serialize(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject articleUpdateJson = new JsonObject();
|
||||
articleUpdateJson.addProperty("media_id", wxMpMaterialArticleUpdate.getMediaId());
|
||||
articleUpdateJson.addProperty("index", wxMpMaterialArticleUpdate.getIndex());
|
||||
articleUpdateJson.add("articles", WxMpGsonBuilder.create().toJsonTree(wxMpMaterialArticleUpdate.getArticles(), WxMpMaterialNews.WxMpMaterialNewsArticle.class));
|
||||
return articleUpdateJson;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.result.WxMpMaterialCountResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author codepiano
|
||||
*/
|
||||
public class WxMpMaterialCountResultAdapter implements JsonDeserializer<WxMpMaterialCountResult> {
|
||||
|
||||
public WxMpMaterialCountResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxMpMaterialCountResult countResult = new WxMpMaterialCountResult();
|
||||
JsonObject materialCountResultJsonObject = json.getAsJsonObject();
|
||||
|
||||
if (materialCountResultJsonObject.get("voice_count") != null && !materialCountResultJsonObject.get("voice_count").isJsonNull()) {
|
||||
countResult.setVoiceCount(GsonHelper.getAsInteger(materialCountResultJsonObject.get("voice_count")));
|
||||
}
|
||||
if (materialCountResultJsonObject.get("video_count") != null && !materialCountResultJsonObject.get("video_count").isJsonNull()) {
|
||||
countResult.setVideoCount(GsonHelper.getAsInteger(materialCountResultJsonObject.get("video_count")));
|
||||
}
|
||||
if (materialCountResultJsonObject.get("image_count") != null && !materialCountResultJsonObject.get("image_count").isJsonNull()) {
|
||||
countResult.setImageCount(GsonHelper.getAsInteger(materialCountResultJsonObject.get("image_count")));
|
||||
}
|
||||
if (materialCountResultJsonObject.get("news_count") != null && !materialCountResultJsonObject.get("news_count").isJsonNull()) {
|
||||
countResult.setNewsCount(GsonHelper.getAsInteger(materialCountResultJsonObject.get("news_count")));
|
||||
}
|
||||
return countResult;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.result.WxMpMaterialFileBatchGetResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WxMpMaterialFileBatchGetGsonAdapter implements JsonDeserializer<WxMpMaterialFileBatchGetResult> {
|
||||
|
||||
public WxMpMaterialFileBatchGetResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpMaterialFileBatchGetResult wxMpMaterialFileBatchGetResult = new WxMpMaterialFileBatchGetResult();
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
if (json.get("total_count") != null && !json.get("total_count").isJsonNull()) {
|
||||
wxMpMaterialFileBatchGetResult.setTotalCount(GsonHelper.getAsInteger(json.get("total_count")));
|
||||
}
|
||||
if (json.get("item_count") != null && !json.get("item_count").isJsonNull()) {
|
||||
wxMpMaterialFileBatchGetResult.setItemCount(GsonHelper.getAsInteger(json.get("item_count")));
|
||||
}
|
||||
if (json.get("item") != null && !json.get("item").isJsonNull()) {
|
||||
JsonArray item = json.getAsJsonArray("item");
|
||||
List<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem> items = new ArrayList<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem>();
|
||||
for (JsonElement anItem : item) {
|
||||
JsonObject articleInfo = anItem.getAsJsonObject();
|
||||
items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem.class));
|
||||
}
|
||||
wxMpMaterialFileBatchGetResult.setItems(items);
|
||||
}
|
||||
return wxMpMaterialFileBatchGetResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.result.WxMpMaterialFileBatchGetResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
|
||||
public class WxMpMaterialFileBatchGetGsonItemAdapter implements JsonDeserializer<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem> {
|
||||
|
||||
public WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem wxMaterialFileBatchGetNewsItem = new WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem();
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
if (json.get("media_id") != null && !json.get("media_id").isJsonNull()) {
|
||||
wxMaterialFileBatchGetNewsItem.setMediaId(GsonHelper.getAsString(json.get("media_id")));
|
||||
}
|
||||
if (json.get("update_time") != null && !json.get("update_time").isJsonNull()) {
|
||||
wxMaterialFileBatchGetNewsItem.setUpdateTime(new Date(1000 * GsonHelper.getAsLong(json.get("update_time"))));
|
||||
}
|
||||
if (json.get("name") != null && !json.get("name").isJsonNull()) {
|
||||
wxMaterialFileBatchGetNewsItem.setName(GsonHelper.getAsString(json.get("name")));
|
||||
}
|
||||
if (json.get("url") != null && !json.get("url").isJsonNull()) {
|
||||
wxMaterialFileBatchGetNewsItem.setUrl(GsonHelper.getAsString(json.get("url")));
|
||||
}
|
||||
return wxMaterialFileBatchGetNewsItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.WxMpMaterialNews;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMaterialNews.WxMpMaterialNewsArticle>, JsonDeserializer<WxMpMaterialNews.WxMpMaterialNewsArticle> {
|
||||
|
||||
public JsonElement serialize(WxMpMaterialNews.WxMpMaterialNewsArticle article, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject articleJson = new JsonObject();
|
||||
|
||||
articleJson.addProperty("thumb_media_id", article.getThumbMediaId());
|
||||
articleJson.addProperty("title", article.getTitle());
|
||||
articleJson.addProperty("content", article.getContent());
|
||||
if (null != article.getAuthor()) {
|
||||
articleJson.addProperty("author", article.getAuthor());
|
||||
}
|
||||
if (null != article.getContentSourceUrl()) {
|
||||
articleJson.addProperty("content_source_url", article.getContentSourceUrl());
|
||||
}
|
||||
if (null != article.getDigest()) {
|
||||
articleJson.addProperty("digest", article.getDigest());
|
||||
}
|
||||
articleJson.addProperty("show_cover_pic", article.isShowCoverPic() ? "1" : "0");
|
||||
return articleJson;
|
||||
}
|
||||
|
||||
public WxMpMaterialNews.WxMpMaterialNewsArticle deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
JsonObject articleInfo = jsonElement.getAsJsonObject();
|
||||
WxMpMaterialNews.WxMpMaterialNewsArticle article = new WxMpMaterialNews.WxMpMaterialNewsArticle();
|
||||
|
||||
JsonElement title = articleInfo.get("title");
|
||||
if (title != null && !title.isJsonNull()) {
|
||||
article.setTitle(GsonHelper.getAsString(title));
|
||||
}
|
||||
JsonElement content = articleInfo.get("content");
|
||||
if (content != null && !content.isJsonNull()) {
|
||||
article.setContent(GsonHelper.getAsString(content));
|
||||
}
|
||||
JsonElement contentSourceUrl = articleInfo.get("content_source_url");
|
||||
if (contentSourceUrl != null && !contentSourceUrl.isJsonNull()) {
|
||||
article.setContentSourceUrl(GsonHelper.getAsString(contentSourceUrl));
|
||||
}
|
||||
JsonElement author = articleInfo.get("author");
|
||||
if (author != null && !author.isJsonNull()) {
|
||||
article.setAuthor(GsonHelper.getAsString(author));
|
||||
}
|
||||
JsonElement digest = articleInfo.get("digest");
|
||||
if (digest != null && !digest.isJsonNull()) {
|
||||
article.setDigest(GsonHelper.getAsString(digest));
|
||||
}
|
||||
JsonElement thumbMediaId = articleInfo.get("thumb_media_id");
|
||||
if (thumbMediaId != null && !thumbMediaId.isJsonNull()) {
|
||||
article.setThumbMediaId(GsonHelper.getAsString(thumbMediaId));
|
||||
}
|
||||
JsonElement showCoverPic = articleInfo.get("show_cover_pic");
|
||||
if (showCoverPic != null && !showCoverPic.isJsonNull()) {
|
||||
article.setShowCoverPic(GsonHelper.getAsBoolean(showCoverPic));
|
||||
}
|
||||
return article;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.result.WxMpMaterialNewsBatchGetResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WxMpMaterialNewsBatchGetGsonAdapter implements JsonDeserializer<WxMpMaterialNewsBatchGetResult> {
|
||||
|
||||
public WxMpMaterialNewsBatchGetResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = new WxMpMaterialNewsBatchGetResult();
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
if (json.get("total_count") != null && !json.get("total_count").isJsonNull()) {
|
||||
wxMpMaterialNewsBatchGetResult.setTotalCount(GsonHelper.getAsInteger(json.get("total_count")));
|
||||
}
|
||||
if (json.get("item_count") != null && !json.get("item_count").isJsonNull()) {
|
||||
wxMpMaterialNewsBatchGetResult.setItemCount(GsonHelper.getAsInteger(json.get("item_count")));
|
||||
}
|
||||
if (json.get("item") != null && !json.get("item").isJsonNull()) {
|
||||
JsonArray item = json.getAsJsonArray("item");
|
||||
List<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem> items = new ArrayList<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem>();
|
||||
for (JsonElement anItem : item) {
|
||||
JsonObject articleInfo = anItem.getAsJsonObject();
|
||||
items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class));
|
||||
}
|
||||
wxMpMaterialNewsBatchGetResult.setItems(items);
|
||||
}
|
||||
return wxMpMaterialNewsBatchGetResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.WxMpMaterialNews;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMaterialNewsBatchGetResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
|
||||
public class WxMpMaterialNewsBatchGetGsonItemAdapter implements JsonDeserializer<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem> {
|
||||
|
||||
public WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem wxMaterialNewsBatchGetNewsItem = new WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem();
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
if (json.get("media_id") != null && !json.get("media_id").isJsonNull()) {
|
||||
wxMaterialNewsBatchGetNewsItem.setMediaId(GsonHelper.getAsString(json.get("media_id")));
|
||||
}
|
||||
if (json.get("update_time") != null && !json.get("update_time").isJsonNull()) {
|
||||
wxMaterialNewsBatchGetNewsItem.setUpdateTime(new Date(1000 * GsonHelper.getAsLong(json.get("update_time"))));
|
||||
}
|
||||
if (json.get("content") != null && !json.get("content").isJsonNull()) {
|
||||
JsonObject newsItem = json.getAsJsonObject("content");
|
||||
wxMaterialNewsBatchGetNewsItem.setContent(WxMpGsonBuilder.create().fromJson(newsItem, WxMpMaterialNews.class));
|
||||
}
|
||||
return wxMaterialNewsBatchGetNewsItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class WxMpMaterialNewsGsonAdapter implements JsonSerializer<WxMpMaterialNews>, JsonDeserializer<WxMpMaterialNews> {
|
||||
|
||||
public JsonElement serialize(WxMpMaterialNews wxMpMaterialNews, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject newsJson = new JsonObject();
|
||||
|
||||
JsonArray articleJsonArray = new JsonArray();
|
||||
for (WxMpMaterialNews.WxMpMaterialNewsArticle article : wxMpMaterialNews.getArticles()) {
|
||||
JsonObject articleJson = WxMpGsonBuilder.create().toJsonTree(article, WxMpMaterialNews.WxMpMaterialNewsArticle.class).getAsJsonObject();
|
||||
articleJsonArray.add(articleJson);
|
||||
}
|
||||
newsJson.add("articles", articleJsonArray);
|
||||
|
||||
return newsJson;
|
||||
}
|
||||
|
||||
public WxMpMaterialNews deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpMaterialNews wxMpMaterialNews = new WxMpMaterialNews();
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
if (json.get("news_item") != null && !json.get("news_item").isJsonNull()) {
|
||||
JsonArray articles = json.getAsJsonArray("news_item");
|
||||
for (JsonElement article1 : articles) {
|
||||
JsonObject articleInfo = article1.getAsJsonObject();
|
||||
WxMpMaterialNews.WxMpMaterialNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNews.WxMpMaterialNewsArticle.class);
|
||||
wxMpMaterialNews.addArticle(article);
|
||||
}
|
||||
}
|
||||
return wxMpMaterialNews;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
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.result.WxMpMaterialUploadResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author codepiano
|
||||
*/
|
||||
public class WxMpMaterialUploadResultAdapter implements JsonDeserializer<WxMpMaterialUploadResult> {
|
||||
|
||||
public WxMpMaterialUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxMpMaterialUploadResult uploadResult = new WxMpMaterialUploadResult();
|
||||
JsonObject uploadResultJsonObject = json.getAsJsonObject();
|
||||
|
||||
if (uploadResultJsonObject.get("url") != null && !uploadResultJsonObject.get("url").isJsonNull()) {
|
||||
uploadResult.setUrl(GsonHelper.getAsString(uploadResultJsonObject.get("url")));
|
||||
}
|
||||
if (uploadResultJsonObject.get("media_id") != null && !uploadResultJsonObject.get("media_id").isJsonNull()) {
|
||||
uploadResult.setMediaId(GsonHelper.getAsString(uploadResultJsonObject.get("media_id")));
|
||||
}
|
||||
return uploadResult;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
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.result.WxMpMaterialVideoInfoResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author codepiano
|
||||
*/
|
||||
public class WxMpMaterialVideoInfoResultAdapter implements JsonDeserializer<WxMpMaterialVideoInfoResult> {
|
||||
|
||||
public WxMpMaterialVideoInfoResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxMpMaterialVideoInfoResult uploadResult = new WxMpMaterialVideoInfoResult();
|
||||
JsonObject uploadResultJsonObject = json.getAsJsonObject();
|
||||
|
||||
if (uploadResultJsonObject.get("title") != null && !uploadResultJsonObject.get("title").isJsonNull()) {
|
||||
uploadResult.setTitle(GsonHelper.getAsString(uploadResultJsonObject.get("title")));
|
||||
}
|
||||
if (uploadResultJsonObject.get("description") != null && !uploadResultJsonObject.get("description").isJsonNull()) {
|
||||
uploadResult.setDescription(GsonHelper.getAsString(uploadResultJsonObject.get("description")));
|
||||
}
|
||||
if (uploadResultJsonObject.get("down_url") != null && !uploadResultJsonObject.get("down_url").isJsonNull()) {
|
||||
uploadResult.setDownUrl(GsonHelper.getAsString(uploadResultJsonObject.get("down_url")));
|
||||
}
|
||||
return uploadResult;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user