mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
add user black list api and impl
This commit is contained in:
@@ -327,7 +327,7 @@ public interface WxMpService {
|
||||
*
|
||||
* @return WxMpGroupService
|
||||
*/
|
||||
|
||||
|
||||
WxMpGroupService getGroupService();
|
||||
|
||||
/**
|
||||
@@ -364,4 +364,11 @@ public interface WxMpService {
|
||||
* @return WxMpDataCubeService
|
||||
*/
|
||||
WxMpDataCubeService getDataCubeService();
|
||||
|
||||
/**
|
||||
* 返回用户黑名单管理相关接口的方法实现类,以方便调用其各种借口
|
||||
*
|
||||
* @return WxMpUserBlackListService
|
||||
*/
|
||||
WxMpUserBlackListService getBlackListService();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author miller
|
||||
*/
|
||||
public interface WxMpUserBlackListService {
|
||||
/**
|
||||
* <pre>
|
||||
* 获取公众号的黑名单列表
|
||||
* 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
|
||||
* </pre>
|
||||
*/
|
||||
WxMpUserBlackListGetResult blackList(String nextOpenid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 拉黑用户
|
||||
* 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
|
||||
* </pre>
|
||||
*/
|
||||
void pushToBlackList(List<String> openIdList) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 取消拉黑用户
|
||||
* 详情请见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA&token=&lang=zh_CN
|
||||
* </pre>
|
||||
*/
|
||||
void pullFromBlackList(List<String> openIdList) throws WxErrorException;
|
||||
}
|
||||
@@ -1,23 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.BasicResponseHandler;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
@@ -42,6 +28,7 @@ import me.chanjar.weixin.mp.api.WxMpMenuService;
|
||||
import me.chanjar.weixin.mp.api.WxMpPayService;
|
||||
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserBlackListService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserTagService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpIndustry;
|
||||
@@ -57,6 +44,18 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.BasicResponseHandler;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
@@ -75,7 +74,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
private final Object globalJsapiTicketRefreshLock = new Object();
|
||||
|
||||
private WxMpConfigStorage configStorage;
|
||||
|
||||
|
||||
private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this);
|
||||
|
||||
private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this);
|
||||
@@ -96,6 +95,8 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
private WxMpDataCubeService dataCubeService = new WxMpDataCubeServiceImpl(this);
|
||||
|
||||
private WxMpUserBlackListService blackListService = new WxMpUserBlackListServiceImpl(this);
|
||||
|
||||
private CloseableHttpClient httpClient;
|
||||
|
||||
private HttpHost httpProxy;
|
||||
@@ -312,7 +313,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
if (state != null) {
|
||||
url.append("&state=").append(state);
|
||||
}
|
||||
|
||||
|
||||
url.append("#wechat_redirect");
|
||||
return url.toString();
|
||||
}
|
||||
@@ -474,7 +475,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public HttpHost getHttpProxy() {
|
||||
return this.httpProxy;
|
||||
}
|
||||
@@ -495,7 +496,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
if (null == apacheHttpClientBuilder) {
|
||||
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
|
||||
}
|
||||
|
||||
|
||||
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
|
||||
.httpProxyPort(this.configStorage.getHttpProxyPort())
|
||||
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
|
||||
@@ -580,4 +581,9 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
return this.dataCubeService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUserBlackListService getBlackListService() {
|
||||
return this.blackListService;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserBlackListService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserBlackListGetResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author miller
|
||||
*/
|
||||
public class WxMpUserBlackListServiceImpl implements WxMpUserBlackListService {
|
||||
private static final String API_BLACK_LIST_PREFIX = "https://api.weixin.qq.com/cgi-bin/tags/members";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpUserBlackListServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUserBlackListGetResult blackList(String nextOpenid) throws WxErrorException {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("begin_openid", nextOpenid);
|
||||
String url = API_BLACK_LIST_PREFIX + "/getblacklist";
|
||||
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, jsonObject.toString());
|
||||
return WxMpUserBlackListGetResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushToBlackList(List<String> openIdList) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("openid_list", openIdList);
|
||||
String url = API_BLACK_LIST_PREFIX + "/batchblacklist";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pullFromBlackList(List<String> openIdList) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("openid_list", openIdList);
|
||||
String url = API_BLACK_LIST_PREFIX + "/batchunblacklist";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url, new Gson().toJson(map));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user