, JsonSeri
if (user.getStatus() != null) {
o.addProperty("status", user.getStatus());
}
+ if (user.getEnable() != null) {
+ o.addProperty("enable", user.getEnable());
+ }
if (user.getExtAttrs().size() > 0) {
JsonArray attrsJsonArray = new JsonArray();
for (WxCpUser.Attr attr : user.getExtAttrs()) {
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index 81e3b941..48999b06 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -6,7 +6,7 @@
me.chanjar
weixin-java-parent
- 1.2.0
+ 1.3.0
weixin-java-mp
WeiXin Java Tools - MP
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
index 45de6f8c..5c15e89b 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
@@ -47,9 +47,9 @@ public interface WxMpService {
*
* 获取access_token,本方法线程安全
* 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
- *
+ *
* 另:本service的所有方法都会在access_token过期是调用此方法
- *
+ *
* 程序员在非必要情况下尽量不要主动调用此方法
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
@@ -111,6 +111,135 @@ public interface WxMpService {
*/
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException;
+ /**
+ *
+ * 上传非图文永久素材
+ *
+ * 上传的多媒体文件有格式和大小限制,如下:
+ * 图片(image): 图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式
+ * 语音(voice):语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式
+ * 视频(video):在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON
+ * 缩略图(thumb):文档未说明
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
+ *
+ * @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
+ * @param material 上传的素材, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterial}
+ * @return
+ * @throws WxErrorException
+ */
+ public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException;
+
+ /**
+ *
+ * 上传永久图文素材
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
+ *
+ * @param news 上传的图文消息, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialNews}
+ * @return
+ * @throws WxErrorException
+ */
+ public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws WxErrorException;
+
+ /**
+ *
+ * 下载声音或者图片永久素材
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+ *
+ * @param media_id 永久素材的id
+ * @return
+ * @throws WxErrorException
+ */
+ public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException;
+
+ /**
+ *
+ * 获取视频永久素材的信息和下载地址
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+ *
+ * @param media_id 永久素材的id
+ * @return
+ * @throws WxErrorException
+ */
+ public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException;
+
+ /**
+ *
+ * 获取图文永久素材的信息
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
+ *
+ * @param media_id 永久素材的id
+ * @return
+ * @throws WxErrorException
+ */
+ public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException;
+
+ /**
+ *
+ * 更新图文永久素材
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
+ *
+ * @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate}
+ * @return
+ * @throws WxErrorException
+ */
+ public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException;
+
+ /**
+ *
+ * 删除永久素材
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/5/e66f61c303db51a6c0f90f46b15af5f5.html
+ *
+ * @param media_id 永久素材的id
+ * @return
+ * @throws WxErrorException
+ */
+ public boolean materialDelete(String media_id) throws WxErrorException;
+
+ /**
+ *
+ * 获取各类素材总数
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/16/8cc64f8c189674b421bee3ed403993b8.html
+ *
+ * @return
+ * @throws WxErrorException
+ */
+ public WxMpMaterialCountResult materialCount() throws WxErrorException;
+
+ /**
+ *
+ * 分页获取图文素材列表
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
+ *
+ * @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
+ * @param count 返回素材的数量,取值在1到20之间
+ * @return
+ * @throws WxErrorException
+ */
+ public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException;
+
+ /**
+ *
+ * 分页获取其他媒体素材列表
+ *
+ * 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
+ *
+ * @param type 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
+ * @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
+ * @param count 返回素材的数量,取值在1到20之间
+ * @return
+ * @throws WxErrorException
+ */
+ public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException;
+
/**
* @see #mediaUpload(String, String, InputStream)
* @param mediaType
@@ -118,7 +247,7 @@ public interface WxMpService {
* @throws WxErrorException
*/
public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException;
-
+
/**
*
* 下载多媒体文件
@@ -130,7 +259,7 @@ public interface WxMpService {
* @throws WxErrorException
*/
public File mediaDownload(String media_id) throws WxErrorException;
-
+
/**
*
* 发送客服消息
@@ -140,11 +269,11 @@ public interface WxMpService {
* @throws WxErrorException
*/
public void customMessageSend(WxMpCustomMessage message) throws WxErrorException;
-
+
/**
*
- * 上传群发用的图文消息,上传后才能群发图文消息
- *
+ * 上传群发用的图文消息,上传后才能群发图文消息
+ *
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
*
* @param news
@@ -153,7 +282,7 @@ public interface WxMpService {
* @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage)
*/
public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException;
-
+
/**
*
* 上传群发用的视频,上传后才能群发视频消息
@@ -175,10 +304,10 @@ public interface WxMpService {
*
* @param message
* @throws WxErrorException
- * @return
+ * @return
*/
public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException;
-
+
/**
*
* 按openId列表群发消息
@@ -201,7 +330,7 @@ public interface WxMpService {
* @throws WxErrorException
*/
public void menuCreate(WxMenu menu) throws WxErrorException;
-
+
/**
*
* 自定义菜单删除接口
@@ -210,7 +339,7 @@ public interface WxMpService {
* @throws WxErrorException
*/
public void menuDelete() throws WxErrorException;
-
+
/**
*
* 自定义菜单查询接口
@@ -227,11 +356,11 @@ public interface WxMpService {
* 最多支持创建500个分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
*
- * @param name 分组名字(30个字符以内)
+ * @param name 分组名字(30个字符以内)
* @throws WxErrorException
*/
public WxMpGroup groupCreate(String name) throws WxErrorException;
-
+
/**
*
* 分组管理接口 - 查询所有分组
@@ -241,34 +370,34 @@ public interface WxMpService {
* @throws WxErrorException
*/
public List groupGet() throws WxErrorException;
-
+
/**
*
* 分组管理接口 - 查询用户所在分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
*
- * @param openid 微信用户的openid
+ * @param openid 微信用户的openid
* @throws WxErrorException
*/
public long userGetGroup(String openid) throws WxErrorException;
-
+
/**
*
* 分组管理接口 - 修改分组名
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
- *
+ *
* 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
*
- * @param group 要更新的group,group的id,name必须设置
+ * @param group 要更新的group,group的id,name必须设置
* @throws WxErrorException
*/
public void groupUpdate(WxMpGroup group) throws WxErrorException;
-
+
/**
*
* 分组管理接口 - 移动用户分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
- *
+ *
* 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
*
* @param openid 用户openid
@@ -294,7 +423,7 @@ public interface WxMpService {
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
*
* @param openid 用户openid
- * @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语
+ * @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语
* @return
* @throws WxErrorException
*/
@@ -397,7 +526,7 @@ public interface WxMpService {
*
* @param scope
* @param state
- * @return code
+ * @return url
*/
public String oauth2buildAuthorizationUrl(String scope, String state);
@@ -410,7 +539,7 @@ public interface WxMpService {
* 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode
* @param scope
* @param state
- * @return code
+ * @return url
*/
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state);
/**
@@ -543,7 +672,7 @@ public interface WxMpService {
void setMaxRetryTimes(int maxRetryTimes);
/**
- * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1)
+ * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
* @param openId 支付人openId
* @param outTradeNo 商户端对应订单号
@@ -570,4 +699,19 @@ public interface WxMpService {
*/
Map getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);
+ /**
+ * 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
+ * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
+ * @param transactionId
+ * @param outTradeNo
+ */
+ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo);
+
+ /**
+ * 读取支付结果通知
+ * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
+ * @param xmlData
+ * @return
+ */
+ WxMpPayCallback getJSSDKCallbackData(String xmlData);
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
index 61960113..6e616284 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
@@ -1,13 +1,21 @@
package me.chanjar.weixin.mp.api;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.internal.Streams;
-import com.google.gson.reflect.TypeToken;
-import com.google.gson.stream.JsonReader;
-import com.thoughtworks.xstream.XStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.UUID;
+
+import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.WxMenu;
@@ -21,13 +29,53 @@ import me.chanjar.weixin.common.util.StringUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.common.util.fs.FileUtils;
-import me.chanjar.weixin.common.util.http.*;
+import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor;
+import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
+import me.chanjar.weixin.common.util.http.RequestExecutor;
+import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
+import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
+import me.chanjar.weixin.common.util.http.URIUtil;
+import me.chanjar.weixin.common.util.http.Utf8ResponseHandler;
import me.chanjar.weixin.common.util.json.GsonHelper;
+import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
-import me.chanjar.weixin.mp.bean.*;
-import me.chanjar.weixin.mp.bean.result.*;
-import me.chanjar.weixin.mp.util.http.*;
+import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+import me.chanjar.weixin.mp.bean.WxMpGroup;
+import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
+import me.chanjar.weixin.mp.bean.WxMpMassNews;
+import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
+import me.chanjar.weixin.mp.bean.WxMpMassVideo;
+import me.chanjar.weixin.mp.bean.WxMpMaterial;
+import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate;
+import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
+import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
+import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
+import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
+import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
+import me.chanjar.weixin.mp.bean.result.WxMpMaterialCountResult;
+import me.chanjar.weixin.mp.bean.result.WxMpMaterialFileBatchGetResult;
+import me.chanjar.weixin.mp.bean.result.WxMpMaterialNewsBatchGetResult;
+import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult;
+import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult;
+import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
+import me.chanjar.weixin.mp.bean.result.WxMpPayCallback;
+import me.chanjar.weixin.mp.bean.result.WxMpPayResult;
+import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult;
+import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
+import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
+import me.chanjar.weixin.mp.bean.result.WxMpUser;
+import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
+import me.chanjar.weixin.mp.bean.result.WxMpUserList;
+import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
+import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor;
+import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
+import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor;
+import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor;
+import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor;
+import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+
+import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.Consts;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
@@ -46,12 +94,13 @@ import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.security.NoSuchAlgorithmException;
-import java.util.*;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.internal.Streams;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.thoughtworks.xstream.XStream;
public class WxMpServiceImpl implements WxMpService {
@@ -162,6 +211,7 @@ public class WxMpServiceImpl implements WxMpService {
"url=" + url
);
WxJsapiSignature jsapiSignature = new WxJsapiSignature();
+ jsapiSignature.setAppid(wxMpConfigStorage.getAppId());
jsapiSignature.setTimestamp(timestamp);
jsapiSignature.setNoncestr(noncestr);
jsapiSignature.setUrl(url);
@@ -271,13 +321,13 @@ public class WxMpServiceImpl implements WxMpService {
}
}
- public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(String type, int offset, int count) throws WxErrorException {
+ public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";
- Map params = new HashMap();
- params.put("type", type);
+ Map params = new HashMap<>();
+ params.put("type", WxConsts.MATERIAL_NEWS);
params.put("offset", offset);
params.put("count", count);
- String responseText = post(url, new Gson().toJson(params));
+ String responseText = post(url, WxGsonBuilder.create().toJson(params));
WxError wxError = WxError.fromJson(responseText);
if (wxError.getErrorCode() == 0) {
return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialNewsBatchGetResult.class);
@@ -288,11 +338,11 @@ public class WxMpServiceImpl implements WxMpService {
public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";
- Map params = new HashMap();
+ Map params = new HashMap<>();
params.put("type", type);
params.put("offset", offset);
params.put("count", count);
- String responseText = post(url, new Gson().toJson(params));
+ String responseText = post(url, WxGsonBuilder.create().toJson(params));
WxError wxError = WxError.fromJson(responseText);
if (wxError.getErrorCode() == 0) {
return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialFileBatchGetResult.class);
@@ -347,8 +397,9 @@ public class WxMpServiceImpl implements WxMpService {
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
*/
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
- return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken>() {
- }.getType());
+ return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"),
+ new TypeToken>() {
+ }.getType());
}
public long userGetGroup(String openid) throws WxErrorException {
@@ -595,8 +646,9 @@ public class WxMpServiceImpl implements WxMpService {
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
String responseContent = post(url, param.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
- return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken>() {
- }.getType());
+ return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"),
+ new TypeToken>() {
+ }.getType());
}
public String get(String url, String queryParam) throws WxErrorException {
@@ -644,6 +696,9 @@ public class WxMpServiceImpl implements WxMpService {
}
protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException {
+ if (uri.indexOf("access_token=") != -1) {
+ throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
+ }
String accessToken = getAccessToken(false);
String uriWithAccessToken = uri;
@@ -789,7 +844,64 @@ public class WxMpServiceImpl implements WxMpService {
payInfo.put("signType", "MD5");
String finalSign = WxCryptUtil.createSign(payInfo, wxMpConfigStorage.getPartnerKey());
- payInfo.put("sign", finalSign);
+ payInfo.put("paySign", finalSign);
return payInfo;
}
+
+ @Override
+ public WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo) {
+ String nonce_str = System.currentTimeMillis() + "";
+
+ SortedMap packageParams = new TreeMap();
+ packageParams.put("appid", wxMpConfigStorage.getAppId());
+ packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
+ packageParams.put("transaction_id", transactionId);
+ packageParams.put("out_trade_no", outTradeNo);
+ packageParams.put("nonce_str", nonce_str);
+
+ String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
+ String xml = "" +
+ "" + wxMpConfigStorage.getAppId() + "" +
+ "" + wxMpConfigStorage.getPartnerId() + "" +
+ "" + transactionId + "" +
+ "" + outTradeNo + "" +
+ "" + nonce_str + "" +
+ "" + sign + "" +
+ "";
+
+ HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery");
+ if (httpProxy != null) {
+ RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
+ httpPost.setConfig(config);
+ }
+
+ StringEntity entity = new StringEntity(xml, Consts.UTF_8);
+ httpPost.setEntity(entity);
+ try {
+ CloseableHttpResponse response = httpClient.execute(httpPost);
+ String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.alias("xml", WxMpPayResult.class);
+ WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
+ return wxMpPayResult;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return new WxMpPayResult();
+ }
+
+ @Override
+ public WxMpPayCallback getJSSDKCallbackData(String xmlData) {
+ try {
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.alias("xml", WxMpPayCallback.class);
+ WxMpPayCallback wxMpCallback = (WxMpPayCallback) xstream.fromXML(xmlData);
+ return wxMpCallback;
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+ return new WxMpPayCallback();
+ }
+
+
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java
index af64464d..f1de7d9e 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMaterialNews.java
@@ -35,7 +35,8 @@ public class WxMpMaterialNews implements Serializable {
* 4. contentSourceUrl 在图文消息页面点击“阅读原文”后的页面链接
* 5. content (必填) 图文消息页面的内容,支持HTML标签
* 6. digest 图文消息的描述
- * 7, showCoverPic 是否显示封面,true为显示,false为不显示
+ * 7. showCoverPic 是否显示封面,true为显示,false为不显示
+ * 8. url 点击图文消息跳转链接
*
*
* @author chanjarster
@@ -70,6 +71,12 @@ public class WxMpMaterialNews implements Serializable {
*/
private boolean showCoverPic;
+ /**
+ * 点击图文消息跳转链接
+ * @return
+ */
+ private String url;
+
public String getThumbMediaId() {
return thumbMediaId;
}
@@ -126,11 +133,19 @@ public class WxMpMaterialNews implements Serializable {
this.showCoverPic = showCoverPic;
}
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
@Override
public String toString() {
return "WxMpMassNewsArticle [" + "thumbMediaId=" + thumbMediaId + ", author=" + author + ", title=" + title +
", contentSourceUrl=" + contentSourceUrl + ", content=" + content + ", digest=" + digest +
- ", showCoverPic=" + showCoverPic + "]";
+ ", showCoverPic=" + showCoverPic +", url=" + url + "]";
}
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java
index 370d4430..bca8c143 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java
@@ -121,4 +121,12 @@ public abstract class WxMpXmlOutMessage implements Serializable {
public static NewsBuilder NEWS() {
return new NewsBuilder();
}
+ /**
+ * 获得客服消息builder
+ *
+ * @return
+ */
+ public static TransferCustomerServiceBuilder TRANSFER_CUSTOMER_SERVICE() {
+ return new TransferCustomerServiceBuilder();
+ }
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java
new file mode 100644
index 00000000..5783d2b4
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTransferCustomerServiceMessage.java
@@ -0,0 +1,41 @@
+package me.chanjar.weixin.mp.bean;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamConverter;
+import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
+import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;
+
+@XStreamAlias("xml")
+public class WxMpXmlOutTransferCustomerServiceMessage extends WxMpXmlOutMessage {
+ @XStreamAlias("TransInfo")
+ protected final TransInfo transInfo = new TransInfo();
+
+ public WxMpXmlOutTransferCustomerServiceMessage() {
+ this.msgType = WxConsts.CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE;
+ }
+
+ public String getKfAccount() {
+ return transInfo.getKfAccount();
+ }
+
+ public void setKfAccount(String kfAccount) {
+ transInfo.setKfAccount(kfAccount);
+ }
+
+ @XStreamAlias("TransInfo")
+ public static class TransInfo {
+
+ @XStreamAlias("KfAccount")
+ @XStreamConverter(value=XStreamCDataConverter.class)
+ private String kfAccount;
+
+ public String getKfAccount() {
+ return kfAccount;
+ }
+
+ public void setKfAccount(String kfAccount) {
+ this.kfAccount = kfAccount;
+ }
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java
new file mode 100644
index 00000000..37616cf9
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TransferCustomerServiceBuilder.java
@@ -0,0 +1,28 @@
+package me.chanjar.weixin.mp.bean.outxmlbuilder;
+
+import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferCustomerServiceMessage;
+
+/**
+ * 客服消息builder
+ *
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build();
+ *
+ *
+ * @author chanjarster
+ */
+public final class TransferCustomerServiceBuilder extends BaseBuilder {
+ private String kfAccount;
+
+ public TransferCustomerServiceBuilder kfAccount(String kfAccount) {
+ this.kfAccount = kfAccount;
+ return this;
+ }
+
+
+ public WxMpXmlOutTransferCustomerServiceMessage build() {
+ WxMpXmlOutTransferCustomerServiceMessage m = new WxMpXmlOutTransferCustomerServiceMessage();
+ setCommon(m);
+ m.setKfAccount(kfAccount);
+ return m;
+ }
+}
\ No newline at end of file
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java
new file mode 100644
index 00000000..18aeda4d
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayCallback.java
@@ -0,0 +1,279 @@
+package me.chanjar.weixin.mp.bean.result;
+
+import java.io.Serializable;
+
+/**
+ * pre> 订单支付状态回调
+ *
+ * 支付结果通知(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7)
+ *
+ * /pre>
+ *
+ * @author ukid
+ */
+public class WxMpPayCallback implements Serializable {
+ private String return_code;
+ private String return_msg;
+
+ private String appid;
+ private String mch_id;
+ private String device_info;
+ private String nonce_str;
+ private String sign;
+ private String result_code;
+ private String err_code;
+ private String err_code_des;
+ private String openid;
+ private String is_subscribe;
+ private String trade_type;
+ private String bank_type;
+ private String total_fee;
+ private String fee_type;
+ private String cash_fee;
+ private String cash_fee_type;
+ private String coupon_fee;
+ private String coupon_count;
+ private String coupon_batch_id_$n;
+ private String coupon_id_$n;
+ private String coupon_fee_$n;
+ private String transaction_id;
+ private String out_trade_no;
+ private String attach;
+ private String time_end;
+
+ public String getReturn_code() {
+ return return_code;
+ }
+
+ public String getReturn_msg() {
+ return return_msg;
+ }
+
+ public String getAppid() {
+ return appid;
+ }
+
+ public String getMch_id() {
+ return mch_id;
+ }
+
+ public String getDevice_info() {
+ return device_info;
+ }
+
+ public String getNonce_str() {
+ return nonce_str;
+ }
+
+ public String getSign() {
+ return sign;
+ }
+
+ public String getResult_code() {
+ return result_code;
+ }
+
+ public String getErr_code() {
+ return err_code;
+ }
+
+ public String getErr_code_des() {
+ return err_code_des;
+ }
+
+ public String getOpenid() {
+ return openid;
+ }
+
+ public String getIs_subscribe() {
+ return is_subscribe;
+ }
+
+ public String getTrade_type() {
+ return trade_type;
+ }
+
+ public String getBank_type() {
+ return bank_type;
+ }
+
+ public String getTotal_fee() {
+ return total_fee;
+ }
+
+ public String getFee_type() {
+ return fee_type;
+ }
+
+ public String getCash_fee() {
+ return cash_fee;
+ }
+
+ public String getCash_fee_type() {
+ return cash_fee_type;
+ }
+
+ public String getCoupon_fee() {
+ return coupon_fee;
+ }
+
+ public String getCoupon_count() {
+ return coupon_count;
+ }
+
+ public String getCoupon_batch_id_$n() {
+ return coupon_batch_id_$n;
+ }
+
+ public String getCoupon_id_$n() {
+ return coupon_id_$n;
+ }
+
+ public String getCoupon_fee_$n() {
+ return coupon_fee_$n;
+ }
+
+ public String getTransaction_id() {
+ return transaction_id;
+ }
+
+ public String getOut_trade_no() {
+ return out_trade_no;
+ }
+
+ public String getAttach() {
+ return attach;
+ }
+
+ public String getTime_end() {
+ return time_end;
+ }
+
+ public void setReturn_code(String return_code) {
+ this.return_code = return_code;
+ }
+
+ public void setReturn_msg(String return_msg) {
+ this.return_msg = return_msg;
+ }
+
+ public void setAppid(String appid) {
+ this.appid = appid;
+ }
+
+ public void setMch_id(String mch_id) {
+ this.mch_id = mch_id;
+ }
+
+ public void setDevice_info(String device_info) {
+ this.device_info = device_info;
+ }
+
+ public void setNonce_str(String nonce_str) {
+ this.nonce_str = nonce_str;
+ }
+
+ public void setSign(String sign) {
+ this.sign = sign;
+ }
+
+ public void setResult_code(String result_code) {
+ this.result_code = result_code;
+ }
+
+ public void setErr_code(String err_code) {
+ this.err_code = err_code;
+ }
+
+ public void setErr_code_des(String err_code_des) {
+ this.err_code_des = err_code_des;
+ }
+
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
+ public void setIs_subscribe(String is_subscribe) {
+ this.is_subscribe = is_subscribe;
+ }
+
+ public void setTrade_type(String trade_type) {
+ this.trade_type = trade_type;
+ }
+
+ public void setBank_type(String bank_type) {
+ this.bank_type = bank_type;
+ }
+
+ public void setTotal_fee(String total_fee) {
+ this.total_fee = total_fee;
+ }
+
+ public void setFee_type(String fee_type) {
+ this.fee_type = fee_type;
+ }
+
+ public void setCash_fee(String cash_fee) {
+ this.cash_fee = cash_fee;
+ }
+
+ public void setCash_fee_type(String cash_fee_type) {
+ this.cash_fee_type = cash_fee_type;
+ }
+
+ public void setCoupon_fee(String coupon_fee) {
+ this.coupon_fee = coupon_fee;
+ }
+
+ public void setCoupon_count(String coupon_count) {
+ this.coupon_count = coupon_count;
+ }
+
+ public void setCoupon_batch_id_$n(String coupon_batch_id_$n) {
+ this.coupon_batch_id_$n = coupon_batch_id_$n;
+ }
+
+ public void setCoupon_id_$n(String coupon_id_$n) {
+ this.coupon_id_$n = coupon_id_$n;
+ }
+
+ public void setCoupon_fee_$n(String coupon_fee_$n) {
+ this.coupon_fee_$n = coupon_fee_$n;
+ }
+
+ public void setTransaction_id(String transaction_id) {
+ this.transaction_id = transaction_id;
+ }
+
+ public void setOut_trade_no(String out_trade_no) {
+ this.out_trade_no = out_trade_no;
+ }
+
+ public void setAttach(String attach) {
+ this.attach = attach;
+ }
+
+ public void setTime_end(String time_end) {
+ this.time_end = time_end;
+ }
+
+ @Override
+ public String toString() {
+ return "WxMpPayCallback [return_code=" + return_code + ", return_msg="
+ + return_msg + ", appid=" + appid + ", mch_id=" + mch_id
+ + ", device_info=" + device_info + ", nonce_str=" + nonce_str
+ + ", sign=" + sign + ", result_code=" + result_code
+ + ", err_code=" + err_code + ", err_code_des=" + err_code_des
+ + ", openid=" + openid + ", is_subscribe=" + is_subscribe
+ + ", trade_type=" + trade_type + ", bank_type=" + bank_type
+ + ", total_fee=" + total_fee + ", fee_type=" + fee_type
+ + ", cash_fee=" + cash_fee + ", cash_fee_type=" + cash_fee_type
+ + ", coupon_fee=" + coupon_fee + ", coupon_count="
+ + coupon_count + ", coupon_batch_id_$n=" + coupon_batch_id_$n
+ + ", coupon_id_$n=" + coupon_id_$n + ", coupon_fee_$n="
+ + coupon_fee_$n + ", transaction_id=" + transaction_id
+ + ", out_trade_no=" + out_trade_no + ", attach=" + attach
+ + ", time_end=" + time_end + "]";
+ }
+
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java
new file mode 100644
index 00000000..7fd850fb
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPayResult.java
@@ -0,0 +1,215 @@
+package me.chanjar.weixin.mp.bean.result;
+
+import java.io.Serializable;
+
+/**
+ *
+ * 查询订单支付状态返回的结果
+ *
+ * 查询订单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2)
+ *
+ *
+ *
+ * @author ukid
+ */
+public class WxMpPayResult implements Serializable {
+ private String return_code;
+ private String return_msg;
+ private String appid;
+ private String mch_id;
+ private String nonce_str;
+ private String sign;
+ private String result_code;
+ private String err_code;
+ private String err_code_des;
+ private String trade_state;
+ private String device_info;
+ private String openid;
+ private String is_subscribe;
+ private String trade_type;
+ private String bank_type;
+ private String total_fee;
+ private String coupon_fee;
+ private String fee_type;
+ private String transaction_id;
+ private String out_trade_no;
+ private String attach;
+ private String time_end;
+
+ public String getReturn_code() {
+ return return_code;
+ }
+
+ public String getReturn_msg() {
+ return return_msg;
+ }
+
+ public String getAppid() {
+ return appid;
+ }
+
+ public String getMch_id() {
+ return mch_id;
+ }
+
+ public String getNonce_str() {
+ return nonce_str;
+ }
+
+ public String getSign() {
+ return sign;
+ }
+
+ public String getResult_code() {
+ return result_code;
+ }
+
+ public String getErr_code() {
+ return err_code;
+ }
+
+ public String getErr_code_des() {
+ return err_code_des;
+ }
+
+ public String getTrade_state() {
+ return trade_state;
+ }
+
+ public String getDevice_info() {
+ return device_info;
+ }
+
+ public String getOpenid() {
+ return openid;
+ }
+
+ public String getIs_subscribe() {
+ return is_subscribe;
+ }
+
+ public String getTrade_type() {
+ return trade_type;
+ }
+
+ public String getBank_type() {
+ return bank_type;
+ }
+
+ public String getTotal_fee() {
+ return total_fee;
+ }
+
+ public String getCoupon_fee() {
+ return coupon_fee;
+ }
+
+ public String getFee_type() {
+ return fee_type;
+ }
+
+ public String getTransaction_id() {
+ return transaction_id;
+ }
+
+ public String getOut_trade_no() {
+ return out_trade_no;
+ }
+
+ public String getAttach() {
+ return attach;
+ }
+
+ public String getTime_end() {
+ return time_end;
+ }
+
+ public void setReturn_code(String return_code) {
+ this.return_code = return_code;
+ }
+
+ public void setReturn_msg(String return_msg) {
+ this.return_msg = return_msg;
+ }
+
+ public void setAppid(String appid) {
+ this.appid = appid;
+ }
+
+ public void setMch_id(String mch_id) {
+ this.mch_id = mch_id;
+ }
+
+ public void setNonce_str(String nonce_str) {
+ this.nonce_str = nonce_str;
+ }
+
+ public void setSign(String sign) {
+ this.sign = sign;
+ }
+
+ public void setResult_code(String result_code) {
+ this.result_code = result_code;
+ }
+
+ public void setErr_code(String err_code) {
+ this.err_code = err_code;
+ }
+
+ public void setErr_code_des(String err_code_des) {
+ this.err_code_des = err_code_des;
+ }
+
+ public void setTrade_state(String trade_state) {
+ this.trade_state = trade_state;
+ }
+
+ public void setDevice_info(String device_info) {
+ this.device_info = device_info;
+ }
+
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
+ public void setIs_subscribe(String is_subscribe) {
+ this.is_subscribe = is_subscribe;
+ }
+
+ public void setTrade_type(String trade_type) {
+ this.trade_type = trade_type;
+ }
+
+ public void setBank_type(String bank_type) {
+ this.bank_type = bank_type;
+ }
+
+ public void setTotal_fee(String total_fee) {
+ this.total_fee = total_fee;
+ }
+
+ public void setCoupon_fee(String coupon_fee) {
+ this.coupon_fee = coupon_fee;
+ }
+
+ public void setFee_type(String fee_type) {
+ this.fee_type = fee_type;
+ }
+
+ public void setTransaction_id(String transaction_id) {
+ this.transaction_id = transaction_id;
+ }
+
+ public void setOut_trade_no(String out_trade_no) {
+ this.out_trade_no = out_trade_no;
+ }
+
+ public void setAttach(String attach) {
+ this.attach = attach;
+ }
+
+ public void setTime_end(String time_end) {
+ this.time_end = time_end;
+ }
+
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java
index 25286168..aa42299a 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpPrepayIdResult.java
@@ -4,10 +4,9 @@ import java.io.Serializable;
/**
*
- * 群发消息一发送就返回的结果
+ * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果
*
- * 真正的群发消息是否发送成功要看
- * http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口#.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81.E7.BE.A4.E5.8F.91.E7.BB.93.E6.9E.9C
+ * 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
*
*
*
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java
index 4da3417a..8e7c41de 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java
@@ -1,10 +1,10 @@
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.common.util.json.WxGsonBuilder;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
@@ -31,9 +31,9 @@ public class MaterialDeleteRequestExecutor implements RequestExecutor params = new HashMap();
+ Map params = new HashMap<>();
params.put("media_id", materialId);
- httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
+ httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
CloseableHttpResponse response = httpclient.execute(httpPost);
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java
index 9cae8268..e23ecc50 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java
@@ -1,10 +1,10 @@
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.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.apache.http.HttpHost;
@@ -32,9 +32,9 @@ public class MaterialNewsInfoRequestExecutor implements RequestExecutor params = new HashMap();
+ Map params = new HashMap<>();
params.put("media_id", materialId);
- httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
+ httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
CloseableHttpResponse response = httpclient.execute(httpPost);
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java
index 2d922614..63d92523 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java
@@ -1,10 +1,10 @@
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.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.WxMpMaterial;
import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult;
import org.apache.http.HttpHost;
@@ -39,7 +39,7 @@ public class MaterialUploadRequestExecutor implements RequestExecutor form = material.getForm();
if (material.getForm() != null) {
- multipartEntityBuilder.addTextBody("description", new Gson().toJson(form));
+ multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));
}
httpPost.setEntity(multipartEntityBuilder.build());
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java
index f097eaef..e529f4e7 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java
@@ -1,10 +1,10 @@
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.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
@@ -31,9 +31,9 @@ public class MaterialVideoInfoRequestExecutor implements RequestExecutor params = new HashMap();
+ Map params = new HashMap<>();
params.put("media_id", materialId);
- httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
+ httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
CloseableHttpResponse response = httpclient.execute(httpPost);
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java
index 1c7e8639..72917a93 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java
@@ -1,10 +1,10 @@
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 me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
@@ -41,9 +41,9 @@ public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExec
httpPost.setConfig(config);
}
- Map params = new HashMap();
+ Map params = new HashMap<>();
params.put("media_id", materialId);
- httpPost.setEntity(new StringEntity(new Gson().toJson(params)));
+ httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
CloseableHttpResponse response = httpclient.execute(httpPost);
// 下载媒体文件出错
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
@@ -51,7 +51,7 @@ public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExec
String responseContentString = new String(responseContent, "UTF-8");
if (responseContentString.length() < 100) {
try {
- WxError wxError = new Gson().fromJson(responseContentString, WxError.class);
+ WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java
index 5483068f..74e3edad 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialFileBatchGetGsonAdapter.java
@@ -29,7 +29,7 @@ public class WxMpMaterialFileBatchGetGsonAdapter implements JsonDeserializer items = new ArrayList();
+ List items = new ArrayList<>();
for (JsonElement anItem : item) {
JsonObject articleInfo = anItem.getAsJsonObject();
items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem.class));
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java
index 4f0e2e6d..141baeab 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMaterialNewsArticleGsonAdapter.java
@@ -32,6 +32,9 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer items = new ArrayList();
+ List items = new ArrayList<>();
for (JsonElement anItem : item) {
JsonObject articleInfo = anItem.getAsJsonObject();
items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class));
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java
index bddc864f..8e145e15 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMaterialAPITest.java
@@ -31,7 +31,7 @@ public class WxMpMaterialAPITest {
@Inject
protected WxMpServiceImpl wxService;
- private Map> media_ids = new LinkedHashMap>();
+ private Map> media_ids = new LinkedHashMap<>();
// 缩略图的id,测试上传图文使用
private String thumbMediaId = "";
// 单图文消息media_id
@@ -64,7 +64,7 @@ public class WxMpMaterialAPITest {
thumbMediaId = res.getMediaId();
}
- Map materialInfo = new HashMap();
+ Map materialInfo = new HashMap<>();
materialInfo.put("media_id", res.getMediaId());
materialInfo.put("length", tempFile.length());
materialInfo.put("filename", tempFile.getName());
@@ -195,7 +195,7 @@ public class WxMpMaterialAPITest {
@Test(dependsOnMethods = {"testUpdateNewsInfo"})
public void testMaterialNewsList() throws WxErrorException {
- WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(WxConsts.MATERIAL_NEWS, 0, 20);
+ WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(0, 20);
return;
}
@@ -217,8 +217,8 @@ public class WxMpMaterialAPITest {
public Object[][] downloadMaterial() {
Object[][] params = new Object[this.media_ids.size()][];
int index = 0;
- for (Iterator iterator = this.media_ids.keySet().iterator(); iterator.hasNext(); ) {
- params[index] = new Object[]{iterator.next()};
+ for (String mediaId : this.media_ids.keySet()) {
+ params[index] = new Object[]{mediaId};
index++;
}
return params;
@@ -226,9 +226,9 @@ public class WxMpMaterialAPITest {
@DataProvider
public Iterator