mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-30 01:58:23 +08:00
抽取部分接口地址为常量
This commit is contained in:
@ -16,6 +16,13 @@ import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
|||||||
* @author chanjaster
|
* @author chanjaster
|
||||||
*/
|
*/
|
||||||
public interface WxCpService {
|
public interface WxCpService {
|
||||||
|
String GET_JSAPI_TICKET = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
|
||||||
|
String MESSAGE_SEND = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
|
||||||
|
String GET_CALLBACK_IP = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip";
|
||||||
|
String BATCH_REPLACE_PARTY = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty";
|
||||||
|
String BATCH_REPLACE_USER = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser";
|
||||||
|
String BATCH_GET_RESULT = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid=";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 验证推送过来的消息的正确性
|
* 验证推送过来的消息的正确性
|
||||||
|
|||||||
@ -36,6 +36,9 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
|
|||||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author chanjarster
|
||||||
|
*/
|
||||||
public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> {
|
public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
@ -99,8 +102,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
|||||||
if (this.configStorage.isJsapiTicketExpired()) {
|
if (this.configStorage.isJsapiTicketExpired()) {
|
||||||
synchronized (this.globalJsapiTicketRefreshLock) {
|
synchronized (this.globalJsapiTicketRefreshLock) {
|
||||||
if (this.configStorage.isJsapiTicketExpired()) {
|
if (this.configStorage.isJsapiTicketExpired()) {
|
||||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
|
String responseContent = execute(SimpleGetRequestExecutor.create(this), WxCpService.GET_JSAPI_TICKET, null);
|
||||||
String responseContent = execute(SimpleGetRequestExecutor.create(this), url, null);
|
|
||||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||||
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
|
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
|
||||||
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
|
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
|
||||||
@ -138,19 +140,17 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException {
|
public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException {
|
||||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
|
|
||||||
Integer agentId = message.getAgentId();
|
Integer agentId = message.getAgentId();
|
||||||
if (null == agentId) {
|
if (null == agentId) {
|
||||||
message.setAgentId(this.getWxCpConfigStorage().getAgentId());
|
message.setAgentId(this.getWxCpConfigStorage().getAgentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return WxCpMessageSendResult.fromJson(this.post(url, message.toJson()));
|
return WxCpMessageSendResult.fromJson(this.post(WxCpService.MESSAGE_SEND, message.toJson()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getCallbackIp() throws WxErrorException {
|
public String[] getCallbackIp() throws WxErrorException {
|
||||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip";
|
String responseContent = get(WxCpService.GET_CALLBACK_IP, null);
|
||||||
String responseContent = get(url, null);
|
|
||||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||||
JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
|
JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
|
||||||
String[] ips = new String[jsonArray.size()];
|
String[] ips = new String[jsonArray.size()];
|
||||||
@ -292,23 +292,21 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String replaceParty(String mediaId) throws WxErrorException {
|
public String replaceParty(String mediaId) throws WxErrorException {
|
||||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty";
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("media_id", mediaId);
|
jsonObject.addProperty("media_id", mediaId);
|
||||||
return post(url, jsonObject.toString());
|
return post(WxCpService.BATCH_REPLACE_PARTY, jsonObject.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String replaceUser(String mediaId) throws WxErrorException {
|
public String replaceUser(String mediaId) throws WxErrorException {
|
||||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser";
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("media_id", mediaId);
|
jsonObject.addProperty("media_id", mediaId);
|
||||||
return post(url, jsonObject.toString());
|
return post(WxCpService.BATCH_REPLACE_USER, jsonObject.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTaskResult(String joinId) throws WxErrorException {
|
public String getTaskResult(String joinId) throws WxErrorException {
|
||||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid=" + joinId;
|
String url = WxCpService.BATCH_GET_RESULT + joinId;
|
||||||
return get(url, null);
|
return get(url, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user