From 7538b8ec72e7fe26d71c0d53f21b33d4447a1b9d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 31 Mar 2019 16:07:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E9=83=A8=E5=88=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=9C=B0=E5=9D=80=E4=B8=BA=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/cp/api/WxCpService.java | 7 +++++++ .../cp/api/impl/BaseWxCpServiceImpl.java | 20 +++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index 64756dfb..c57f8e95 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -16,6 +16,13 @@ import me.chanjar.weixin.cp.config.WxCpConfigStorage; * @author chanjaster */ 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="; + /** *
    * 验证推送过来的消息的正确性
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
index e985e211..b8bcf666 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
@@ -36,6 +36,9 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
 import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
 import me.chanjar.weixin.cp.config.WxCpConfigStorage;
 
+/**
+ * @author chanjarster
+ */
 public abstract class BaseWxCpServiceImpl implements WxCpService, RequestHttp {
   protected final Logger log = LoggerFactory.getLogger(this.getClass());
 
@@ -99,8 +102,7 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH
     if (this.configStorage.isJsapiTicketExpired()) {
       synchronized (this.globalJsapiTicketRefreshLock) {
         if (this.configStorage.isJsapiTicketExpired()) {
-          String url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
-          String responseContent = execute(SimpleGetRequestExecutor.create(this), url, null);
+          String responseContent = execute(SimpleGetRequestExecutor.create(this), WxCpService.GET_JSAPI_TICKET, null);
           JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
           JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
           String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
@@ -138,19 +140,17 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH
 
   @Override
   public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException {
-    String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
     Integer agentId = message.getAgentId();
     if (null == agentId) {
       message.setAgentId(this.getWxCpConfigStorage().getAgentId());
     }
 
-    return WxCpMessageSendResult.fromJson(this.post(url, message.toJson()));
+    return WxCpMessageSendResult.fromJson(this.post(WxCpService.MESSAGE_SEND, message.toJson()));
   }
 
   @Override
   public String[] getCallbackIp() throws WxErrorException {
-    String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip";
-    String responseContent = get(url, null);
+    String responseContent = get(WxCpService.GET_CALLBACK_IP, null);
     JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
     JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
     String[] ips = new String[jsonArray.size()];
@@ -292,23 +292,21 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH
 
   @Override
   public String replaceParty(String mediaId) throws WxErrorException {
-    String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty";
     JsonObject jsonObject = new JsonObject();
     jsonObject.addProperty("media_id", mediaId);
-    return post(url, jsonObject.toString());
+    return post(WxCpService.BATCH_REPLACE_PARTY, jsonObject.toString());
   }
 
   @Override
   public String replaceUser(String mediaId) throws WxErrorException {
-    String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser";
     JsonObject jsonObject = new JsonObject();
     jsonObject.addProperty("media_id", mediaId);
-    return post(url, jsonObject.toString());
+    return post(WxCpService.BATCH_REPLACE_USER, jsonObject.toString());
   }
 
   @Override
   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);
   }