Skip to content

Commit 57f3755

Browse files
committed
binarywang#68 实现获取公众号的自动回复规则的接口
1 parent 166e54c commit 57f3755

File tree

7 files changed

+647
-6
lines changed

7 files changed

+647
-6
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package me.chanjar.weixin.common.util.json;
2+
3+
import com.google.gson.JsonParseException;
4+
import com.google.gson.TypeAdapter;
5+
import com.google.gson.stream.JsonReader;
6+
import com.google.gson.stream.JsonToken;
7+
import com.google.gson.stream.JsonWriter;
8+
import org.apache.commons.lang3.BooleanUtils;
9+
10+
import java.io.IOException;
11+
12+
/**
13+
* <pre>
14+
* Gson 布尔类型类型转换器
15+
* Created by Binary Wang on 2017-7-8.
16+
* </pre>
17+
*
18+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
19+
*/
20+
public class WxBooleanTypeAdapter extends TypeAdapter<Boolean> {
21+
@Override
22+
public void write(JsonWriter out, Boolean value) throws IOException {
23+
if (value == null) {
24+
out.nullValue();
25+
} else {
26+
out.value(value);
27+
}
28+
}
29+
30+
@Override
31+
public Boolean read(JsonReader in) throws IOException {
32+
JsonToken peek = in.peek();
33+
switch (peek) {
34+
case BOOLEAN:
35+
return in.nextBoolean();
36+
case NULL:
37+
in.nextNull();
38+
return null;
39+
case NUMBER:
40+
return BooleanUtils.toBoolean(in.nextInt());
41+
case STRING:
42+
return BooleanUtils.toBoolean(in.nextString());
43+
default:
44+
throw new JsonParseException("Expected BOOLEAN or NUMBER but was " + peek);
45+
}
46+
}
47+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package me.chanjar.weixin.common.util.json;
2+
3+
import com.google.gson.JsonParseException;
4+
import com.google.gson.TypeAdapter;
5+
import com.google.gson.stream.JsonReader;
6+
import com.google.gson.stream.JsonToken;
7+
import com.google.gson.stream.JsonWriter;
8+
9+
import java.io.IOException;
10+
import java.util.Date;
11+
12+
/**
13+
* <pre>
14+
* Gson 日期类型转换器
15+
* Created by Binary Wang on 2017-7-8.
16+
* </pre>
17+
*
18+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
19+
*/
20+
public class WxDateTypeAdapter extends TypeAdapter<Date> {
21+
@Override
22+
public void write(JsonWriter out, Date value) throws IOException {
23+
if (value == null) {
24+
out.nullValue();
25+
} else {
26+
out.value(value.getTime() / 1000);
27+
}
28+
}
29+
30+
@Override
31+
public Date read(JsonReader in) throws IOException {
32+
JsonToken peek = in.peek();
33+
switch (peek) {
34+
case NULL:
35+
in.nextNull();
36+
return null;
37+
case NUMBER:
38+
return new Date(in.nextInt() * 1000);
39+
default:
40+
throw new JsonParseException("Expected NUMBER but was " + peek);
41+
}
42+
}
43+
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public interface WxMpService {
7777
*/
7878
String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect";
7979

80+
/**
81+
* 获取公众号的自动回复规则
82+
*/
83+
String GET_CURRENT_AUTOREPLY_INFO_URL = "https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info";
84+
8085
/**
8186
* <pre>
8287
* 验证消息的确来自微信服务器
@@ -273,6 +278,24 @@ public interface WxMpService {
273278
*/
274279
String[] getCallbackIP() throws WxErrorException;
275280

281+
/**
282+
* <pre>
283+
* 获取公众号的自动回复规则
284+
* http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751299&token=&lang=zh_CN
285+
* 开发者可以通过该接口,获取公众号当前使用的自动回复规则,包括关注后自动回复、消息自动回复(60分钟内触发一次)、关键词自动回复。
286+
* 请注意:
287+
* 1、第三方平台开发者可以通过本接口,在旗下公众号将业务授权给你后,立即通过本接口检测公众号的自动回复配置,并通过接口再次给公众号设置好自动回复规则,以提升公众号运营者的业务体验。
288+
* 2、本接口仅能获取公众号在公众平台官网的自动回复功能中设置的自动回复规则,若公众号自行开发实现自动回复,或通过第三方平台开发者来实现,则无法获取。
289+
* 3、认证/未认证的服务号/订阅号,以及接口测试号,均拥有该接口权限。
290+
* 4、从第三方平台的公众号登录授权机制上来说,该接口从属于消息与菜单权限集。
291+
* 5、本接口中返回的图片/语音/视频为临时素材(临时素材每次获取都不同,3天内有效,通过素材管理-获取临时素材接口来获取这些素材),本接口返回的图文消息为永久素材素材(通过素材管理-获取永久素材接口来获取这些素材)。
292+
* 接口调用请求说明
293+
* http请求方式: GET(请使用https协议)
294+
* https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info?access_token=ACCESS_TOKEN
295+
* </pre>
296+
*/
297+
WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorException;
298+
276299
/**
277300
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
278301
*/
@@ -292,15 +315,10 @@ public interface WxMpService {
292315
*/
293316
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
294317

295-
/**
296-
* 获取代理对象
297-
*/
298-
//HttpHost getRequestHttpProxy();
299-
300318
/**
301319
* <pre>
302320
* 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
303-
* 默认:1000ms
321+
* @param retrySleepMillis 默认:1000ms
304322
* </pre>
305323
*/
306324
void setRetrySleepMillis(int retrySleepMillis);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ public String[] getCallbackIP() throws WxErrorException {
231231
return ipArray;
232232
}
233233

234+
@Override
235+
public WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorException {
236+
return WxMpCurrentAutoReplyInfo.fromJson(this.get(GET_CURRENT_AUTOREPLY_INFO_URL, null));
237+
}
238+
234239
@Override
235240
public String get(String url, String queryParam) throws WxErrorException {
236241
return execute(SimpleGetRequestExecutor.create(this), url, queryParam);

0 commit comments

Comments
 (0)