Skip to content

Commit eaad636

Browse files
committed
binarywang#252 原有图文素材管理接口增加留言管理所需两个参数:need_open_comment 和 only_fans_can_comment
1 parent 554fd08 commit eaad636

13 files changed

+137
-21
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws
7777
}
7878

7979
@Override
80-
public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException {
80+
public InputStream materialImageOrVoiceDownload(String mediaId) throws WxErrorException {
8181
return this.wxMpService.execute(MaterialVoiceAndImageDownloadRequestExecutor
82-
.create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), MATERIAL_GET_URL, media_id);
82+
.create(this.wxMpService.getRequestHttp(), this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), MATERIAL_GET_URL, mediaId);
8383
}
8484

8585
@Override
86-
public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException {
87-
return this.wxMpService.execute(MaterialVideoInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_GET_URL, media_id);
86+
public WxMpMaterialVideoInfoResult materialVideoInfo(String mediaId) throws WxErrorException {
87+
return this.wxMpService.execute(MaterialVideoInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_GET_URL, mediaId);
8888
}
8989

9090
@Override
91-
public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException {
92-
return this.wxMpService.execute(MaterialNewsInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_GET_URL, media_id);
91+
public WxMpMaterialNews materialNewsInfo(String mediaId) throws WxErrorException {
92+
return this.wxMpService.execute(MaterialNewsInfoRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_GET_URL, mediaId);
9393
}
9494

9595
@Override
@@ -104,8 +104,8 @@ public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleU
104104
}
105105

106106
@Override
107-
public boolean materialDelete(String media_id) throws WxErrorException {
108-
return this.wxMpService.execute(MaterialDeleteRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_DEL_URL, media_id);
107+
public boolean materialDelete(String mediaId) throws WxErrorException {
108+
return this.wxMpService.execute(MaterialDeleteRequestExecutor.create(this.wxMpService.getRequestHttp()), MATERIAL_DEL_URL, mediaId);
109109
}
110110

111111
@Override

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialNews.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
55

66
import java.io.Serializable;
7+
import java.util.Date;
78
import java.util.ArrayList;
89
import java.util.List;
910

1011
public class WxMpMaterialNews implements Serializable {
1112
private static final long serialVersionUID = -3283203652013494976L;
1213

14+
private Date createdTime;
15+
private Date updatedTime;
16+
1317
private List<WxMpMaterialNewsArticle> articles = new ArrayList<>();
1418

1519
public List<WxMpMaterialNewsArticle> getArticles() {
@@ -28,9 +32,25 @@ public boolean isEmpty() {
2832
return this.articles == null || this.articles.isEmpty();
2933
}
3034

35+
public Date getCreatedTime() {
36+
return this.createdTime;
37+
}
38+
39+
public void setCreatedTime(Date createdTime) {
40+
this.createdTime = createdTime;
41+
}
42+
43+
public Date getUpdatedTime() {
44+
return this.updatedTime;
45+
}
46+
47+
public void setUpdatedTime(Date updatedTime) {
48+
this.updatedTime = updatedTime;
49+
}
50+
3151
@Override
3252
public String toString() {
33-
return ToStringUtils.toSimpleString(this);
53+
return this.toJson();
3454
}
3555

3656
/**
@@ -44,6 +64,8 @@ public String toString() {
4464
* 6. digest 图文消息的描述
4565
* 7. showCoverPic 是否显示封面,true为显示,false为不显示
4666
* 8. url 点击图文消息跳转链接
67+
* 9. need_open_comment(新增字段) 否 Uint32 是否打开评论,0不打开,1打开
68+
* 10. only_fans_can_comment(新增字段) 否 Uint32 是否粉丝才可评论,0所有人可评论,1粉丝才可评论
4769
* </pre>
4870
*
4971
* @author chanjarster
@@ -87,6 +109,18 @@ public static class WxMpMaterialNewsArticle {
87109
*/
88110
private String url;
89111

112+
/**
113+
* need_open_comment
114+
* 是否打开评论,0不打开,1打开
115+
*/
116+
private Boolean needOpenComment;
117+
118+
/**
119+
* only_fans_can_comment
120+
* 是否粉丝才可评论,0所有人可评论,1粉丝才可评论
121+
*/
122+
private Boolean onlyFansCanComment;
123+
90124
public String getThumbMediaId() {
91125
return this.thumbMediaId;
92126
}
@@ -159,6 +193,22 @@ public void setThumbUrl(String thumbUrl) {
159193
this.thumbUrl = thumbUrl;
160194
}
161195

196+
public Boolean getNeedOpenComment() {
197+
return this.needOpenComment;
198+
}
199+
200+
public void setNeedOpenComment(Boolean needOpenComment) {
201+
this.needOpenComment = needOpenComment;
202+
}
203+
204+
public Boolean getOnlyFansCanComment() {
205+
return this.onlyFansCanComment;
206+
}
207+
208+
public void setOnlyFansCanComment(Boolean onlyFansCanComment) {
209+
this.onlyFansCanComment = onlyFansCanComment;
210+
}
211+
162212
@Override
163213
public String toString() {
164214
return ToStringUtils.toSimpleString(this);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/material/WxMpMaterialUploadResult.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package me.chanjar.weixin.mp.bean.material;
22

3+
import me.chanjar.weixin.common.util.ToStringUtils;
34
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
45

56
import java.io.Serializable;
67

78
public class WxMpMaterialUploadResult implements Serializable {
8-
9-
/**
10-
*
11-
*/
129
private static final long serialVersionUID = -128818731449449537L;
1310
private String mediaId;
1411
private String url;
12+
private Integer errCode;
13+
private String errMsg;
1514

1615
public static WxMpMaterialUploadResult fromJson(String json) {
1716
return WxMpGsonBuilder.create().fromJson(json, WxMpMaterialUploadResult.class);
@@ -33,9 +32,25 @@ public void setUrl(String url) {
3332
this.url = url;
3433
}
3534

35+
public Integer getErrCode() {
36+
return this.errCode;
37+
}
38+
39+
public void setErrCode(Integer errCode) {
40+
this.errCode = errCode;
41+
}
42+
43+
public String getErrMsg() {
44+
return this.errMsg;
45+
}
46+
47+
public void setErrMsg(String errMsg) {
48+
this.errMsg = errMsg;
49+
}
50+
3651
@Override
3752
public String toString() {
38-
return "WxMpMaterialUploadResult [media_id=" + this.mediaId + ", url=" + this.url + "]";
53+
return ToStringUtils.toSimpleString(this);
3954
}
4055

4156
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVoiceAndImageDownloadRequestExecutor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ public abstract class MaterialVoiceAndImageDownloadRequestExecutor<H, P> impleme
1313
protected RequestHttp<H, P> requestHttp;
1414
protected File tmpDirFile;
1515

16-
1716
public MaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
1817
this.requestHttp = requestHttp;
1918
this.tmpDirFile = tmpDirFile;
2019
}
2120

22-
2321
public static RequestExecutor<InputStream, String> create(RequestHttp requestHttp, File tmpDirFile) {
2422
switch (requestHttp.getRequestType()) {
2523
case APACHE_HTTP:

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialNewsInfoRequestExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.apache.http.client.methods.HttpPost;
1515
import org.apache.http.entity.StringEntity;
1616
import org.apache.http.impl.client.CloseableHttpClient;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
1719

1820
import java.io.IOException;
1921
import java.util.HashMap;
@@ -23,6 +25,8 @@
2325
* Created by ecoolper on 2017/5/5.
2426
*/
2527
public class ApacheMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<CloseableHttpClient, HttpHost> {
28+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
29+
2630
public ApacheMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
2731
super(requestHttp);
2832
}
@@ -40,6 +44,7 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc
4044
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
4145
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
4246
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
47+
this.logger.debug("响应原始数据:{}", responseContent);
4348
WxError error = WxError.fromJson(responseContent);
4449
if (error.getErrorCode() != 0) {
4550
throw new WxErrorException(error);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialVoiceAndImageDownloadRequestExecutor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.io.IOException;
2020
import java.io.InputStream;
21+
import java.nio.charset.StandardCharsets;
2122
import java.util.HashMap;
2223
import java.util.Map;
2324

@@ -41,10 +42,10 @@ public InputStream execute(String uri, String materialId) throws WxErrorExceptio
4142
params.put("media_id", materialId);
4243
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
4344
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
44-
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
45+
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
4546
// 下载媒体文件出错
4647
byte[] responseContent = IOUtils.toByteArray(inputStream);
47-
String responseContentString = new String(responseContent, "UTF-8");
48+
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
4849
if (responseContentString.length() < 100) {
4950
try {
5051
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialNewsInfoRequestExecutor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
1313
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
1414
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
1517

1618
import java.io.IOException;
1719

1820
/**
1921
* Created by ecoolper on 2017/5/5.
2022
*/
2123
public class JoddMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<HttpConnectionProvider, ProxyInfo> {
24+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
2225
public JoddMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
2326
super(requestHttp);
2427
}
@@ -36,6 +39,7 @@ public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorExc
3639
response.charset(StringPool.UTF_8);
3740

3841
String responseContent = response.bodyText();
42+
this.logger.debug("响应原始数据:{}", responseContent);
3943
WxError error = WxError.fromJson(responseContent);
4044
if (error.getErrorCode() != 0) {
4145
throw new WxErrorException(error);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/jodd/JoddMaterialVoiceAndImageDownloadRequestExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.File;
1818
import java.io.IOException;
1919
import java.io.InputStream;
20+
import java.nio.charset.StandardCharsets;
2021

2122
/**
2223
* Created by ecoolper on 2017/5/5.
@@ -40,7 +41,7 @@ public InputStream execute(String uri, String materialId) throws WxErrorExceptio
4041
try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
4142
// 下载媒体文件出错
4243
byte[] responseContent = IOUtils.toByteArray(inputStream);
43-
String responseContentString = new String(responseContent, "UTF-8");
44+
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
4445
if (responseContentString.length() < 100) {
4546
try {
4647
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialNewsInfoRequestExecutor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
99
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
1010
import okhttp3.*;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
1113

1214
import java.io.IOException;
1315

1416
/**
1517
* Created by ecoolper on 2017/5/5.
1618
*/
1719
public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<ConnectionPool, OkHttpProxyInfo> {
20+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
1821
public OkhttpMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
1922
super(requestHttp);
2023
}
@@ -44,6 +47,7 @@ public Request authenticate(Route route, Response response) throws IOException {
4447

4548
Response response = client.newCall(request).execute();
4649
String responseContent = response.body().string();
50+
this.logger.debug("响应原始数据:{}", responseContent);
4751

4852
WxError error = WxError.fromJson(responseContent);
4953
if (error.getErrorCode() != 0) {

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/okhttp/OkhttpMaterialVoiceAndImageDownloadRequestExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.File;
1414
import java.io.IOException;
1515
import java.io.InputStream;
16+
import java.nio.charset.StandardCharsets;
1617

1718
/**
1819
* Created by ecoolper on 2017/5/5.
@@ -50,7 +51,7 @@ public Request authenticate(Route route, Response response) throws IOException {
5051

5152
// 下载媒体文件出错
5253
byte[] responseContent = IOUtils.toByteArray(inputStream);
53-
String responseContentString = new String(responseContent, "UTF-8");
54+
String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
5455
if (responseContentString.length() < 100) {
5556
try {
5657
WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);

0 commit comments

Comments
 (0)