#1157 增加网络检测接口

This commit is contained in:
billytomato
2019-08-15 13:26:43 +08:00
committed by Binary Wang
parent 6e1d7fcef0
commit d1586aec25
8 changed files with 197 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.WxNetCheckResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
@@ -178,6 +179,20 @@ public interface WxMpService {
*/
String[] getCallbackIP() throws WxErrorException;
/**
* <pre>
* 网络检测
* https://mp.weixin.qq.com/wiki?t=resource/res_main&id=21541575776DtsuT
* 为了帮助开发者排查回调连接失败的问题提供这个网络检测的API。它可以对开发者URL做域名解析然后对所有IP进行一次ping操作得到丢包率和耗时。
* </pre>
*
* @param action 执行的检测动作
* @param operator 指定平台从某个运营商进行检测
* @throws WxErrorException
*/
WxNetCheckResult netCheck(String action, String operator) throws WxErrorException;
/**
* <pre>
* 获取公众号的自动回复规则.

View File

@@ -8,6 +8,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.WxNetCheckResult;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.StandardSessionManager;
@@ -236,6 +237,15 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
return ipArray;
}
@Override
public WxNetCheckResult netCheck(String action, String operator) throws WxErrorException {
JsonObject o = new JsonObject();
o.addProperty("action", action);
o.addProperty("check_operator", operator);
String responseContent = this.post(NETCHECK_URL, o.toString());
return WxNetCheckResult.fromJson(responseContent);
}
@Override
public WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorException {
return WxMpCurrentAutoReplyInfo.fromJson(this.get(GET_CURRENT_AUTOREPLY_INFO_URL, null));

View File

@@ -110,6 +110,10 @@ public interface WxMpApiUrl {
* 获取微信服务器IP地址.
*/
GET_CALLBACK_IP_URL(API_DEFAULT_HOST_URL, "/cgi-bin/getcallbackip"),
/**
* 网络检测.
*/
NETCHECK_URL(API_DEFAULT_HOST_URL, "/cgi-bin/callback/check"),
/**
* 第三方使用网站应用授权登录的url.
*/