Date: Sun, 26 May 2019 17:03:50 +0800
Subject: [PATCH 03/74] =?UTF-8?q?#1053=20=E4=BC=81=E4=B8=9A=E5=BE=AE?=
=?UTF-8?q?=E4=BF=A1=E6=A0=B9=E6=8D=AEcode=E8=8E=B7=E5=8F=96=E6=88=90?=
=?UTF-8?q?=E5=91=98=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E?=
=?UTF-8?q?=E7=BB=93=E6=9E=9C=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../weixin/cp/api/WxCpOAuth2Service.java | 24 ++++++---
.../cp/api/impl/WxCpOAuth2ServiceImpl.java | 52 +++++++++----------
.../weixin/cp/bean/WxCpOauth2UserInfo.java | 28 ++++++++++
.../api/impl/WxCpOAuth2ServiceImplTest.java | 12 ++++-
.../weixin/cp/demo/WxCpOAuth2Servlet.java | 5 +-
5 files changed, 85 insertions(+), 36 deletions(-)
create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOauth2UserInfo.java
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
index 5f3d6daa82..c6d9063fbb 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
@@ -1,20 +1,25 @@
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
import me.chanjar.weixin.cp.bean.WxCpUserDetail;
/**
*
- * OAuth2相关管理接口
+ * OAuth2相关管理接口.
* Created by BinaryWang on 2017/6/24.
*
*
* @author Binary Wang
*/
public interface WxCpOAuth2Service {
+ String URL_GET_USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
+ String URL_GET_USER_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail";
+ String URL_OAUTH_2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
+
/**
*
- * 构造oauth2授权的url连接
+ * 构造oauth2授权的url连接.
*
*
* @param state 状态码
@@ -24,7 +29,7 @@ public interface WxCpOAuth2Service {
/**
*
- * 构造oauth2授权的url连接
+ * 构造oauth2授权的url连接.
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code
*
*
@@ -57,16 +62,18 @@ public interface WxCpOAuth2Service {
*
*
* @param code 微信oauth授权返回的代码
- * @return [userid, deviceid]
+ * @return WxCpOauth2UserInfo
+ * @throws WxErrorException 异常
* @see #getUserInfo(Integer, String)
*/
- String[] getUserInfo(String code) throws WxErrorException;
+ WxCpOauth2UserInfo getUserInfo(String code) throws WxErrorException;
/**
*
* 根据code获取成员信息
* http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
* https://work.weixin.qq.com/api/doc#10028/根据code获取成员信息
+ * https://work.weixin.qq.com/api/doc#90000/90135/91023 获取访问用户身份
* 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
@@ -74,10 +81,11 @@ public interface WxCpOAuth2Service {
*
* @param agentId 企业号应用的id
* @param code 通过成员授权获取到的code,最大为512字节。每次成员授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。
- * @return [UserId, DeviceId, OpenId, user_ticket, expires_in]
+ * @return WxCpOauth2UserInfo
+ * @throws WxErrorException 异常
* @see #getUserInfo(String)
*/
- String[] getUserInfo(Integer agentId, String code) throws WxErrorException;
+ WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErrorException;
/**
*
@@ -92,6 +100,8 @@ public interface WxCpOAuth2Service {
*
*
* @param userTicket 成员票据
+ * @return WxCpUserDetail
+ * @throws WxErrorException 异常
*/
WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException;
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
index 3507de0769..6ff91fc35a 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
@@ -3,30 +3,31 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
import me.chanjar.weixin.cp.bean.WxCpUserDetail;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.SNSAPI_PRIVATEINFO;
+import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.SNSAPI_USERINFO;
+
/**
*
- *
+ * oauth2相关接口实现类.
* Created by Binary Wang on 2017-6-25.
- * @author Binary Wang
- *
- * @author Binary Wang
*
+ *
+ * @author Binary Wang
*/
+@AllArgsConstructor
public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service {
- private WxCpService mainService;
-
- public WxCpOAuth2ServiceImpl(WxCpService mainService) {
- this.mainService = mainService;
- }
+ private final WxCpService mainService;
@Override
public String buildAuthorizationUrl(String state) {
@@ -43,50 +44,49 @@ public String buildAuthorizationUrl(String redirectUri, String state) {
@Override
public String buildAuthorizationUrl(String redirectUri, String state, String scope) {
- StringBuilder url = new StringBuilder("https://open.weixin.qq.com/connect/oauth2/authorize?");
- url.append("appid=").append(this.mainService.getWxCpConfigStorage().getCorpId());
+ StringBuilder url = new StringBuilder(WxCpOAuth2Service.URL_OAUTH_2_AUTHORIZE);
+ url.append("?appid=").append(this.mainService.getWxCpConfigStorage().getCorpId());
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectUri));
url.append("&response_type=code");
url.append("&scope=").append(scope);
- if (WxConsts.OAuth2Scope.SNSAPI_PRIVATEINFO.equals(scope)
- || WxConsts.OAuth2Scope.SNSAPI_USERINFO.equals(scope)) {
+ if (SNSAPI_PRIVATEINFO.equals(scope) || SNSAPI_USERINFO.equals(scope)) {
url.append("&agentid=").append(this.mainService.getWxCpConfigStorage().getAgentId());
}
if (state != null) {
url.append("&state=").append(state);
}
+
url.append("#wechat_redirect");
return url.toString();
}
@Override
- public String[] getUserInfo(String code) throws WxErrorException {
+ public WxCpOauth2UserInfo getUserInfo(String code) throws WxErrorException {
return this.getUserInfo(this.mainService.getWxCpConfigStorage().getAgentId(), code);
}
@Override
- public String[] getUserInfo(Integer agentId, String code) throws WxErrorException {
- String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=%s&agentid=%d",
- code, agentId);
- String responseText = this.mainService.get(url, null);
+ public WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErrorException {
+ String responseText = this.mainService.get(String.format(WxCpOAuth2Service.URL_GET_USER_INFO, code, agentId), null);
JsonElement je = new JsonParser().parse(responseText);
JsonObject jo = je.getAsJsonObject();
- return new String[]{GsonHelper.getString(jo, "UserId"),
- GsonHelper.getString(jo, "DeviceId"),
- GsonHelper.getString(jo, "OpenId"),
- GsonHelper.getString(jo, "user_ticket"),
- GsonHelper.getString(jo, "expires_in")
- };
+
+ return WxCpOauth2UserInfo.builder()
+ .userId(GsonHelper.getString(jo, "UserId"))
+ .deviceId(GsonHelper.getString(jo, "DeviceId"))
+ .openId(GsonHelper.getString(jo, "OpenId"))
+ .userTicket(GsonHelper.getString(jo, "user_ticket"))
+ .expiresIn(GsonHelper.getString(jo, "expires_in"))
+ .build();
}
@Override
public WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail";
JsonObject param = new JsonObject();
param.addProperty("user_ticket", userTicket);
- String responseText = this.mainService.post(url, param.toString());
+ String responseText = this.mainService.post(WxCpOAuth2Service.URL_GET_USER_DETAIL, param.toString());
return WxCpGsonBuilder.create().fromJson(responseText, WxCpUserDetail.class);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOauth2UserInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOauth2UserInfo.java
new file mode 100644
index 0000000000..9122f18d3a
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOauth2UserInfo.java
@@ -0,0 +1,28 @@
+package me.chanjar.weixin.cp.bean;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+/**
+ *
+ * 用oauth2获取用户信息的结果类
+ * Created by BinaryWang on 2019/5/26.
+ *
+ *
+ * @author Binary Wang
+ */
+@Data
+@Accessors(chain = true)
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class WxCpOauth2UserInfo {
+ private String openId;
+ private String deviceId;
+ private String userId;
+ private String userTicket;
+ private String expiresIn;
+}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImplTest.java
index 21801e4b42..4df8756334 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImplTest.java
@@ -4,10 +4,13 @@
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
import me.chanjar.weixin.cp.bean.WxCpUserDetail;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+
/**
*
* Created by BinaryWang on 2018/4/22.
@@ -28,6 +31,13 @@ public void testGetUserDetail() throws WxErrorException {
@Test
public void testGetUserInfo() throws WxErrorException {
- this.wxService.getOauth2Service().getUserInfo("abc");
+ final WxCpOauth2UserInfo result = this.wxService.getOauth2Service().getUserInfo("abc");
+ assertThat(result).isNotNull();
+ System.out.println(result);
}
+
+ @Test
+ public void testBuildAuthorizationUrl() {
+ }
+
}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java
index d652884b64..14d933da8a 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpOAuth2Servlet.java
@@ -2,6 +2,7 @@
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -30,9 +31,9 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
response.getWriter().println("code
");
response.getWriter().println(code);
- String[] res = this.wxCpService.getOauth2Service().getUserInfo(code);
+ WxCpOauth2UserInfo res = this.wxCpService.getOauth2Service().getUserInfo(code);
response.getWriter().println("result
");
- response.getWriter().println(Arrays.toString(res));
+ response.getWriter().println(res);
} catch (WxErrorException e) {
e.printStackTrace();
}
From e1b623906b864cdbd7091cb725504e7f6d57afe5 Mon Sep 17 00:00:00 2001
From: Binary Wang
Date: Sun, 26 May 2019 17:09:28 +0800
Subject: [PATCH 04/74] =?UTF-8?q?=E5=8F=91=E5=B8=833.4.1.B=E6=B5=8B?=
=?UTF-8?q?=E8=AF=95=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
starters/wx-java-mp-starter/pom.xml | 2 +-
starters/wx-java-pay-starter/pom.xml | 2 +-
weixin-java-common/pom.xml | 2 +-
weixin-java-cp/pom.xml | 2 +-
weixin-java-miniapp/pom.xml | 2 +-
weixin-java-mp/pom.xml | 2 +-
weixin-java-open/pom.xml | 2 +-
weixin-java-pay/pom.xml | 2 +-
9 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index 49ccee6520..07631b61b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
4.0.0
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
pom
WxJava - Weixin/Wechat Java SDK
微信开发Java SDK
diff --git a/starters/wx-java-mp-starter/pom.xml b/starters/wx-java-mp-starter/pom.xml
index 639662b8fe..2c276e94e2 100644
--- a/starters/wx-java-mp-starter/pom.xml
+++ b/starters/wx-java-mp-starter/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
../../
diff --git a/starters/wx-java-pay-starter/pom.xml b/starters/wx-java-pay-starter/pom.xml
index eba398b454..4201da5b76 100644
--- a/starters/wx-java-pay-starter/pom.xml
+++ b/starters/wx-java-pay-starter/pom.xml
@@ -5,7 +5,7 @@
wx-java
com.github.binarywang
- 3.4.0
+ 3.4.1.B
../../
4.0.0
diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml
index 7e5f54fefc..2ddba54d34 100644
--- a/weixin-java-common/pom.xml
+++ b/weixin-java-common/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
weixin-java-common
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index 09208eb329..8de47acac2 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
weixin-java-cp
diff --git a/weixin-java-miniapp/pom.xml b/weixin-java-miniapp/pom.xml
index de3c9f50df..3c7b511468 100644
--- a/weixin-java-miniapp/pom.xml
+++ b/weixin-java-miniapp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
weixin-java-miniapp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index ed8c7e75de..8bd9841711 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
weixin-java-mp
diff --git a/weixin-java-open/pom.xml b/weixin-java-open/pom.xml
index a624a38c7f..549aa5b4fa 100644
--- a/weixin-java-open/pom.xml
+++ b/weixin-java-open/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
weixin-java-open
diff --git a/weixin-java-pay/pom.xml b/weixin-java-pay/pom.xml
index a6130d13ee..115b07e286 100644
--- a/weixin-java-pay/pom.xml
+++ b/weixin-java-pay/pom.xml
@@ -5,7 +5,7 @@
com.github.binarywang
wx-java
- 3.4.0
+ 3.4.1.B
4.0.0
From 3465d538803eee981dabcd7e3bd51f9c0b1474e9 Mon Sep 17 00:00:00 2001
From: Xiaoyu Guo
Date: Tue, 28 May 2019 12:41:09 +0800
Subject: [PATCH 05/74] =?UTF-8?q?#1058=20=E5=85=AC=E4=BC=97=E5=8F=B7?=
=?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8A=A0=E5=85=A5=E8=AE=BE=E5=A4=87=E7=BB=91?=
=?UTF-8?q?=E5=AE=9A=E8=A7=A3=E7=BB=91=E6=B6=88=E6=81=AF=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-2
---
.../mp/bean/message/WxMpXmlMessage.java | 8 ++++
.../bean/message/WxMpXmlOutDeviceMessage.java | 36 ++++++++++++++
.../mp/bean/message/WxMpXmlOutMessage.java | 7 +++
.../mp/builder/outxml/DeviceBuilder.java | 48 +++++++++++++++++++
4 files changed, 99 insertions(+)
create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutDeviceMessage.java
create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/DeviceBuilder.java
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
index 368f70e383..ba6fd227be 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java
@@ -527,6 +527,14 @@ public class WxMpXmlMessage implements Serializable {
@XStreamAlias("DeviceID")
@XStreamConverter(value = XStreamCDataConverter.class)
private String deviceId;
+
+ /**
+ * 微信客户端生成的session id,用于request和response对应,
+ * 因此响应中该字段第三方需要原封不变的带回
+ */
+ @XStreamAlias("SessionID")
+ @XStreamConverter(value = XStreamCDataConverter.class)
+ private String sessionId;
/**
* 微信用户账号的OpenID.
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutDeviceMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutDeviceMessage.java
new file mode 100644
index 0000000000..b32935a106
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutDeviceMessage.java
@@ -0,0 +1,36 @@
+package me.chanjar.weixin.mp.bean.message;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamConverter;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
+
+@XStreamAlias("xml")
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class WxMpXmlOutDeviceMessage extends WxMpXmlOutMessage {
+ private static final long serialVersionUID = -3093843149649157587L;
+
+ @XStreamAlias("DeviceType")
+ @XStreamConverter(value = XStreamCDataConverter.class)
+ private String deviceType;
+
+ @XStreamAlias("DeviceID")
+ @XStreamConverter(value = XStreamCDataConverter.class)
+ private String deviceId;
+
+ @XStreamAlias("Content")
+ @XStreamConverter(value = XStreamCDataConverter.class)
+ private String content;
+
+ @XStreamAlias("SessionID")
+ @XStreamConverter(value = XStreamCDataConverter.class)
+ private String sessionId;
+
+ public WxMpXmlOutDeviceMessage() {
+ this.msgType = WxConsts.XmlMsgType.DEVICE_TEXT;
+ }
+}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java
index b1940fc487..74b053f17d 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlOutMessage.java
@@ -79,6 +79,13 @@ public static NewsBuilder NEWS() {
public static TransferCustomerServiceBuilder TRANSFER_CUSTOMER_SERVICE() {
return new TransferCustomerServiceBuilder();
}
+
+ /**
+ * 获得设备消息builder
+ */
+ public static DeviceBuilder DEVICE() {
+ return new DeviceBuilder();
+ }
@SuppressWarnings("unchecked")
public String toXml() {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/DeviceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/DeviceBuilder.java
new file mode 100644
index 0000000000..664c2e3a02
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/builder/outxml/DeviceBuilder.java
@@ -0,0 +1,48 @@
+package me.chanjar.weixin.mp.builder.outxml;
+
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutDeviceMessage;
+
+/**
+ * 设备消息 Builder
+ * @author biggates
+ * @see https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-2
+ */
+public final class DeviceBuilder extends BaseBuilder {
+
+ private String deviceId;
+ private String deviceType;
+ private String content;
+ private String sessionId;
+
+ public DeviceBuilder deviceType(String deviceType) {
+ this.deviceType = deviceType;
+ return this;
+ }
+
+ public DeviceBuilder deviceId(String deviceId) {
+ this.deviceId = deviceId;
+ return this;
+ }
+
+ public DeviceBuilder content(String content) {
+ this.content = content;
+ return this;
+ }
+
+ public DeviceBuilder sessionId(String sessionId) {
+ this.sessionId = sessionId;
+ return this;
+ }
+
+ @Override
+ public WxMpXmlOutDeviceMessage build() {
+ WxMpXmlOutDeviceMessage m = new WxMpXmlOutDeviceMessage();
+ setCommon(m);
+ m.setDeviceId(this.deviceId);
+ m.setDeviceType(this.deviceType);
+ m.setContent(this.content);
+ m.setSessionId(this.sessionId);
+ return m;
+ }
+
+}
From f67333a06ad464fb27c162b328d58ca5e037ea3a Mon Sep 17 00:00:00 2001
From: Binary Wang
Date: Sun, 2 Jun 2019 12:19:18 +0800
Subject: [PATCH 06/74] =?UTF-8?q?=E8=A7=84=E8=8C=83=E5=8C=96=E5=B9=B6?=
=?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../weixin/cp/api/WxCpAgentService.java | 3 +
.../weixin/cp/api/WxCpChatService.java | 36 +-
.../weixin/cp/api/WxCpDepartmentService.java | 4 +
.../weixin/cp/api/WxCpMenuService.java | 4 +
.../chanjar/weixin/cp/api/WxCpOAService.java | 66 ----
.../chanjar/weixin/cp/api/WxCpOaService.java | 68 ++++
.../me/chanjar/weixin/cp/api/WxCpService.java | 5 +-
.../chanjar/weixin/cp/api/WxCpTagService.java | 25 +-
.../weixin/cp/api/WxCpTaskCardService.java | 2 +
.../chanjar/weixin/cp/api/WxCpTpService.java | 342 +++++++++---------
.../weixin/cp/api/WxCpUserService.java | 13 +
.../cp/api/impl/BaseWxCpServiceImpl.java | 4 +-
.../cp/api/impl/WxCpAgentServiceImpl.java | 9 +-
.../cp/api/impl/WxCpChatServiceImpl.java | 2 +-
.../api/impl/WxCpDepartmentServiceImpl.java | 10 +-
.../cp/api/impl/WxCpMenuServiceImpl.java | 12 +-
...erviceImpl.java => WxCpOaServiceImpl.java} | 48 +--
.../impl/WxCpServiceApacheHttpClientImpl.java | 13 +-
.../cp/api/impl/WxCpServiceJoddHttpImpl.java | 10 +-
.../cp/api/impl/WxCpServiceOkHttpImpl.java | 51 +--
.../cp/api/impl/WxCpTagServiceImpl.java | 44 +--
.../cp/api/impl/WxCpTaskCardServiceImpl.java | 3 +-
.../WxCpTpServiceApacheHttpClientImpl.java | 228 ++++++------
.../cp/api/impl/WxCpUserServiceImpl.java | 43 +--
.../weixin/cp/bean/WxCpTagGetResult.java | 6 +-
.../cp/api/impl/WxCpAgentServiceImplTest.java | 3 +-
...plTest.java => WxCpOaServiceImplTest.java} | 2 +-
.../cp/api/impl/WxCpTagServiceImplTest.java | 9 +-
.../wxpay/bean/request/BaseWxPayRequest.java | 2 +
.../request/WxPayUnifiedOrderRequest.java | 2 +
30 files changed, 534 insertions(+), 535 deletions(-)
delete mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAService.java
create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
rename weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/{WxCpOAServiceImpl.java => WxCpOaServiceImpl.java} (71%)
rename weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/{WxCpOAServiceImplTest.java => WxCpOaServiceImplTest.java} (97%)
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
index feea8acbd1..30214a478f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
@@ -15,6 +15,9 @@
* @author huansinho
*/
public interface WxCpAgentService {
+ String GET_AGENT = "https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=%d";
+ String AGENT_SET = "https://qyapi.weixin.qq.com/cgi-bin/agent/set";
+ String AGENT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/agent/list";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
index 95f747e356..bbfc0fdd48 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
@@ -1,11 +1,11 @@
package me.chanjar.weixin.cp.api;
-import java.util.List;
-
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpAppChatMessage;
import me.chanjar.weixin.cp.bean.WxCpChat;
+import java.util.List;
+
/**
* 群聊服务.
*
@@ -15,6 +15,10 @@ public interface WxCpChatService {
String APPCHAT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/create";
String APPCHAT_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/update";
String APPCHAT_GET_CHATID = "https://qyapi.weixin.qq.com/cgi-bin/appchat/get?chatid=";
+ String APPCHAT_SEND = "https://qyapi.weixin.qq.com/cgi-bin/appchat/send";
+
+ @Deprecated
+ String chatCreate(String name, String owner, List users, String chatId) throws WxErrorException;
/**
* 创建群聊会话,注意:刚创建的群,如果没有下发消息,在企业微信不会出现该群.
@@ -24,15 +28,13 @@ public interface WxCpChatService {
* @param users 群成员id列表。至少2人,至多500人
* @param chatId 群聊的唯一标志,不能与已有的群重复;字符串类型,最长32个字符。只允许字符0-9及字母a-zA-Z。如果不填,系统会随机生成群id
* @return 创建的群聊会话chatId
- * @throws WxErrorException 发生异常
- */
- String chatCreate(String name, String owner, List users, String chatId) throws WxErrorException;
-
- /**
- * chatCreate 同名方法
+ * @throws WxErrorException 异常
*/
String create(String name, String owner, List users, String chatId) throws WxErrorException;
+ @Deprecated
+ void chatUpdate(String chatId, String name, String owner, List usersToAdd, List usersToDelete) throws WxErrorException;
+
/**
* 修改群聊会话.
*
@@ -41,26 +43,19 @@ public interface WxCpChatService {
* @param owner 新群主的id。若不需更新,请忽略此参数(null or empty)
* @param usersToAdd 添加成员的id列表,若不需要更新,则传递空对象或者空集合
* @param usersToDelete 踢出成员的id列表,若不需要更新,则传递空对象或者空集合
- * @throws WxErrorException 发生异常
- */
- void chatUpdate(String chatId, String name, String owner, List usersToAdd, List usersToDelete) throws WxErrorException;
-
- /**
- * chatUpdate 同名方法
+ * @throws WxErrorException 异常
*/
void update(String chatId, String name, String owner, List usersToAdd, List usersToDelete) throws WxErrorException;
+ @Deprecated
+ WxCpChat chatGet(String chatId) throws WxErrorException;
+
/**
* 获取群聊会话.
*
* @param chatId 群聊编号
* @return 群聊会话
- * @throws WxErrorException 发生异常
- */
- WxCpChat chatGet(String chatId) throws WxErrorException;
-
- /**
- * chatGet 同名方法
+ * @throws WxErrorException 异常
*/
WxCpChat get(String chatId) throws WxErrorException;
@@ -71,6 +66,7 @@ public interface WxCpChatService {
* 文档地址:https://work.weixin.qq.com/api/doc#90000/90135/90248
*
* @param message 要发送的消息内容对象
+ * @throws WxErrorException 异常
*/
void sendMsg(WxCpAppChatMessage message) throws WxErrorException;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
index 8af1d3041a..3f80d693ad 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
@@ -14,6 +14,10 @@
* @author Binary Wang
*/
public interface WxCpDepartmentService {
+ String DEPARTMENT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
+ String DEPARTMENT_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
+ String DEPARTMENT_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=%d";
+ String DEPARTMENT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
index 068c037a48..be7b4b7e55 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
@@ -12,6 +12,10 @@
* @author Binary Wang
*/
public interface WxCpMenuService {
+ String MENU_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=%d";
+ String MENU_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=%d";
+ String MENU_GET = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=%d";
+
/**
*
* 自定义菜单创建接口
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAService.java
deleted file mode 100644
index e8cf874eb6..0000000000
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAService.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package me.chanjar.weixin.cp.api;
-
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
-import me.chanjar.weixin.cp.bean.WxCpCheckinData;
-import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
-import me.chanjar.weixin.cp.bean.WxCpDialRecord;
-
-import java.util.Date;
-import java.util.List;
-
-/**
- * @author Element
- * @Package me.chanjar.weixin.cp.api
- * @date 2019-04-06 10:52
- * @Description:
- * 企业微信OA相关接口
- *
- *
- */
-public interface WxCpOAService {
-
- /**
- *
- * 获取打卡数据
- * API doc : https://work.weixin.qq.com/api/doc#90000/90135/90262
- *
- *
- * @param openCheckinDataType 打卡类型。1:上下班打卡;2:外出打卡;3:全部打卡
- * @param starttime 获取打卡记录的开始时间
- * @param endtime 获取打卡记录的结束时间
- * @param userIdList 需要获取打卡记录的用户列表
- */
- List getCheckinData(Integer openCheckinDataType, Date starttime, Date endtime, List userIdList) throws WxErrorException;
-
- /**
- *
- * 获取打卡规则
- * API doc : https://work.weixin.qq.com/api/doc#90000/90135/90263
- *
- *
- * @param datetime 需要获取规则的当天日期
- * @param userIdList 需要获取打卡规则的用户列表
- * @return
- * @throws WxErrorException
- */
- List getCheckinOption(Date datetime, List userIdList) throws WxErrorException;
-
- /**
- *
- * 获取审批数据
- * 通过本接口来获取公司一段时间内的审批记录。一次拉取调用最多拉取10000个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
- * API doc : https://work.weixin.qq.com/api/doc#90000/90135/91530
- *
- *
- * @param starttime 获取审批记录的开始时间
- * @param endtime 获取审批记录的结束时间
- * @param nextSpnum 第一个拉取的审批单号,不填从该时间段的第一个审批单拉取
- * @return
- * @throws WxErrorException
- */
- WxCpApprovalDataResult getApprovalData(Date starttime, Date endtime, Long nextSpnum) throws WxErrorException;
-
- List getDialRecord(Date starttime, Date endtime, Integer offset, Integer limit) throws WxErrorException;
-
-}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
new file mode 100644
index 0000000000..26922c0eee
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
@@ -0,0 +1,68 @@
+package me.chanjar.weixin.cp.api;
+
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
+import me.chanjar.weixin.cp.bean.WxCpCheckinData;
+import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
+import me.chanjar.weixin.cp.bean.WxCpDialRecord;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 企业微信OA相关接口.
+ *
+ * @author Element
+ * @date 2019-04-06 10:52
+ */
+public interface WxCpOaService {
+ String GET_CHECKIN_DATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata";
+ String GET_CHECKIN_OPTION = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption";
+ String GET_APPROVAL_DATA = "https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata";
+ String GET_DIAL_RECORD = "https://qyapi.weixin.qq.com/cgi-bin/dial/get_dial_record";
+
+ /**
+ *
+ * 获取打卡数据
+ * API doc : https://work.weixin.qq.com/api/doc#90000/90135/90262
+ *
+ *
+ * @param openCheckinDataType 打卡类型。1:上下班打卡;2:外出打卡;3:全部打卡
+ * @param startTime 获取打卡记录的开始时间
+ * @param endTime 获取打卡记录的结束时间
+ * @param userIdList 需要获取打卡记录的用户列表
+ * @return 打卡数据列表
+ * @throws WxErrorException 异常
+ */
+ List getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime, List userIdList) throws WxErrorException;
+
+ /**
+ *
+ * 获取打卡规则
+ * API doc : https://work.weixin.qq.com/api/doc#90000/90135/90263
+ *
+ *
+ * @param datetime 需要获取规则的当天日期
+ * @param userIdList 需要获取打卡规则的用户列表
+ * @return 打卡规则列表
+ * @throws WxErrorException 异常
+ */
+ List getCheckinOption(Date datetime, List userIdList) throws WxErrorException;
+
+ /**
+ *
+ * 获取审批数据
+ * 通过本接口来获取公司一段时间内的审批记录。一次拉取调用最多拉取10000个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
+ * API doc : https://work.weixin.qq.com/api/doc#90000/90135/91530
+ *
+ *
+ * @param startTime 获取审批记录的开始时间
+ * @param endTime 获取审批记录的结束时间
+ * @param nextSpnum 第一个拉取的审批单号,不填从该时间段的第一个审批单拉取
+ * @throws WxErrorException 异常
+ */
+ WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException;
+
+ List getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) throws WxErrorException;
+
+}
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 364723db87..13d2e9dc4a 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
@@ -13,7 +13,7 @@
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
/**
- * 微信API的Service
+ * 微信API的Service.
* @author chanjaster
*/
public interface WxCpService {
@@ -25,6 +25,7 @@ public interface WxCpService {
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=";
String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session";
+ String GET_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?&corpid=%s&corpsecret=%s";
/**
*
@@ -310,7 +311,7 @@ public interface WxCpService {
WxCpAgentService getAgentService();
- WxCpOAService getOAService();
+ WxCpOaService getOAService();
/**
* http请求对象
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
index 9624f9e409..a570a80b10 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
@@ -17,6 +17,14 @@
* @author Binary Wang
*/
public interface WxCpTagService {
+ String TAG_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/tag/create";
+ String TAG_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/tag/update";
+ String TAG_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?tagid=%s";
+ String TAG_LIST = "https://qyapi.weixin.qq.com/cgi-bin/tag/list";
+ String TAG_GET = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagid=%s";
+ String TAG_ADDTAGUSERS = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
+ String TAG_DELTAGUSERS = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
+
/**
* 创建标签.
*
@@ -51,6 +59,14 @@ public interface WxCpTagService {
*/
List listUsersByTagId(String tagId) throws WxErrorException;
+ /**
+ * 获取标签成员.
+ * 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
+ *
+ * @param tagId 标签id
+ */
+ WxCpTagGetResult get(String tagId) throws WxErrorException;
+
/**
* 增加标签成员.
*
@@ -69,13 +85,4 @@ public interface WxCpTagService {
*/
WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List userIds, List partyIds) throws WxErrorException;
-
- /**
- * 获取标签成员.
- * 对应: http://qydev.weixin.qq.com/wiki/index.php?title=管理标签 中的get接口
- *
- * @param tagId 标签id
- */
- WxCpTagGetResult get(String tagId) throws WxErrorException;
-
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
index 038c2dd3bf..1e1077014f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
@@ -14,6 +14,8 @@
* @date 2019-05-16
*/
public interface WxCpTaskCardService {
+ String MESSAGE_UPDATE_TASKCARD = "https://qyapi.weixin.qq.com/cgi-bin/message/update_taskcard";
+
/**
*
* 更新任务卡片消息状态
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
index 741d27de58..6e0d63fb2c 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
@@ -1,169 +1,173 @@
-package me.chanjar.weixin.cp.api;
-
-import me.chanjar.weixin.common.bean.WxAccessToken;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
-import me.chanjar.weixin.common.util.http.RequestExecutor;
-import me.chanjar.weixin.common.util.http.RequestHttp;
-import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
-import me.chanjar.weixin.cp.bean.WxCpTpCorp;
-import me.chanjar.weixin.cp.config.WxCpConfigStorage;
-import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
-
-/**
- * 微信第三方应用API的Service
- * @author zhenjun cai
- */
-public interface WxCpTpService {
- String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/miniprogram/jscode2session";
- String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token";
- String GET_PERMANENT_CODE = "https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code";
- /**
- *
- * 验证推送过来的消息的正确性
- * 详情请见: https://work.weixin.qq.com/api/doc#90000/90139/90968/消息体签名校验
- *
- *
- * @param msgSignature 消息签名
- * @param timestamp 时间戳
- * @param nonce 随机数
- * @param data 微信传输过来的数据,有可能是echoStr,有可能是xml消息
- */
- boolean checkSignature(String msgSignature, String timestamp, String nonce, String data);
-
- /**
- * 获取suite_access_token, 不强制刷新suite_access_token
- *
- * @see #getSuiteAccessToken(boolean)
- */
- String getSuiteAccessToken() throws WxErrorException;
-
- /**
- *
- * 获取suite_access_token,本方法线程安全
- * 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
- * 另:本service的所有方法都会在suite_access_token过期是调用此方法
- * 程序员在非必要情况下尽量不要主动调用此方法
- * 详情请见: https://work.weixin.qq.com/api/doc#90001/90143/90600
- *
- *
- * @param forceRefresh 强制刷新
- */
- String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException;
-
- /**
- * 获得suite_ticket,不强制刷新suite_ticket
- *
- * @see #getSuiteTicket(boolean)
- */
- String getSuiteTicket() throws WxErrorException;
-
- /**
- *
- * 获得suite_ticket
- * 由于suite_ticket是微信服务器定时推送(每10分钟),不能主动获取,如果碰到过期只能抛异常
- *
- * 详情请见:https://work.weixin.qq.com/api/doc#90001/90143/90628
- *
- *
- * @param forceRefresh 强制刷新
- */
- String getSuiteTicket(boolean forceRefresh) throws WxErrorException;
-
- /**
- * 小程序登录凭证校验
- *
- * @param jsCode 登录时获取的 code
- */
- WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException;
-
- /**
- * 获取企业凭证
- * @param authCorpid 授权方corpid
- * @param permanentCode 永久授权码,通过get_permanent_code获取
- */
- WxAccessToken getCorpToken(String authCorpid, String permanentCode) throws WxErrorException;
-
- /**
- * 获取企业永久授权码
- * @param authCode
- * @return
- */
- WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException;
-
- /**
- * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
- *
- * @param url 接口地址
- * @param queryParam 请求参数
- */
- String get(String url, String queryParam) throws WxErrorException;
-
- /**
- * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求
- *
- * @param url 接口地址
- * @param postData 请求body字符串
- */
- String post(String url, String postData) throws WxErrorException;
-
- /**
- *
- * Service没有实现某个API的时候,可以用这个,
- * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
- * 可以参考,{@link MediaUploadRequestExecutor}的实现方法
- *
- *
- * @param executor 执行器
- * @param uri 请求地址
- * @param data 参数
- * @param 请求值类型
- * @param 返回值类型
- */
- T execute(RequestExecutor executor, String uri, E data) throws WxErrorException;
-
- /**
- *
- * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
- * 默认:1000ms
- *
- *
- * @param retrySleepMillis 重试休息时间
- */
- void setRetrySleepMillis(int retrySleepMillis);
-
- /**
- *
- * 设置当微信系统响应系统繁忙时,最大重试次数
- * 默认:5次
- *
- *
- * @param maxRetryTimes 最大重试次数
- */
- void setMaxRetryTimes(int maxRetryTimes);
-
- /**
- * 初始化http请求对象
- */
- void initHttp();
-
- /**
- * 获取WxMpConfigStorage 对象
- *
- * @return WxMpConfigStorage
- */
- WxCpTpConfigStorage getWxCpTpConfigStorage();
-
- /**
- * 注入 {@link WxCpTpConfigStorage} 的实现
- *
- * @param wxConfigProvider 配置对象
- */
- void setWxCpTpConfigStorage(WxCpTpConfigStorage wxConfigProvider);
-
- /**
- * http请求对象
- */
- RequestHttp, ?> getRequestHttp();
-
-}
+package me.chanjar.weixin.cp.api;
+
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
+import me.chanjar.weixin.common.util.http.RequestExecutor;
+import me.chanjar.weixin.common.util.http.RequestHttp;
+import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
+import me.chanjar.weixin.cp.bean.WxCpTpCorp;
+import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
+
+/**
+ * 微信第三方应用API的Service.
+ *
+ * @author zhenjun cai
+ */
+public interface WxCpTpService {
+ String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/miniprogram/jscode2session";
+ String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token";
+ String GET_PERMANENT_CODE = "https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code";
+ String GET_SUITE_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token";
+
+ /**
+ *
+ * 验证推送过来的消息的正确性
+ * 详情请见: https://work.weixin.qq.com/api/doc#90000/90139/90968/消息体签名校验
+ *
+ *
+ * @param msgSignature 消息签名
+ * @param timestamp 时间戳
+ * @param nonce 随机数
+ * @param data 微信传输过来的数据,有可能是echoStr,有可能是xml消息
+ */
+ boolean checkSignature(String msgSignature, String timestamp, String nonce, String data);
+
+ /**
+ * 获取suite_access_token, 不强制刷新suite_access_token
+ *
+ * @see #getSuiteAccessToken(boolean)
+ */
+ String getSuiteAccessToken() throws WxErrorException;
+
+ /**
+ *
+ * 获取suite_access_token,本方法线程安全
+ * 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
+ * 另:本service的所有方法都会在suite_access_token过期是调用此方法
+ * 程序员在非必要情况下尽量不要主动调用此方法
+ * 详情请见: https://work.weixin.qq.com/api/doc#90001/90143/90600
+ *
+ *
+ * @param forceRefresh 强制刷新
+ */
+ String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException;
+
+ /**
+ * 获得suite_ticket,不强制刷新suite_ticket
+ *
+ * @see #getSuiteTicket(boolean)
+ */
+ String getSuiteTicket() throws WxErrorException;
+
+ /**
+ *
+ * 获得suite_ticket
+ * 由于suite_ticket是微信服务器定时推送(每10分钟),不能主动获取,如果碰到过期只能抛异常
+ *
+ * 详情请见:https://work.weixin.qq.com/api/doc#90001/90143/90628
+ *
+ *
+ * @param forceRefresh 强制刷新
+ */
+ String getSuiteTicket(boolean forceRefresh) throws WxErrorException;
+
+ /**
+ * 小程序登录凭证校验
+ *
+ * @param jsCode 登录时获取的 code
+ */
+ WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException;
+
+ /**
+ * 获取企业凭证
+ *
+ * @param authCorpid 授权方corpid
+ * @param permanentCode 永久授权码,通过get_permanent_code获取
+ */
+ WxAccessToken getCorpToken(String authCorpid, String permanentCode) throws WxErrorException;
+
+ /**
+ * 获取企业永久授权码
+ *
+ * @param authCode
+ * @return
+ */
+ WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException;
+
+ /**
+ * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
+ *
+ * @param url 接口地址
+ * @param queryParam 请求参数
+ */
+ String get(String url, String queryParam) throws WxErrorException;
+
+ /**
+ * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求
+ *
+ * @param url 接口地址
+ * @param postData 请求body字符串
+ */
+ String post(String url, String postData) throws WxErrorException;
+
+ /**
+ *
+ * Service没有实现某个API的时候,可以用这个,
+ * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
+ * 可以参考,{@link MediaUploadRequestExecutor}的实现方法
+ *
+ *
+ * @param executor 执行器
+ * @param uri 请求地址
+ * @param data 参数
+ * @param 请求值类型
+ * @param 返回值类型
+ */
+ T execute(RequestExecutor executor, String uri, E data) throws WxErrorException;
+
+ /**
+ *
+ * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
+ * 默认:1000ms
+ *
+ *
+ * @param retrySleepMillis 重试休息时间
+ */
+ void setRetrySleepMillis(int retrySleepMillis);
+
+ /**
+ *
+ * 设置当微信系统响应系统繁忙时,最大重试次数
+ * 默认:5次
+ *
+ *
+ * @param maxRetryTimes 最大重试次数
+ */
+ void setMaxRetryTimes(int maxRetryTimes);
+
+ /**
+ * 初始化http请求对象
+ */
+ void initHttp();
+
+ /**
+ * 获取WxMpConfigStorage 对象
+ *
+ * @return WxMpConfigStorage
+ */
+ WxCpTpConfigStorage getWxCpTpConfigStorage();
+
+ /**
+ * 注入 {@link WxCpTpConfigStorage} 的实现
+ *
+ * @param wxConfigProvider 配置对象
+ */
+ void setWxCpTpConfigStorage(WxCpTpConfigStorage wxConfigProvider);
+
+ /**
+ * http请求对象
+ */
+ RequestHttp, ?> getRequestHttp();
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
index 310a1efa5e..091c687595 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
@@ -17,6 +17,19 @@
* @author Binary Wang
*/
public interface WxCpUserService {
+ String URL_AUTHENTICATE = "https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?userid=";
+ String URL_USER_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/user/create";
+ String URL_USER_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/user/update";
+ String URL_USER_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?userid=";
+ String URL_USER_BATCH_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
+ String URL_USER_GET = "https://qyapi.weixin.qq.com/cgi-bin/user/get?userid=";
+ String URL_USER_LIST = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=";
+ String URL_USER_SIMPLE_LIST = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=";
+ String URL_BATCH_INVITE = "https://qyapi.weixin.qq.com/cgi-bin/batch/invite";
+ String URL_CONVERT_TO_OPENID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid";
+ String URL_CONVERT_TO_USERID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid";
+ String URL_GET_EXTERNAL_CONTACT = "https://qyapi.weixin.qq.com/cgi-bin/crm/get_external_contact?external_userid=";
+
/**
*
* 用在二次验证的时候.
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 3eb99b79d2..d9c88b47a5 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
@@ -45,7 +45,7 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH
private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
private WxCpTagService tagService = new WxCpTagServiceImpl(this);
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
- private WxCpOAService oaService = new WxCpOAServiceImpl(this);
+ private WxCpOaService oaService = new WxCpOaServiceImpl(this);
private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
/**
@@ -389,7 +389,7 @@ public WxCpChatService getChatService() {
}
@Override
- public WxCpOAService getOAService() {
+ public WxCpOaService getOAService() {
return oaService;
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
index 3a977b81d8..10c417729e 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
@@ -37,15 +37,13 @@ public WxCpAgent get(Integer agentId) throws WxErrorException {
throw new IllegalArgumentException("缺少agentid参数");
}
- String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=" + agentId;
- String responseContent = this.mainService.get(url, null);
+ String responseContent = this.mainService.get(String.format(WxCpAgentService.GET_AGENT, agentId), null);
return WxCpAgent.fromJson(responseContent);
}
@Override
public void set(WxCpAgent agentInfo) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/set";
- String responseContent = this.mainService.post(url, agentInfo.toJson());
+ String responseContent = this.mainService.post(WxCpAgentService.AGENT_SET, agentInfo.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
@@ -54,8 +52,7 @@ public void set(WxCpAgent agentInfo) throws WxErrorException {
@Override
public List list() throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/list";
- String responseContent = this.mainService.get(url, null);
+ String responseContent = this.mainService.get(WxCpAgentService.AGENT_LIST, null);
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
index 05d298c9ad..0b1fb59381 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
@@ -98,7 +98,7 @@ public WxCpChat get(String chatId) throws WxErrorException {
@Override
public void sendMsg(WxCpAppChatMessage message) throws WxErrorException {
- this.cpService.post("https://qyapi.weixin.qq.com/cgi-bin/appchat/send", message.toJson());
+ this.cpService.post(WxCpChatService.APPCHAT_SEND, message.toJson());
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
index 481115fa51..09ded1b8b3 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
@@ -29,27 +29,25 @@ public WxCpDepartmentServiceImpl(WxCpService mainService) {
@Override
public Long create(WxCpDepart depart) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
- String responseContent = this.mainService.post(url, depart.toJson());
+ String responseContent = this.mainService.post(WxCpDepartmentService.DEPARTMENT_CREATE, depart.toJson());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("id"));
}
@Override
public void update(WxCpDepart group) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
- this.mainService.post(url, group.toJson());
+ this.mainService.post(WxCpDepartmentService.DEPARTMENT_UPDATE, group.toJson());
}
@Override
public void delete(Long departId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=" + departId;
+ String url = String.format(WxCpDepartmentService.DEPARTMENT_DELETE, departId);
this.mainService.get(url, null);
}
@Override
public List list(Long id) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
+ String url = WxCpDepartmentService.DEPARTMENT_LIST;
if (id != null) {
url += "?id=" + id;
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
index f58eff4763..d33ade0191 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
@@ -8,10 +8,11 @@
/**
*
- * 菜单管理相关接口
+ * 菜单管理相关接口.
* Created by Binary Wang on 2017-6-25.
- * @author Binary Wang
*
+ *
+ * @author Binary Wang
*/
public class WxCpMenuServiceImpl implements WxCpMenuService {
private WxCpService mainService;
@@ -27,8 +28,7 @@ public void create(WxMenu menu) throws WxErrorException {
@Override
public void create(Integer agentId, WxMenu menu) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=" + agentId;
- this.mainService.post(url, menu.toJson());
+ this.mainService.post(String.format(WxCpMenuService.MENU_CREATE, agentId), menu.toJson());
}
@Override
@@ -38,7 +38,7 @@ public void delete() throws WxErrorException {
@Override
public void delete(Integer agentId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=" + agentId;
+ String url = String.format(WxCpMenuService.MENU_DELETE, agentId);
this.mainService.get(url, null);
}
@@ -49,7 +49,7 @@ public WxMenu get() throws WxErrorException {
@Override
public WxMenu get(Integer agentId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + agentId;
+ String url = String.format(WxCpMenuService.MENU_GET, agentId);
try {
String resultContent = this.mainService.get(url, null);
return WxCpGsonBuilder.create().fromJson(resultContent, WxMenu.class);
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
similarity index 71%
rename from weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAServiceImpl.java
rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
index 2d1ca6ab0b..cc3b274495 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
@@ -6,7 +6,7 @@
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.api.WxCpOAService;
+import me.chanjar.weixin.cp.api.WxCpOaService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
@@ -19,22 +19,19 @@
/**
* @author Element
- * @Package me.chanjar.weixin.cp.api.impl
* @date 2019-04-06 11:20
- * @Description: TODO
*/
-public class WxCpOAServiceImpl implements WxCpOAService {
-
+public class WxCpOaServiceImpl implements WxCpOaService {
private WxCpService mainService;
- public WxCpOAServiceImpl(WxCpService mainService) {
+ public WxCpOaServiceImpl(WxCpService mainService) {
this.mainService = mainService;
}
@Override
- public List getCheckinData(Integer openCheckinDataType, Date starttime, Date endtime, List userIdList) throws WxErrorException {
+ public List getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime, List userIdList) throws WxErrorException {
- if (starttime == null || endtime == null) {
+ if (startTime == null || endTime == null) {
throw new RuntimeException("starttime and endtime can't be null");
}
@@ -42,15 +39,13 @@ public List getCheckinData(Integer openCheckinDataType, Date st
throw new RuntimeException("用户列表不能为空,不超过100个,若用户超过100个,请分批获取");
}
- long endtimestamp = endtime.getTime() / 1000L;
- long starttimestamp = starttime.getTime() / 1000L;
+ long endtimestamp = endTime.getTime() / 1000L;
+ long starttimestamp = startTime.getTime() / 1000L;
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60) {
throw new RuntimeException("获取记录时间跨度不超过一个月");
}
- String url = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata";
-
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
@@ -64,7 +59,7 @@ public List getCheckinData(Integer openCheckinDataType, Date st
jsonObject.add("useridlist", jsonArray);
- String responseContent = this.mainService.post(url, jsonObject.toString());
+ String responseContent = this.mainService.post(WxCpOaService.GET_CHECKIN_DATA, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -76,7 +71,6 @@ public List getCheckinData(Integer openCheckinDataType, Date st
@Override
public List getCheckinOption(Date datetime, List userIdList) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption";
if (datetime == null) {
throw new RuntimeException("datetime can't be null");
}
@@ -94,7 +88,7 @@ public List getCheckinOption(Date datetime, List user
jsonObject.addProperty("datetime", datetime.getTime() / 1000L);
jsonObject.add("useridlist", jsonArray);
- String responseContent = this.mainService.post(url, jsonObject.toString());
+ String responseContent = this.mainService.post(WxCpOaService.GET_CHECKIN_OPTION, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
@@ -106,24 +100,20 @@ public List getCheckinOption(Date datetime, List user
}
@Override
- public WxCpApprovalDataResult getApprovalData(Date starttime, Date endtime, Long nextSpnum) throws WxErrorException {
-
- String url = "https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata";
+ public WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("starttime", starttime.getTime() / 1000L);
- jsonObject.addProperty("endtime", endtime.getTime() / 1000L);
+ jsonObject.addProperty("starttime", startTime.getTime() / 1000L);
+ jsonObject.addProperty("endtime", endTime.getTime() / 1000L);
if (nextSpnum != null) {
jsonObject.addProperty("next_spnum", nextSpnum);
}
- String responseContent = this.mainService.post(url, jsonObject.toString());
+ String responseContent = this.mainService.post(WxCpOaService.GET_APPROVAL_DATA, jsonObject.toString());
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class);
}
@Override
- public List getDialRecord(Date starttime, Date endtime, Integer offset, Integer limit) throws WxErrorException {
-
- String url = "https://qyapi.weixin.qq.com/cgi-bin/dial/get_dial_record";
+ public List getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
if (offset == null) {
@@ -137,10 +127,10 @@ public List getDialRecord(Date starttime, Date endtime, Integer
jsonObject.addProperty("offset", offset);
jsonObject.addProperty("limit", limit);
- if (starttime != null && endtime != null) {
+ if (startTime != null && endTime != null) {
- long endtimestamp = endtime.getTime() / 1000L;
- long starttimestamp = starttime.getTime() / 1000L;
+ long endtimestamp = endTime.getTime() / 1000L;
+ long starttimestamp = startTime.getTime() / 1000L;
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60) {
throw new RuntimeException("受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询");
@@ -148,11 +138,9 @@ public List getDialRecord(Date starttime, Date endtime, Integer
jsonObject.addProperty("start_time", starttimestamp);
jsonObject.addProperty("end_time", endtimestamp);
-
-
}
- String responseContent = this.mainService.post(url, jsonObject.toString());
+ String responseContent = this.mainService.post(WxCpOaService.GET_DIAL_RECORD, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
index 86e237168d..11a183b507 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
@@ -8,7 +8,7 @@
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
-import me.chanjar.weixin.cp.api.WxCpOAService;
+import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
@@ -19,6 +19,9 @@
import java.io.IOException;
+/**
+ * @author someone
+ */
public class WxCpServiceApacheHttpClientImpl extends BaseWxCpServiceImpl {
protected CloseableHttpClient httpClient;
protected HttpHost httpProxy;
@@ -45,9 +48,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
synchronized (this.globalAccessTokenRefreshLock) {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
- + "&corpid=" + this.configStorage.getCorpId()
- + "&corpsecret=" + this.configStorage.getCorpSecret();
+ String url = String.format(WxCpService.GET_TOKEN, this.configStorage.getCorpId(), this.configStorage.getCorpSecret());
try {
HttpGet httpGet = new HttpGet(url);
if (this.httpProxy != null) {
@@ -56,8 +57,8 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
httpGet.setConfig(config);
}
String resultContent;
- try (CloseableHttpClient httpclient = getRequestHttpClient();
- CloseableHttpResponse response = httpclient.execute(httpGet)) {
+ try (CloseableHttpClient httpClient = getRequestHttpClient();
+ CloseableHttpResponse response = httpClient.execute(httpGet)) {
resultContent = new BasicResponseHandler().handleResponse(response);
} finally {
httpGet.releaseConnection();
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
index 3603a59b17..d5d08900b9 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
@@ -6,8 +6,12 @@
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType;
+import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
+/**
+ * @author someone
+ */
public class WxCpServiceJoddHttpImpl extends BaseWxCpServiceImpl {
protected HttpConnectionProvider httpClient;
protected ProxyInfo httpProxy;
@@ -35,11 +39,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
synchronized (this.globalAccessTokenRefreshLock) {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
- + "&corpid=" + this.configStorage.getCorpId()
- + "&corpsecret=" + this.configStorage.getCorpSecret();
-
- HttpRequest request = HttpRequest.get(url);
+ HttpRequest request = HttpRequest.get(String.format(WxCpService.GET_TOKEN, this.configStorage.getCorpId(), this.configStorage.getCorpSecret()));
if (this.httpProxy != null) {
httpClient.useProxy(this.httpProxy);
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
index 9163ce03a6..f4cc540f3c 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
@@ -6,15 +6,18 @@
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
+import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import okhttp3.*;
import java.io.IOException;
+/**
+ * @author someone
+ */
public class WxCpServiceOkHttpImpl extends BaseWxCpServiceImpl {
- protected OkHttpClient httpClient;
- protected OkHttpProxyInfo httpProxy;
-
+ private OkHttpClient httpClient;
+ private OkHttpProxyInfo httpProxy;
@Override
public OkHttpClient getRequestHttpClient() {
@@ -38,28 +41,28 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
synchronized (this.globalAccessTokenRefreshLock) {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
- + "&corpid=" + this.configStorage.getCorpId()
- + "&corpsecret=" + this.configStorage.getCorpSecret();
- //得到httpClient
- OkHttpClient client = getRequestHttpClient();
- //请求的request
- Request request = new Request.Builder().url(url).get().build();
- String resultContent = null;
- try {
- Response response = client.newCall(request).execute();
- resultContent = response.body().string();
- } catch (IOException e) {
- this.log.error(e.getMessage(), e);
- }
+ //得到httpClient
+ OkHttpClient client = getRequestHttpClient();
+ //请求的request
+ Request request = new Request.Builder()
+ .url(String.format(WxCpService.GET_TOKEN, this.configStorage.getCorpId(), this.configStorage.getCorpSecret()))
+ .get()
+ .build();
+ String resultContent = null;
+ try {
+ Response response = client.newCall(request).execute();
+ resultContent = response.body().string();
+ } catch (IOException e) {
+ this.log.error(e.getMessage(), e);
+ }
- WxError error = WxError.fromJson(resultContent, WxType.CP);
- if (error.getErrorCode() != 0) {
- throw new WxErrorException(error);
- }
- WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
- this.configStorage.updateAccessToken(accessToken.getAccessToken(),
- accessToken.getExpiresIn());
+ WxError error = WxError.fromJson(resultContent, WxType.CP);
+ if (error.getErrorCode() != 0) {
+ throw new WxErrorException(error);
+ }
+ WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
+ this.configStorage.updateAccessToken(accessToken.getAccessToken(),
+ accessToken.getExpiresIn());
}
return this.configStorage.getAccessToken();
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java
index 22bb0fcf96..413436207f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java
@@ -1,12 +1,6 @@
package me.chanjar.weixin.cp.api.impl;
-import java.util.List;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
+import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
@@ -17,12 +11,15 @@
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import java.util.List;
+
/**
*
- * 标签管理接口
+ * 标签管理接口.
* Created by Binary Wang on 2017-6-25.
- * @author Binary Wang
*
+ *
+ * @author Binary Wang
*/
public class WxCpTagServiceImpl implements WxCpTagService {
private WxCpService mainService;
@@ -33,33 +30,29 @@ public WxCpTagServiceImpl(WxCpService mainService) {
@Override
public String create(String tagName) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/create";
JsonObject o = new JsonObject();
o.addProperty("tagname", tagName);
- String responseContent = this.mainService.post(url, o.toString());
+ String responseContent = this.mainService.post(WxCpTagService.TAG_CREATE, o.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
}
@Override
public void update(String tagId, String tagName) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/update";
JsonObject o = new JsonObject();
o.addProperty("tagid", tagId);
o.addProperty("tagname", tagName);
- this.mainService.post(url, o.toString());
+ this.mainService.post(WxCpTagService.TAG_UPDATE, o.toString());
}
@Override
public void delete(String tagId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?tagid=" + tagId;
- this.mainService.get(url, null);
+ this.mainService.get(String.format(WxCpTagService.TAG_DELETE, tagId), null);
}
@Override
public List listAll() throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/list";
- String responseContent = this.mainService.get(url, null);
+ String responseContent = this.mainService.get(WxCpTagService.TAG_LIST, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -71,8 +64,7 @@ public List listAll() throws WxErrorException {
@Override
public List listUsersByTagId(String tagId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagid=" + tagId;
- String responseContent = this.mainService.get(url, null);
+ String responseContent = this.mainService.get(String.format(WxCpTagService.TAG_GET, tagId), null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -84,22 +76,20 @@ public List listUsersByTagId(String tagId) throws WxErrorException {
@Override
public WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List userIds, List partyIds) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tagid", tagId);
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
- return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
+ return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(WxCpTagService.TAG_ADDTAGUSERS, jsonObject.toString()));
}
@Override
public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List userIds, List partyIds) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tagid", tagId);
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
- return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
+ return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(WxCpTagService.TAG_DELTAGUSERS, jsonObject.toString()));
}
private void addUserIdsAndPartyIdsToJson(List userIds, List partyIds, JsonObject jsonObject) {
@@ -122,15 +112,11 @@ private void addUserIdsAndPartyIdsToJson(List userIds, List part
@Override
public WxCpTagGetResult get(String tagId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get";
- if (tagId != null) {
- url += "?tagId=" + tagId;
- } else {
+ if (tagId == null) {
throw new IllegalArgumentException("缺少tagId参数");
}
- String responseContent = this.mainService.get(url, null);
-
+ String responseContent = this.mainService.get(String.format(WxCpTagService.TAG_GET, tagId), null);
return WxCpTagGetResult.fromJson(responseContent);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java
index 3011320d50..e70a7d376a 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java
@@ -33,7 +33,6 @@ public void update(List userIds, String taskId, String clickedKey) throw
data.put("task_id", taskId);
data.put("clicked_key", clickedKey);
- String url = "https://qyapi.weixin.qq.com/cgi-bin/message/update_taskcard";
- this.mainService.post(url, WxGsonBuilder.create().toJson(data));
+ this.mainService.post(MESSAGE_UPDATE_TASKCARD, WxGsonBuilder.create().toJson(data));
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java
index 0b8a134d48..f673a622bd 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java
@@ -1,114 +1,114 @@
-package me.chanjar.weixin.cp.api.impl;
-
-
-import java.io.IOException;
-
-import org.apache.http.Consts;
-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.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
-
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-
-import me.chanjar.weixin.common.WxType;
-import me.chanjar.weixin.common.error.WxError;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.common.util.http.HttpType;
-import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
-import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
-import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
-
-public class WxCpTpServiceApacheHttpClientImpl extends BaseWxCpTpServiceImpl {
- protected CloseableHttpClient httpClient;
- protected HttpHost httpProxy;
-
- @Override
- public CloseableHttpClient getRequestHttpClient() {
- return httpClient;
- }
-
- @Override
- public HttpHost getRequestHttpProxy() {
- return httpProxy;
- }
-
- @Override
- public HttpType getRequestType() {
- return HttpType.APACHE_HTTP;
- }
-
- @Override
- public String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException {
- if (!this.configStorage.isSuiteAccessTokenExpired() && !forceRefresh) {
- return this.configStorage.getSuiteAccessToken();
- }
-
- synchronized (this.globalSuiteAccessTokenRefreshLock) {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token";
- try {
- HttpPost httpPost = new HttpPost(url);
- if (this.httpProxy != null) {
- RequestConfig config = RequestConfig.custom()
- .setProxy(this.httpProxy).build();
- httpPost.setConfig(config);
- }
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("suite_id", this.configStorage.getSuiteId());
- jsonObject.addProperty("suite_secret", this.configStorage.getSuiteSecret());
- jsonObject.addProperty("suite_ticket", this.getSuiteTicket());
- StringEntity entity = new StringEntity(jsonObject.toString(), Consts.UTF_8);
- httpPost.setEntity(entity);
-
- String resultContent;
- try (CloseableHttpClient httpclient = getRequestHttpClient();
- CloseableHttpResponse response = httpclient.execute(httpPost)) {
- resultContent = new BasicResponseHandler().handleResponse(response);
- } finally {
- httpPost.releaseConnection();
- }
- WxError error = WxError.fromJson(resultContent, WxType.CP);
- if (error.getErrorCode() != 0) {
- throw new WxErrorException(error);
- }
- jsonObject = new JsonParser().parse(resultContent).getAsJsonObject();
- String suiteAccussToken = jsonObject.get("suite_access_token").getAsString();
- Integer expiresIn = jsonObject.get("expires_in").getAsInt();
- this.configStorage.updateSuiteAccessToken(suiteAccussToken, expiresIn);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return this.configStorage.getSuiteAccessToken();
- }
-
- @Override
- public void initHttp() {
- ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
- .getApacheHttpClientBuilder();
- if (null == apacheHttpClientBuilder) {
- apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
- }
-
- apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
- .httpProxyPort(this.configStorage.getHttpProxyPort())
- .httpProxyUsername(this.configStorage.getHttpProxyUsername())
- .httpProxyPassword(this.configStorage.getHttpProxyPassword());
-
- if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
- this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
- }
-
- this.httpClient = apacheHttpClientBuilder.build();
- }
-
- @Override
- public WxCpTpConfigStorage getWxCpTpConfigStorage() {
- return this.configStorage;
- }
-
-}
+package me.chanjar.weixin.cp.api.impl;
+
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import me.chanjar.weixin.common.WxType;
+import me.chanjar.weixin.common.error.WxError;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.util.http.HttpType;
+import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
+import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
+import me.chanjar.weixin.cp.api.WxCpTpService;
+import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
+import org.apache.http.Consts;
+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.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import java.io.IOException;
+
+/**
+ * @author someone
+ */
+public class WxCpTpServiceApacheHttpClientImpl extends BaseWxCpTpServiceImpl {
+ private CloseableHttpClient httpClient;
+ private HttpHost httpProxy;
+
+ @Override
+ public CloseableHttpClient getRequestHttpClient() {
+ return httpClient;
+ }
+
+ @Override
+ public HttpHost getRequestHttpProxy() {
+ return httpProxy;
+ }
+
+ @Override
+ public HttpType getRequestType() {
+ return HttpType.APACHE_HTTP;
+ }
+
+ @Override
+ public String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException {
+ if (!this.configStorage.isSuiteAccessTokenExpired() && !forceRefresh) {
+ return this.configStorage.getSuiteAccessToken();
+ }
+
+ synchronized (this.globalSuiteAccessTokenRefreshLock) {
+ try {
+ HttpPost httpPost = new HttpPost(WxCpTpService.GET_SUITE_TOKEN);
+ if (this.httpProxy != null) {
+ RequestConfig config = RequestConfig.custom()
+ .setProxy(this.httpProxy).build();
+ httpPost.setConfig(config);
+ }
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("suite_id", this.configStorage.getSuiteId());
+ jsonObject.addProperty("suite_secret", this.configStorage.getSuiteSecret());
+ jsonObject.addProperty("suite_ticket", this.getSuiteTicket());
+ StringEntity entity = new StringEntity(jsonObject.toString(), Consts.UTF_8);
+ httpPost.setEntity(entity);
+
+ String resultContent;
+ try (CloseableHttpClient httpclient = getRequestHttpClient();
+ CloseableHttpResponse response = httpclient.execute(httpPost)) {
+ resultContent = new BasicResponseHandler().handleResponse(response);
+ } finally {
+ httpPost.releaseConnection();
+ }
+ WxError error = WxError.fromJson(resultContent, WxType.CP);
+ if (error.getErrorCode() != 0) {
+ throw new WxErrorException(error);
+ }
+ jsonObject = new JsonParser().parse(resultContent).getAsJsonObject();
+ String suiteAccussToken = jsonObject.get("suite_access_token").getAsString();
+ Integer expiresIn = jsonObject.get("expires_in").getAsInt();
+ this.configStorage.updateSuiteAccessToken(suiteAccussToken, expiresIn);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return this.configStorage.getSuiteAccessToken();
+ }
+
+ @Override
+ public void initHttp() {
+ ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage.getApacheHttpClientBuilder();
+ if (null == apacheHttpClientBuilder) {
+ apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
+ }
+
+ apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
+ .httpProxyPort(this.configStorage.getHttpProxyPort())
+ .httpProxyUsername(this.configStorage.getHttpProxyUsername())
+ .httpProxyPassword(this.configStorage.getHttpProxyPassword());
+
+ if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
+ this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
+ }
+
+ this.httpClient = apacheHttpClientBuilder.build();
+ }
+
+ @Override
+ public WxCpTpConfigStorage getWxCpTpConfigStorage() {
+ return this.configStorage;
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
index 84a16f3496..b3b0909522 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
@@ -26,7 +26,7 @@
* @author Binary Wang
*/
public class WxCpUserServiceImpl implements WxCpUserService {
- private WxCpService mainService;
+ private final WxCpService mainService;
public WxCpUserServiceImpl(WxCpService mainService) {
this.mainService = mainService;
@@ -34,50 +34,44 @@ public WxCpUserServiceImpl(WxCpService mainService) {
@Override
public void authenticate(String userId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?userid=" + userId;
- this.mainService.get(url, null);
+ this.mainService.get(WxCpUserService.URL_AUTHENTICATE + userId, null);
}
@Override
public void create(WxCpUser user) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/create";
- this.mainService.post(url, user.toJson());
+ this.mainService.post(WxCpUserService.URL_USER_CREATE, user.toJson());
}
@Override
public void update(WxCpUser user) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/update";
- this.mainService.post(url, user.toJson());
+ this.mainService.post(WxCpUserService.URL_USER_UPDATE, user.toJson());
}
@Override
public void delete(String... userIds) throws WxErrorException {
if (userIds.length == 1) {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?userid=" + userIds[0];
- this.mainService.get(url, null);
+ this.mainService.get(WxCpUserService.URL_USER_DELETE + userIds[0], null);
return;
}
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
- for (String userid : userIds) {
- jsonArray.add(new JsonPrimitive(userid));
+ for (String userId : userIds) {
+ jsonArray.add(new JsonPrimitive(userId));
}
+
jsonObject.add("useridlist", jsonArray);
- this.mainService.post(url, jsonObject.toString());
+ this.mainService.post(WxCpUserService.URL_USER_BATCH_DELETE, jsonObject.toString());
}
@Override
public WxCpUser getById(String userid) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?userid=" + userid;
- String responseContent = this.mainService.get(url, null);
+ String responseContent = this.mainService.get(WxCpUserService.URL_USER_GET + userid, null);
return WxCpUser.fromJson(responseContent);
}
@Override
public List listByDepartment(Long departId, Boolean fetchChild, Integer status) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
String params = "";
if (fetchChild != null) {
params += "&fetch_child=" + (fetchChild ? "1" : "0");
@@ -88,7 +82,7 @@ public List listByDepartment(Long departId, Boolean fetchChild, Intege
params += "&status=0";
}
- String responseContent = this.mainService.get(url, params);
+ String responseContent = this.mainService.get(WxCpUserService.URL_USER_LIST + departId, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("userlist"),
@@ -99,7 +93,6 @@ public List listByDepartment(Long departId, Boolean fetchChild, Intege
@Override
public List listSimpleByDepartment(Long departId, Boolean fetchChild, Integer status) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;
String params = "";
if (fetchChild != null) {
params += "&fetch_child=" + (fetchChild ? "1" : "0");
@@ -110,7 +103,7 @@ public List listSimpleByDepartment(Long departId, Boolean fetchChild,
params += "&status=0";
}
- String responseContent = this.mainService.get(url, params);
+ String responseContent = this.mainService.get(WxCpUserService.URL_USER_SIMPLE_LIST + departId, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -122,7 +115,6 @@ public List listSimpleByDepartment(Long departId, Boolean fetchChild,
@Override
public WxCpInviteResult invite(List userIds, List partyIds, List tagIds) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/invite";
JsonObject jsonObject = new JsonObject();
if (userIds != null) {
JsonArray jsonArray = new JsonArray();
@@ -148,19 +140,18 @@ public WxCpInviteResult invite(List userIds, List partyIds, List
jsonObject.add("tag", jsonArray);
}
- return WxCpInviteResult.fromJson(this.mainService.post(url, jsonObject.toString()));
+ return WxCpInviteResult.fromJson(this.mainService.post(WxCpUserService.URL_BATCH_INVITE, jsonObject.toString()));
}
@Override
public Map userId2Openid(String userId, Integer agentId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
if (agentId != null) {
jsonObject.addProperty("agentid", agentId);
}
- String responseContent = this.mainService.post(url, jsonObject.toString());
+ String responseContent = this.mainService.post(WxCpUserService.URL_CONVERT_TO_OPENID, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
Map result = Maps.newHashMap();
if (tmpJsonElement.getAsJsonObject().get("openid") != null) {
@@ -176,18 +167,16 @@ public Map userId2Openid(String userId, Integer agentId) throws
@Override
public String openid2UserId(String openid) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("openid", openid);
- String responseContent = this.mainService.post(url, jsonObject.toString());
+ String responseContent = this.mainService.post(WxCpUserService.URL_CONVERT_TO_USERID, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
}
@Override
public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException {
- String url = "https://qyapi.weixin.qq.com/cgi-bin/crm/get_external_contact?external_userid=" + userId;
- String responseContent = this.mainService.get(url, null);
+ String responseContent = this.mainService.get(WxCpUserService.URL_GET_EXTERNAL_CONTACT + userId, null);
return WxCpUserExternalContactInfo.fromJson(responseContent);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagGetResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagGetResult.java
index 28cc4807a1..244419b062 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagGetResult.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTagGetResult.java
@@ -29,19 +29,19 @@ public class WxCpTagGetResult implements Serializable {
private String errmsg;
/**
- * 用户列表
+ * 用户列表.
*/
@SerializedName("userlist")
private List userlist;
/**
- * 部门列表
+ * 部门列表.
*/
@SerializedName("partylist")
private List partylist;
/**
- * 标签名称
+ * 标签名称.
*/
@SerializedName("tagname")
private String tagname;
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java
index 4ce497243d..a2dc46e826 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java
@@ -6,7 +6,6 @@
import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpAgent;
-import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -71,7 +70,7 @@ public static class MockTest {
@Test
public void testGet() throws Exception {
String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"agentid\": 9,\"name\": \"测试应用\",\"square_logo_url\": \"http://wx.qlogo.cn/mmhead/alksjf;lasdjf;lasjfuodiuj3rj2o34j/0\",\"description\": \"这是一个企业号应用\",\"allow_userinfos\": {\"user\": [{\"userid\": \"0009854\"}, {\"userid\": \"1723\"}, {\"userid\": \"5625\"}]},\"allow_partys\": {\"partyid\": [42762742]},\"allow_tags\": {\"tagid\": [23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7]},\"close\": 0,\"redirect_domain\": \"weixin.com.cn\",\"report_location_flag\": 0,\"isreportenter\": 0,\"home_url\": \"\"}";
- when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=9", null)).thenReturn(returnJson);
+ when(wxService.get(String.format(WxCpAgentService.GET_AGENT, 9), null)).thenReturn(returnJson);
when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService));
WxCpAgentService wxAgentService = this.wxService.getAgentService();
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java
similarity index 97%
rename from weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAServiceImplTest.java
rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java
index 9497a5626b..4810cd81d9 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOAServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java
@@ -24,7 +24,7 @@
* @date 2019-04-20 13:46
*/
@Guice(modules = ApiTestModule.class)
-public class WxCpOAServiceImplTest {
+public class WxCpOaServiceImplTest {
@Inject
protected WxCpService wxService;
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java
index 5a6e8ccabd..c4c8b3ccb5 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java
@@ -22,10 +22,10 @@
/**
*
- *
* Created by Binary Wang on 2017-6-25.
- * @author Binary Wang
*
+ *
+ * @author Binary Wang
*/
@Guice(modules = ApiTestModule.class)
public class WxCpTagServiceImplTest {
@@ -35,7 +35,7 @@ public class WxCpTagServiceImplTest {
@Inject
protected ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;
- protected String tagId;
+ private String tagId;
@Test
public void testCreate() throws Exception {
@@ -83,7 +83,7 @@ public void testDelete() throws Exception {
public void testGet() throws WxErrorException {
String apiResultJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"userlist\": [{\"userid\": \"0124035\",\"name\": \"王五\"},{\"userid\": \"0114035\",\"name\": \"梦雪\"}],\"partylist\": [9576,9567,9566],\"tagname\": \"测试标签-001\"}";
WxCpService wxService = mock(WxCpService.class);
- when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagId=150", null)).thenReturn(apiResultJson);
+ when(wxService.get(String.format(WxCpTagService.TAG_GET, 150), null)).thenReturn(apiResultJson);
when(wxService.getTagService()).thenReturn(new WxCpTagServiceImpl(wxService));
WxCpTagService wxCpTagService = wxService.getTagService();
@@ -96,7 +96,6 @@ public void testGet() throws WxErrorException {
assertEquals(3, wxCpTagGetResult.getPartylist().size());
assertEquals("测试标签-001", wxCpTagGetResult.getTagname());
-
}
}
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java
index b39e76fdba..73793a23ff 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java
@@ -3,6 +3,7 @@
import java.io.Serializable;
import java.math.BigDecimal;
+import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import com.github.binarywang.wxpay.config.WxPayConfig;
@@ -27,6 +28,7 @@
* @author Binary Wang
*/
@Data
+@Accessors(chain = true)
public abstract class BaseWxPayRequest implements Serializable {
private static final long serialVersionUID = -4766915659779847060L;
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java
index 78bb789d25..bf29a55b35 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayUnifiedOrderRequest.java
@@ -5,6 +5,7 @@
import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.*;
+import lombok.experimental.Accessors;
import me.chanjar.weixin.common.annotation.Required;
import org.apache.commons.lang3.StringUtils;
@@ -23,6 +24,7 @@
@NoArgsConstructor
@AllArgsConstructor
@XStreamAlias("xml")
+@Accessors(chain = true)
public class WxPayUnifiedOrderRequest extends BaseWxPayRequest {
private static final long serialVersionUID = 4611350167813931828L;
From f71fed4c6a311e152b4fec9656e277b7baaace61 Mon Sep 17 00:00:00 2001
From: Binary Wang
Date: Sun, 2 Jun 2019 12:43:02 +0800
Subject: [PATCH 07/74] =?UTF-8?q?#1060=20=E4=BF=AE=E5=A4=8D=E5=BE=AE?=
=?UTF-8?q?=E4=BF=A1=E5=8D=A1=E5=88=B8=E7=AD=BE=E5=90=8D=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../weixin/common/util/crypto/SHA1.java | 8 +-
.../weixin/mp/api/WxMpCardService.java | 43 +++---
.../mp/api/impl/WxMpCardServiceImpl.java | 134 +++---------------
.../mp/bean/card/WxMpCardDeleteResult.java | 8 +-
4 files changed, 51 insertions(+), 142 deletions(-)
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java
index 3cdc572387..c82f94d871 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java
@@ -6,12 +6,14 @@
import java.util.Arrays;
/**
- * Created by Daniel Qian on 14/10/19.
+ *
+ * @author Daniel Qian
+ * @date 14/10/19
*/
public class SHA1 {
/**
- * 串接arr参数,生成sha1 digest
+ * 串接arr参数,生成sha1 digest.
*/
public static String gen(String... arr) {
if (StringUtils.isAnyEmpty(arr)) {
@@ -27,7 +29,7 @@ public static String gen(String... arr) {
}
/**
- * 用&串接arr参数,生成sha1 digest
+ * 用&串接arr参数,生成sha1 digest.
*/
public static String genWithAmple(String... arr) {
if (StringUtils.isAnyEmpty(arr)) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java
index 66aeccade7..e7f2db4f87 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java
@@ -3,10 +3,9 @@
import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.bean.card.*;
-import me.chanjar.weixin.mp.bean.card.WxMpCardResult;
/**
- * 卡券相关接口
+ * 卡券相关接口.
*
* @author YuJian(mgcnrx11 @ hotmail.com) on 01/11/2016
* @author yuanqixun 2018-08-29
@@ -22,23 +21,24 @@ public interface WxMpCardService {
String CARD_TEST_WHITELIST = "https://api.weixin.qq.com/card/testwhitelist/set";
String CARD_QRCODE_CREATE = "https://api.weixin.qq.com/card/qrcode/create";
String CARD_LANDING_PAGE_CREATE = "https://api.weixin.qq.com/card/landingpage/create";
+
/**
- * 将用户的卡券设置为失效状态
+ * 将用户的卡券设置为失效状态.
*/
String CARD_CODE_UNAVAILABLE = "https://api.weixin.qq.com/card/code/unavailable";
/**
- * 卡券删除
+ * 卡券删除.
*/
String CARD_DELETE = "https://api.weixin.qq.com/card/delete";
/**
- * 得到WxMpService
+ * 得到WxMpService.
*/
WxMpService getWxMpService();
/**
- * 获得卡券api_ticket,不强制刷新卡券api_ticket
+ * 获得卡券api_ticket,不强制刷新卡券api_ticket.
*
* @return 卡券api_ticket
* @see #getCardApiTicket(boolean)
@@ -47,7 +47,7 @@ public interface WxMpCardService {
/**
*
- * 获得卡券api_ticket
+ * 获得卡券api_ticket.
* 获得时会检查卡券apiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
*
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94.9F.E6.88.90.E7.AE.97.E6.B3.95
@@ -61,7 +61,7 @@ public interface WxMpCardService {
/**
*
- * 创建调用卡券api时所需要的签名
+ * 创建调用卡券api时所需要的签名.
*
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD
* .954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94
@@ -73,11 +73,10 @@ public interface WxMpCardService {
* 注意:当做wx.chooseCard调用时,必须传入app_id参与签名,否则会造成签名失败导致拉取卡券列表为空
* @return 卡券Api签名对象
*/
- WxCardApiSignature createCardApiSignature(String... optionalSignParam) throws
- WxErrorException;
+ WxCardApiSignature createCardApiSignature(String... optionalSignParam) throws WxErrorException;
/**
- * 卡券Code解码
+ * 卡券Code解码.
*
* @param encryptCode 加密Code,通过JSSDK的chooseCard接口获得
* @return 解密后的Code
@@ -87,6 +86,7 @@ WxCardApiSignature createCardApiSignature(String... optionalSignParam) throws
/**
* 卡券Code查询.
* 文档地址: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025272&anchor=1
+ *
* @param cardId 卡券ID代表一类卡券
* @param code 单张卡券的唯一标准
* @param checkConsume 是否校验code核销状态,填入true和false时的code异常状态返回数据不同
@@ -105,7 +105,7 @@ WxMpCardResult queryCardCode(String cardId, String code, boolean checkConsume)
String consumeCardCode(String code) throws WxErrorException;
/**
- * 卡券Code核销。核销失败会抛出异常
+ * 卡券Code核销。核销失败会抛出异常.
*
* @param code 单张卡券的唯一标准
* @param cardId 当自定义Code卡券时需要传入card_id
@@ -124,11 +124,10 @@ WxMpCardResult queryCardCode(String cardId, String code, boolean checkConsume)
* @param openId 用券用户的openid
* @param isMark 是否要mark(占用)这个code,填写true或者false,表示占用或解除占用
*/
- void markCardCode(String code, String cardId, String openId, boolean isMark) throws
- WxErrorException;
+ void markCardCode(String code, String cardId, String openId, boolean isMark) throws WxErrorException;
/**
- * 查看卡券详情接口
+ * 查看卡券详情接口.
* 详见 https://mp.weixin.qq.com/wiki/14/8dd77aeaee85f922db5f8aa6386d385e.html#.E6.9F.A5.E7.9C.8B.E5.8D.A1.E5.88.B8.E8.AF.A6.E6.83.85
*
* @param cardId 卡券的ID
@@ -139,7 +138,7 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
String getCardDetail(String cardId) throws WxErrorException;
/**
- * 添加测试白名单
+ * 添加测试白名单.
*
* @param openid 用户的openid
* @return
@@ -147,7 +146,6 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
String addTestWhiteList(String openid) throws WxErrorException;
/**
- *
* @param cardCreateMessage
* @return
* @throws WxErrorException
@@ -155,7 +153,7 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException;
/**
- * 创建卡券二维码
+ * 创建卡券二维码.
*
* @param cardId 卡券编号
* @param outerStr 二维码标识
@@ -164,7 +162,7 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr) throws WxErrorException;
/**
- * 创建卡券二维码
+ * 创建卡券二维码.
*
* @param cardId 卡券编号
* @param outerStr 二维码标识
@@ -174,7 +172,7 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr, int expiresIn) throws WxErrorException;
/**
- * 创建卡券货架
+ * 创建卡券货架.
*
* @param createRequest 货架创建参数
* @return
@@ -183,7 +181,7 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest createRequest) throws WxErrorException;
/**
- * 将用户的卡券设置为失效状态
+ * 将用户的卡券设置为失效状态.
* 详见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025272&anchor=9
*
* @param cardId 卡券编号
@@ -195,7 +193,8 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
String unavailableCardCode(String cardId, String code, String reason) throws WxErrorException;
/**
- * 删除卡券接口
+ * 删除卡券接口.
+ *
* @param cardId
* @return
* @throws WxErrorException
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java
index bdd1990440..d96b9752d0 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java
@@ -2,20 +2,20 @@
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.RandomUtils;
-import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.mp.api.WxMpCardService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.card.*;
import me.chanjar.weixin.mp.enums.TicketType;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.concurrent.locks.Lock;
@@ -25,46 +25,22 @@
*
* @author BinaryWang
*/
+@Slf4j
+@RequiredArgsConstructor
public class WxMpCardServiceImpl implements WxMpCardService {
- private final Logger log = LoggerFactory.getLogger(WxMpCardServiceImpl.class);
-
- private WxMpService wxMpService;
-
private static final Gson GSON = WxMpGsonBuilder.create();
-
- public WxMpCardServiceImpl(WxMpService wxMpService) {
- this.wxMpService = wxMpService;
- }
+ private final WxMpService wxMpService;
@Override
public WxMpService getWxMpService() {
return this.wxMpService;
}
- /**
- * 获得卡券api_ticket,不强制刷新卡券api_ticket.
- *
- * @return 卡券api_ticket
- * @see #getCardApiTicket(boolean)
- */
@Override
public String getCardApiTicket() throws WxErrorException {
return getCardApiTicket(false);
}
- /**
- *
- * 获得卡券api_ticket.
- * 获得时会检查卡券apiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
- *
- * 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD
- * .954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94
- * .9F.E6.88.90.E7.AE.97.E6.B3.95
- *
- *
- * @param forceRefresh 强制刷新
- * @return 卡券api_ticket
- */
@Override
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
final TicketType type = TicketType.WX_CARD;
@@ -91,32 +67,22 @@ public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
return this.getWxMpService().getWxMpConfigStorage().getTicket(type);
}
- /**
- *
- * 创建调用卡券api时所需要的签名
- *
- * 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD
- * .954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94
- * .9F.E6.88.90.E7.AE.97.E6.B3.95
- *
- *
- * @param optionalSignParam 参与签名的参数数组。
- * 可以为下列字段:app_id, card_id, card_type, code, openid, location_id
- * 注意:当做wx.chooseCard调用时,必须传入app_id参与签名,否则会造成签名失败导致拉取卡券列表为空
- * @return 卡券Api签名对象
- */
@Override
- public WxCardApiSignature createCardApiSignature(String... optionalSignParam) throws
- WxErrorException {
+ public WxCardApiSignature createCardApiSignature(String... optionalSignParam) throws WxErrorException {
long timestamp = System.currentTimeMillis() / 1000;
String nonceStr = RandomUtils.getRandomStr();
String cardApiTicket = getCardApiTicket(false);
- String[] signParam = Arrays.copyOf(optionalSignParam, optionalSignParam.length + 3);
- signParam[optionalSignParam.length] = String.valueOf(timestamp);
- signParam[optionalSignParam.length + 1] = nonceStr;
- signParam[optionalSignParam.length + 2] = cardApiTicket;
- String signature = SHA1.gen(signParam);
+ String[] signParams = Arrays.copyOf(optionalSignParam, optionalSignParam.length + 3);
+ signParams[optionalSignParam.length] = String.valueOf(timestamp);
+ signParams[optionalSignParam.length + 1] = nonceStr;
+ signParams[optionalSignParam.length + 2] = cardApiTicket;
+ StringBuilder sb = new StringBuilder();
+ for (String a : signParams) {
+ sb.append(a);
+ }
+ String signature = DigestUtils.sha1Hex(sb.toString());
+
WxCardApiSignature cardApiSignature = new WxCardApiSignature();
cardApiSignature.setTimestamp(timestamp);
cardApiSignature.setNonceStr(nonceStr);
@@ -124,12 +90,6 @@ public WxCardApiSignature createCardApiSignature(String... optionalSignParam) th
return cardApiSignature;
}
- /**
- * 卡券Code解码
- *
- * @param encryptCode 加密Code,通过JSSDK的chooseCard接口获得
- * @return 解密后的Code
- */
@Override
public String decryptCardCode(String encryptCode) throws WxErrorException {
JsonObject param = new JsonObject();
@@ -154,26 +114,11 @@ public WxMpCardResult queryCardCode(String cardId, String code, boolean checkCon
}.getType());
}
- /**
- * 卡券Code核销。核销失败会抛出异常
- *
- * @param code 单张卡券的唯一标准
- * @return 调用返回的JSON字符串。
- *
可用 com.google.gson.JsonParser#parse 等方法直接取JSON串中的errcode等信息。
- */
@Override
public String consumeCardCode(String code) throws WxErrorException {
return consumeCardCode(code, null);
}
- /**
- * 卡券Code核销。核销失败会抛出异常
- *
- * @param code 单张卡券的唯一标准
- * @param cardId 当自定义Code卡券时需要传入card_id
- * @return 调用返回的JSON字符串。
- *
可用 com.google.gson.JsonParser#parse 等方法直接取JSON串中的errcode等信息。
- */
@Override
public String consumeCardCode(String code, String cardId) throws WxErrorException {
JsonObject param = new JsonObject();
@@ -186,19 +131,8 @@ public String consumeCardCode(String code, String cardId) throws WxErrorExceptio
return this.wxMpService.post(CARD_CODE_CONSUME, param.toString());
}
- /**
- * 卡券Mark接口。
- * 开发者在帮助消费者核销卡券之前,必须帮助先将此code(卡券串码)与一个openid绑定(即mark住),
- * 才能进一步调用核销接口,否则报错。
- *
- * @param code 卡券的code码
- * @param cardId 卡券的ID
- * @param openId 用券用户的openid
- * @param isMark 是否要mark(占用)这个code,填写true或者false,表示占用或解除占用
- */
@Override
- public void markCardCode(String code, String cardId, String openId, boolean isMark) throws
- WxErrorException {
+ public void markCardCode(String code, String cardId, String openId, boolean isMark) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("code", code);
param.addProperty("card_id", cardId);
@@ -210,7 +144,7 @@ public void markCardCode(String code, String cardId, String openId, boolean isMa
new TypeToken() {
}.getType());
if (!"0".equals(cardResult.getErrorCode())) {
- this.log.warn("朋友的券mark失败:{}", cardResult.getErrorMsg());
+ log.warn("朋友的券mark失败:{}", cardResult.getErrorMsg());
}
}
@@ -233,43 +167,26 @@ public String getCardDetail(String cardId) throws WxErrorException {
return responseContent;
}
- /**
- * 添加测试白名单.
- *
- * @param openid 用户的openid
- */
@Override
public String addTestWhiteList(String openid) throws WxErrorException {
JsonArray array = new JsonArray();
array.add(openid);
JsonObject jsonObject = new JsonObject();
jsonObject.add("openid", array);
- String respone = this.wxMpService.post(CARD_TEST_WHITELIST, GSON.toJson(jsonObject));
- return respone;
+ return this.wxMpService.post(CARD_TEST_WHITELIST, GSON.toJson(jsonObject));
}
@Override
public WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException {
-
String response = this.wxMpService.post(CARD_CREATE, GSON.toJson(cardCreateMessage));
return WxMpCardCreateResult.fromJson(response);
}
- /**
- * 创建卡券二维码.
- */
@Override
public WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr) throws WxErrorException {
return createQrcodeCard(cardId, outerStr, 0);
}
- /**
- * 创建卡券二维码.
- *
- * @param cardId 卡券编号
- * @param outerStr 二维码标识
- * @param expiresIn 失效时间,单位秒,不填默认365天
- */
@Override
public WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr, int expiresIn) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
@@ -286,23 +203,12 @@ public WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerSt
return WxMpCardQrcodeCreateResult.fromJson(this.wxMpService.post(CARD_QRCODE_CREATE, GSON.toJson(jsonObject)));
}
- /**
- * 创建卡券货架接口.
- */
@Override
public WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest request) throws WxErrorException {
String response = this.wxMpService.post(CARD_LANDING_PAGE_CREATE, GSON.toJson(request));
return WxMpCardLandingPageCreateResult.fromJson(response);
}
- /**
- * 将用户的卡券设置为失效状态.
- * 详见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025272&anchor=9
- *
- * @param cardId 卡券编号
- * @param code 用户会员卡号
- * @param reason 设置为失效的原因
- */
@Override
public String unavailableCardCode(String cardId, String code, String reason) throws WxErrorException {
if (StringUtils.isAnyBlank(cardId, code, reason)) {
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/card/WxMpCardDeleteResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/card/WxMpCardDeleteResult.java
index 3dcbc3534c..8eedbebf60 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/card/WxMpCardDeleteResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/card/WxMpCardDeleteResult.java
@@ -3,11 +3,13 @@
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
- * @description 删除卡券结果
- * @author: fanxl
- * @date: 2019/1/22 0022 10:24
+ * 删除卡券结果.
+ *
+ * @author fanxl
+ * @date 2019/1/22 0022 10:24
*/
public class WxMpCardDeleteResult extends BaseWxMpCardResult {
+ private static final long serialVersionUID = -4367717540650523290L;
public static WxMpCardDeleteResult fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(json, WxMpCardDeleteResult.class);
From 60ebb5495819e4ea9b510c7e3ca611245d74a726 Mon Sep 17 00:00:00 2001
From: Binary Wang
Date: Sun, 2 Jun 2019 12:58:43 +0800
Subject: [PATCH 08/74] =?UTF-8?q?#1059=20=E5=BE=AE=E4=BF=A1=E6=94=AF?=
=?UTF-8?q?=E4=BB=98=E8=AF=81=E4=B9=A6=E5=9C=B0=E5=9D=80=E5=8F=82=E6=95=B0?=
=?UTF-8?q?keyPath=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8=E7=BD=91=E7=BB=9C?=
=?UTF-8?q?=E5=9C=B0=E5=9D=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../binarywang/wxpay/config/WxPayConfig.java | 25 +++++++++++--------
.../wxpay/config/WxPayConfigTest.java | 14 ++++++-----
2 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
index f8d915f8a8..93b3b700d0 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
@@ -1,19 +1,15 @@
package com.github.binarywang.wxpay.config;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.KeyStore;
-import javax.net.ssl.SSLContext;
-
+import com.github.binarywang.wxpay.exception.WxPayException;
+import lombok.Data;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.ssl.SSLContexts;
-import com.github.binarywang.wxpay.exception.WxPayException;
-import lombok.Data;
+import javax.net.ssl.SSLContext;
+import java.io.*;
+import java.net.URL;
+import java.security.KeyStore;
/**
* 微信支付配置
@@ -131,6 +127,15 @@ public SSLContext initSSLContext() throws WxPayException {
if (inputStream == null) {
throw new WxPayException(fileNotFoundMsg);
}
+ } else if (this.getKeyPath().startsWith("http://") || this.getKeyPath().startsWith("https://")) {
+ try {
+ inputStream = new URL(this.keyPath).openStream();
+ if (inputStream == null) {
+ throw new WxPayException(fileNotFoundMsg);
+ }
+ } catch (IOException e) {
+ throw new WxPayException(fileNotFoundMsg, e);
+ }
} else {
try {
File file = new File(this.getKeyPath());
diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigTest.java
index 3edc2c3268..9d3c13da42 100644
--- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigTest.java
+++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/config/WxPayConfigTest.java
@@ -14,16 +14,18 @@
public class WxPayConfigTest {
private WxPayConfig payConfig = new WxPayConfig();
- /**
- * Test init ssl context.
- *
- * @throws Exception the exception
- */
@Test
- public void testInitSSLContext() throws Exception {
+ public void testInitSSLContext_classpath() throws Exception {
payConfig.setMchId("123");
payConfig.setKeyPath("classpath:/abc.p12");
payConfig.initSSLContext();
}
+ @Test
+ public void testInitSSLContext_http() throws Exception {
+ payConfig.setMchId("123");
+ payConfig.setKeyPath("https://www.baidu.com");
+ payConfig.initSSLContext();
+ }
+
}
From 6b08dc881e228031e4bf9bf17c43928d4610afa1 Mon Sep 17 00:00:00 2001
From: Binary Wang
Date: Sun, 2 Jun 2019 14:38:21 +0800
Subject: [PATCH 09/74] Update .travis.yml
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 2f01901cf5..60c4d53e7c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,7 +8,7 @@ language: java
jdk:
- oraclejdk8
-script: "./mvnw clean package -DskipTests=true"
+script: "./mvnw clean package -DskipTests=true -Dcheckstyle.skip=true"
#script:
# - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar
From 97e88bd99ddb961a0aab191c93059bf066a17801 Mon Sep 17 00:00:00 2001
From: crazycode
Date: Sun, 2 Jun 2019 14:40:51 +0800
Subject: [PATCH 10/74] =?UTF-8?q?#1065=20=E6=94=AF=E6=8C=81=E7=A7=81?=
=?UTF-8?q?=E6=9C=89=E5=8C=96=E9=83=A8=E7=BD=B2=E7=89=88=E6=9C=AC=E7=9A=84?=
=?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
通过 wxCpConfigStorage.setBaseApiUrl("http://local_server:port"); 设置私有化部署的企业微信服务地址.
默认值是 https://qyapi.weixin.qq.com , 如果使用默认值,则不需要调用 setBaseApiUrl(baseUrl).
---
.../weixin/cp/api/WxCpAgentService.java | 6 +-
.../weixin/cp/api/WxCpChatService.java | 8 +-
.../weixin/cp/api/WxCpDepartmentService.java | 12 +-
.../weixin/cp/api/WxCpMediaService.java | 14 +-
.../weixin/cp/api/WxCpMenuService.java | 6 +-
.../weixin/cp/api/WxCpOAuth2Service.java | 4 +-
.../chanjar/weixin/cp/api/WxCpOaService.java | 8 +-
.../me/chanjar/weixin/cp/api/WxCpService.java | 18 +-
.../chanjar/weixin/cp/api/WxCpTagService.java | 14 +-
.../weixin/cp/api/WxCpTaskCardService.java | 2 +-
.../chanjar/weixin/cp/api/WxCpTpService.java | 8 +-
.../weixin/cp/api/WxCpUserService.java | 30 +-
.../cp/api/impl/BaseWxCpServiceImpl.java | 46 +-
.../cp/api/impl/BaseWxCpTpServiceImpl.java | 488 +++++++++---------
.../cp/api/impl/WxCpAgentServiceImpl.java | 13 +-
.../cp/api/impl/WxCpChatServiceImpl.java | 8 +-
.../api/impl/WxCpDepartmentServiceImpl.java | 14 +-
.../cp/api/impl/WxCpMediaServiceImpl.java | 19 +-
.../cp/api/impl/WxCpMenuServiceImpl.java | 8 +-
.../cp/api/impl/WxCpOAuth2ServiceImpl.java | 4 +-
.../weixin/cp/api/impl/WxCpOaServiceImpl.java | 8 +-
.../impl/WxCpServiceApacheHttpClientImpl.java | 3 +-
.../cp/api/impl/WxCpServiceJoddHttpImpl.java | 8 +-
.../cp/api/impl/WxCpServiceOkHttpImpl.java | 9 +-
.../cp/api/impl/WxCpTagServiceImpl.java | 30 +-
.../cp/api/impl/WxCpTaskCardServiceImpl.java | 4 +-
.../WxCpTpServiceApacheHttpClientImpl.java | 2 +-
.../cp/api/impl/WxCpUserServiceImpl.java | 39 +-
.../weixin/cp/config/WxCpConfigStorage.java | 16 +
.../cp/config/WxCpInMemoryConfigStorage.java | 15 +
.../cp/config/WxCpJedisConfigStorage.java | 15 +
.../weixin/cp/config/WxCpTpConfigStorage.java | 160 +++---
.../config/WxCpTpInMemoryConfigStorage.java | 475 ++++++++---------
.../cp/api/impl/WxCpAgentServiceImplTest.java | 4 +-
.../cp/api/impl/WxCpTagServiceImplTest.java | 3 +-
35 files changed, 824 insertions(+), 697 deletions(-)
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
index 30214a478f..7dad7b6c76 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
@@ -15,9 +15,9 @@
* @author huansinho
*/
public interface WxCpAgentService {
- String GET_AGENT = "https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=%d";
- String AGENT_SET = "https://qyapi.weixin.qq.com/cgi-bin/agent/set";
- String AGENT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/agent/list";
+ String GET_AGENT = "/cgi-bin/agent/get?agentid=%d";
+ String AGENT_SET = "/cgi-bin/agent/set";
+ String AGENT_LIST = "/cgi-bin/agent/list";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
index bbfc0fdd48..58ab329f01 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
@@ -12,10 +12,10 @@
* @author gaigeshen
*/
public interface WxCpChatService {
- String APPCHAT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/create";
- String APPCHAT_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/update";
- String APPCHAT_GET_CHATID = "https://qyapi.weixin.qq.com/cgi-bin/appchat/get?chatid=";
- String APPCHAT_SEND = "https://qyapi.weixin.qq.com/cgi-bin/appchat/send";
+ String APPCHAT_CREATE = "/cgi-bin/appchat/create";
+ String APPCHAT_UPDATE = "/cgi-bin/appchat/update";
+ String APPCHAT_GET_CHATID = "/cgi-bin/appchat/get?chatid=";
+ String APPCHAT_SEND = "/cgi-bin/appchat/send";
@Deprecated
String chatCreate(String name, String owner, List users, String chatId) throws WxErrorException;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
index 3f80d693ad..8aa7ca353a 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
@@ -1,10 +1,10 @@
package me.chanjar.weixin.cp.api;
-import java.util.List;
-
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpDepart;
+import java.util.List;
+
/**
*
* 部门管理接口
@@ -14,10 +14,10 @@
* @author Binary Wang
*/
public interface WxCpDepartmentService {
- String DEPARTMENT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
- String DEPARTMENT_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
- String DEPARTMENT_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=%d";
- String DEPARTMENT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
+ String DEPARTMENT_CREATE = "/cgi-bin/department/create";
+ String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
+ String DEPARTMENT_DELETE = "/cgi-bin/department/delete?id=%d";
+ String DEPARTMENT_LIST = "/cgi-bin/department/list";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java
index 31ce6b5991..67c67ec625 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java
@@ -1,12 +1,12 @@
package me.chanjar.weixin.cp.api;
+import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
+import me.chanjar.weixin.common.error.WxErrorException;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
-import me.chanjar.weixin.common.error.WxErrorException;
-
/**
*
* 媒体管理接口.
@@ -16,10 +16,10 @@
* @author Binary Wang
*/
public interface WxCpMediaService {
- String MEDIA_GET_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/get";
- String MEDIA_UPLOAD_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?type=";
- String IMG_UPLOAD_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg";
- String JSSDK_MEDIA_GET_URL = "https://qyapi.weixin.qq.com/cgi-bin/media/get/jssdk";
+ String MEDIA_GET_URL = "/cgi-bin/media/get";
+ String MEDIA_UPLOAD_URL = "/cgi-bin/media/upload?type=";
+ String IMG_UPLOAD_URL = "/cgi-bin/media/uploadimg";
+ String JSSDK_MEDIA_GET_URL = "/cgi-bin/media/get/jssdk";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
index be7b4b7e55..7c0a01e595 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
@@ -12,9 +12,9 @@
* @author Binary Wang
*/
public interface WxCpMenuService {
- String MENU_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=%d";
- String MENU_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=%d";
- String MENU_GET = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=%d";
+ String MENU_CREATE = "/cgi-bin/menu/create?agentid=%d";
+ String MENU_DELETE = "/cgi-bin/menu/delete?agentid=%d";
+ String MENU_GET = "/cgi-bin/menu/get?agentid=%d";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
index c6d9063fbb..39d2163e7b 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
@@ -13,8 +13,8 @@
* @author Binary Wang
*/
public interface WxCpOAuth2Service {
- String URL_GET_USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
- String URL_GET_USER_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail";
+ String URL_GET_USER_INFO = "/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
+ String URL_GET_USER_DETAIL = "/cgi-bin/user/getuserdetail";
String URL_OAUTH_2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
/**
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
index 26922c0eee..5cca9e7788 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
@@ -16,10 +16,10 @@
* @date 2019-04-06 10:52
*/
public interface WxCpOaService {
- String GET_CHECKIN_DATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata";
- String GET_CHECKIN_OPTION = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption";
- String GET_APPROVAL_DATA = "https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata";
- String GET_DIAL_RECORD = "https://qyapi.weixin.qq.com/cgi-bin/dial/get_dial_record";
+ String GET_CHECKIN_DATA = "/cgi-bin/checkin/getcheckindata";
+ String GET_CHECKIN_OPTION = "/cgi-bin/checkin/getcheckinoption";
+ String GET_APPROVAL_DATA = "/cgi-bin/corp/getapprovaldata";
+ String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record";
/**
*
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 13d2e9dc4a..12ae987b1b 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
@@ -17,15 +17,15 @@
* @author chanjaster
*/
public interface WxCpService {
- String GET_JSAPI_TICKET = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
- String GET_AGENT_CONFIG_TICKET = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?&type=agent_config";
- 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=";
- String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session";
- String GET_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?&corpid=%s&corpsecret=%s";
+ String GET_JSAPI_TICKET = "/cgi-bin/get_jsapi_ticket";
+ String GET_AGENT_CONFIG_TICKET = "/cgi-bin/ticket/get?&type=agent_config";
+ String MESSAGE_SEND = "/cgi-bin/message/send";
+ String GET_CALLBACK_IP = "/cgi-bin/getcallbackip";
+ String BATCH_REPLACE_PARTY = "/cgi-bin/batch/replaceparty";
+ String BATCH_REPLACE_USER = "/cgi-bin/batch/replaceuser";
+ String BATCH_GET_RESULT = "/cgi-bin/batch/getresult?jobid=";
+ String JSCODE_TO_SESSION_URL = "/cgi-bin/miniprogram/jscode2session";
+ String GET_TOKEN = "/cgi-bin/gettoken?&corpid=%s&corpsecret=%s";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
index a570a80b10..ee1b526d64 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
@@ -17,13 +17,13 @@
* @author Binary Wang
*/
public interface WxCpTagService {
- String TAG_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/tag/create";
- String TAG_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/tag/update";
- String TAG_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?tagid=%s";
- String TAG_LIST = "https://qyapi.weixin.qq.com/cgi-bin/tag/list";
- String TAG_GET = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagid=%s";
- String TAG_ADDTAGUSERS = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
- String TAG_DELTAGUSERS = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
+ String TAG_CREATE = "/cgi-bin/tag/create";
+ String TAG_UPDATE = "/cgi-bin/tag/update";
+ String TAG_DELETE = "/cgi-bin/tag/delete?tagid=%s";
+ String TAG_LIST = "/cgi-bin/tag/list";
+ String TAG_GET = "/cgi-bin/tag/get?tagid=%s";
+ String TAG_ADDTAGUSERS = "/cgi-bin/tag/addtagusers";
+ String TAG_DELTAGUSERS = "/cgi-bin/tag/deltagusers";
/**
* 创建标签.
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
index 1e1077014f..b6ebdc1202 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
@@ -14,7 +14,7 @@
* @date 2019-05-16
*/
public interface WxCpTaskCardService {
- String MESSAGE_UPDATE_TASKCARD = "https://qyapi.weixin.qq.com/cgi-bin/message/update_taskcard";
+ String MESSAGE_UPDATE_TASKCARD = "/cgi-bin/message/update_taskcard";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
index 6e0d63fb2c..6c52bcfde6 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
@@ -15,10 +15,10 @@
* @author zhenjun cai
*/
public interface WxCpTpService {
- String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/miniprogram/jscode2session";
- String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token";
- String GET_PERMANENT_CODE = "https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code";
- String GET_SUITE_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token";
+ String JSCODE_TO_SESSION_URL = "/cgi-bin/service/miniprogram/jscode2session";
+ String GET_CORP_TOKEN = "/cgi-bin/service/get_corp_token";
+ String GET_PERMANENT_CODE = "/cgi-bin/service/get_permanent_code";
+ String GET_SUITE_TOKEN = "/cgi-bin/service/get_suite_token";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
index 091c687595..4289ae94c7 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
@@ -1,13 +1,13 @@
package me.chanjar.weixin.cp.api;
-import java.util.List;
-import java.util.Map;
-
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
+import java.util.List;
+import java.util.Map;
+
/**
*
* 用户管理接口
@@ -17,18 +17,18 @@
* @author Binary Wang
*/
public interface WxCpUserService {
- String URL_AUTHENTICATE = "https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?userid=";
- String URL_USER_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/user/create";
- String URL_USER_UPDATE = "https://qyapi.weixin.qq.com/cgi-bin/user/update";
- String URL_USER_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?userid=";
- String URL_USER_BATCH_DELETE = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
- String URL_USER_GET = "https://qyapi.weixin.qq.com/cgi-bin/user/get?userid=";
- String URL_USER_LIST = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=";
- String URL_USER_SIMPLE_LIST = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=";
- String URL_BATCH_INVITE = "https://qyapi.weixin.qq.com/cgi-bin/batch/invite";
- String URL_CONVERT_TO_OPENID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid";
- String URL_CONVERT_TO_USERID = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid";
- String URL_GET_EXTERNAL_CONTACT = "https://qyapi.weixin.qq.com/cgi-bin/crm/get_external_contact?external_userid=";
+ String URL_AUTHENTICATE = "/cgi-bin/user/authsucc?userid=";
+ String URL_USER_CREATE = "/cgi-bin/user/create";
+ String URL_USER_UPDATE = "/cgi-bin/user/update";
+ String URL_USER_DELETE = "/cgi-bin/user/delete?userid=";
+ String URL_USER_BATCH_DELETE = "/cgi-bin/user/batchdelete";
+ String URL_USER_GET = "/cgi-bin/user/get?userid=";
+ String URL_USER_LIST = "/cgi-bin/user/list?department_id=";
+ String URL_USER_SIMPLE_LIST = "/cgi-bin/user/simplelist?department_id=";
+ String URL_BATCH_INVITE = "/cgi-bin/batch/invite";
+ String URL_CONVERT_TO_OPENID = "/cgi-bin/user/convert_to_openid";
+ String URL_CONVERT_TO_USERID = "/cgi-bin/user/convert_to_userid";
+ String URL_GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";
/**
*
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 d9c88b47a5..e0bab1d90e 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
@@ -18,7 +18,17 @@
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
-import me.chanjar.weixin.cp.api.*;
+import me.chanjar.weixin.cp.api.WxCpAgentService;
+import me.chanjar.weixin.cp.api.WxCpChatService;
+import me.chanjar.weixin.cp.api.WxCpDepartmentService;
+import me.chanjar.weixin.cp.api.WxCpMediaService;
+import me.chanjar.weixin.cp.api.WxCpMenuService;
+import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
+import me.chanjar.weixin.cp.api.WxCpOaService;
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.api.WxCpTagService;
+import me.chanjar.weixin.cp.api.WxCpTaskCardService;
+import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
@@ -37,16 +47,16 @@
public abstract class BaseWxCpServiceImpl implements WxCpService, RequestHttp {
protected final Logger log = LoggerFactory.getLogger(this.getClass());
- private WxCpUserService userService = new WxCpUserServiceImpl(this);
- private WxCpChatService chatService = new WxCpChatServiceImpl(this);
+ private WxCpUserService userService = new WxCpUserServiceImpl(this);
+ private WxCpChatService chatService = new WxCpChatServiceImpl(this);
private WxCpDepartmentService departmentService = new WxCpDepartmentServiceImpl(this);
- private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this);
- private WxCpMenuService menuService = new WxCpMenuServiceImpl(this);
- private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
- private WxCpTagService tagService = new WxCpTagServiceImpl(this);
- private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
- private WxCpOaService oaService = new WxCpOaServiceImpl(this);
- private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
+ private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this);
+ private WxCpMenuService menuService = new WxCpMenuServiceImpl(this);
+ private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
+ private WxCpTagService tagService = new WxCpTagServiceImpl(this);
+ private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
+ private WxCpOaService oaService = new WxCpOaServiceImpl(this);
+ private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
/**
* 全局的是否正在刷新access token的锁
@@ -104,7 +114,7 @@ public String getAgentJsapiTicket(boolean forceRefresh) throws WxErrorException
if (this.configStorage.isAgentJsapiTicketExpired()) {
synchronized (this.globalAgentJsapiTicketRefreshLock) {
if (this.configStorage.isAgentJsapiTicketExpired()) {
- String responseContent = this.get(WxCpService.GET_AGENT_CONFIG_TICKET, null);
+ String responseContent = this.get(this.configStorage.getApiUrl(WxCpService.GET_AGENT_CONFIG_TICKET), null);
JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
this.configStorage.updateAgentJsapiTicket(jsonObject.get("ticket").getAsString(),
jsonObject.get("expires_in").getAsInt());
@@ -129,7 +139,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
if (this.configStorage.isJsapiTicketExpired()) {
synchronized (this.globalJsapiTicketRefreshLock) {
if (this.configStorage.isJsapiTicketExpired()) {
- String responseContent = this.get(WxCpService.GET_JSAPI_TICKET, null);
+ String responseContent = this.get(this.configStorage.getApiUrl(WxCpService.GET_JSAPI_TICKET), null);
JsonObject tmpJsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
this.configStorage.updateJsapiTicket(tmpJsonObject.get("ticket").getAsString(),
tmpJsonObject.get("expires_in").getAsInt());
@@ -170,7 +180,7 @@ public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorExce
message.setAgentId(this.getWxCpConfigStorage().getAgentId());
}
- return WxCpMessageSendResult.fromJson(this.post(WxCpService.MESSAGE_SEND, message.toJson()));
+ return WxCpMessageSendResult.fromJson(this.post(this.configStorage.getApiUrl(WxCpService.MESSAGE_SEND), message.toJson()));
}
@Override
@@ -179,13 +189,13 @@ public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorEx
params.put("js_code", jsCode);
params.put("grant_type", "authorization_code");
- String result = this.get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
+ String result = this.get(this.configStorage.getApiUrl(JSCODE_TO_SESSION_URL), Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxCpMaJsCode2SessionResult.fromJson(result);
}
@Override
public String[] getCallbackIp() throws WxErrorException {
- String responseContent = get(WxCpService.GET_CALLBACK_IP, null);
+ String responseContent = get(this.configStorage.getApiUrl(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()];
@@ -329,19 +339,19 @@ public WxSessionManager getSessionManager() {
public String replaceParty(String mediaId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_id", mediaId);
- return post(WxCpService.BATCH_REPLACE_PARTY, jsonObject.toString());
+ return post(this.configStorage.getApiUrl(WxCpService.BATCH_REPLACE_PARTY), jsonObject.toString());
}
@Override
public String replaceUser(String mediaId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_id", mediaId);
- return post(WxCpService.BATCH_REPLACE_USER, jsonObject.toString());
+ return post(this.configStorage.getApiUrl(WxCpService.BATCH_REPLACE_USER), jsonObject.toString());
}
@Override
public String getTaskResult(String joinId) throws WxErrorException {
- String url = WxCpService.BATCH_GET_RESULT + joinId;
+ String url = this.configStorage.getApiUrl(WxCpService.BATCH_GET_RESULT + joinId);
return get(url, null);
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java
index 837c355e4d..f3714516cf 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java
@@ -1,244 +1,244 @@
-package me.chanjar.weixin.cp.api.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Joiner;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-
-import me.chanjar.weixin.common.WxType;
-import me.chanjar.weixin.common.bean.WxAccessToken;
-import me.chanjar.weixin.common.error.WxError;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.common.util.DataUtils;
-import me.chanjar.weixin.common.util.crypto.SHA1;
-import me.chanjar.weixin.common.util.http.RequestExecutor;
-import me.chanjar.weixin.common.util.http.RequestHttp;
-import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
-import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
-import me.chanjar.weixin.cp.api.WxCpService;
-import me.chanjar.weixin.cp.api.WxCpTpService;
-import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
-import me.chanjar.weixin.cp.bean.WxCpTpCorp;
-import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
-
-/**
- * @author zhenjun cai
- */
-public abstract class BaseWxCpTpServiceImpl implements WxCpTpService, RequestHttp {
- protected final Logger log = LoggerFactory.getLogger(this.getClass());
-
- /**
- * 全局的是否正在刷新access token的锁
- */
- protected final Object globalSuiteAccessTokenRefreshLock = new Object();
-
- /**
- * 全局的是否正在刷新jsapi_ticket的锁
- */
- protected final Object globalSuiteTicketRefreshLock = new Object();
-
-
- protected WxCpTpConfigStorage configStorage;
-
-
- /**
- * 临时文件目录
- */
- private File tmpDirFile;
- private int retrySleepMillis = 1000;
- private int maxRetryTimes = 5;
-
- @Override
- public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) {
- try {
- return SHA1.gen(this.configStorage.getToken(), timestamp, nonce, data)
- .equals(msgSignature);
- } catch (Exception e) {
- this.log.error("Checking signature failed, and the reason is :" + e.getMessage());
- return false;
- }
- }
-
- @Override
- public String getSuiteAccessToken() throws WxErrorException {
- return getSuiteAccessToken(false);
- }
-
- @Override
- public String getSuiteTicket() throws WxErrorException {
- return getSuiteTicket(false);
- }
-
- @Override
- public String getSuiteTicket(boolean forceRefresh) throws WxErrorException {
-// suite ticket由微信服务器推送,不能强制刷新
-// if (forceRefresh) {
-// this.configStorage.expireSuiteTicket();
-// }
-
- if (this.configStorage.isSuiteTicketExpired()) {
-// 本地suite ticket 不存在或者过期
- WxError wxError = WxError.fromJson("{\"errcode\":40085, \"errmsg\":\"invaild suite ticket\"}", WxType.CP);
- throw new WxErrorException(wxError);
- }
- return this.configStorage.getSuiteTicket();
- }
-
-
- @Override
- public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException {
- Map params = new HashMap<>(2);
- params.put("js_code", jsCode);
- params.put("grant_type", "authorization_code");
-
- String result = this.get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
- return WxCpMaJsCode2SessionResult.fromJson(result);
- }
-
-
- @Override
- public WxAccessToken getCorpToken(String authCorpid, String permanentCode) throws WxErrorException {
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("auth_corpid", authCorpid);
- jsonObject.addProperty("permanent_code", permanentCode);
- String result = post(GET_CORP_TOKEN, jsonObject.toString());
-
- return WxAccessToken.fromJson(result);
- }
-
-
- @Override
- public WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException {
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("auth_code", authCode);
-
- String result = post(GET_PERMANENT_CODE, jsonObject.toString());
- jsonObject = new JsonParser().parse(result).getAsJsonObject();
- WxCpTpCorp wxCpTpCorp = WxCpTpCorp.fromJson(jsonObject.get("auth_corp_info").getAsString());
- wxCpTpCorp.setPermanentCode(jsonObject.get("permanent_code").getAsString());
- return wxCpTpCorp;
- }
-
- @Override
- public String get(String url, String queryParam) throws WxErrorException {
- return execute(SimpleGetRequestExecutor.create(this), url, queryParam);
- }
-
- @Override
- public String post(String url, String postData) throws WxErrorException {
- return execute(SimplePostRequestExecutor.create(this), url, postData);
- }
-
- /**
- * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求.
- */
- @Override
- public T execute(RequestExecutor executor, String uri, E data) throws WxErrorException {
- int retryTimes = 0;
- do {
- try {
- return this.executeInternal(executor, uri, data);
- } catch (WxErrorException e) {
- if (retryTimes + 1 > this.maxRetryTimes) {
- this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
- //最后一次重试失败后,直接抛出异常,不再等待
- throw new RuntimeException("微信服务端异常,超出重试次数");
- }
-
- WxError error = e.getError();
- /*
- * -1 系统繁忙, 1000ms后重试
- */
- if (error.getErrorCode() == -1) {
- int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
- try {
- this.log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
- Thread.sleep(sleepMillis);
- } catch (InterruptedException e1) {
- Thread.currentThread().interrupt();
- }
- } else {
- throw e;
- }
- }
- } while (retryTimes++ < this.maxRetryTimes);
-
- this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
- throw new RuntimeException("微信服务端异常,超出重试次数");
- }
-
- protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException {
- E dataForLog = DataUtils.handleDataWithSecret(data);
-
- if (uri.contains("suite_access_token=")) {
- throw new IllegalArgumentException("uri参数中不允许有suite_access_token: " + uri);
- }
- String suiteAccessToken = getSuiteAccessToken(false);
-
- String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "suite_access_token=" + suiteAccessToken;
-
- try {
- T result = executor.execute(uriWithAccessToken, data);
- this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
- return result;
- } catch (WxErrorException e) {
- WxError error = e.getError();
- /*
- * 发生以下情况时尝试刷新suite_access_token
- * 42009 suite_access_token已过期
- */
- if (error.getErrorCode() == 42009) {
- // 强制设置wxCpTpConfigStorage它的suite access token过期了,这样在下一次请求里就会刷新suite access token
- this.configStorage.expireSuiteAccessToken();
- return execute(executor, uri, data);
- }
-
- if (error.getErrorCode() != 0) {
- this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
- throw new WxErrorException(error, e);
- }
- return null;
- } catch (IOException e) {
- this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void setWxCpTpConfigStorage(WxCpTpConfigStorage wxConfigProvider) {
- this.configStorage = wxConfigProvider;
- this.initHttp();
- }
-
- @Override
- public void setRetrySleepMillis(int retrySleepMillis) {
- this.retrySleepMillis = retrySleepMillis;
- }
-
-
- @Override
- public void setMaxRetryTimes(int maxRetryTimes) {
- this.maxRetryTimes = maxRetryTimes;
- }
-
- public File getTmpDirFile() {
- return this.tmpDirFile;
- }
-
- public void setTmpDirFile(File tmpDirFile) {
- this.tmpDirFile = tmpDirFile;
- }
-
- @Override
- public RequestHttp, ?> getRequestHttp() {
- return this;
- }
-
-}
+package me.chanjar.weixin.cp.api.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+import me.chanjar.weixin.common.WxType;
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.error.WxError;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.util.DataUtils;
+import me.chanjar.weixin.common.util.crypto.SHA1;
+import me.chanjar.weixin.common.util.http.RequestExecutor;
+import me.chanjar.weixin.common.util.http.RequestHttp;
+import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
+import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.api.WxCpTpService;
+import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
+import me.chanjar.weixin.cp.bean.WxCpTpCorp;
+import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
+
+/**
+ * @author zhenjun cai
+ */
+public abstract class BaseWxCpTpServiceImpl implements WxCpTpService, RequestHttp {
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ /**
+ * 全局的是否正在刷新access token的锁
+ */
+ protected final Object globalSuiteAccessTokenRefreshLock = new Object();
+
+ /**
+ * 全局的是否正在刷新jsapi_ticket的锁
+ */
+ protected final Object globalSuiteTicketRefreshLock = new Object();
+
+
+ protected WxCpTpConfigStorage configStorage;
+
+
+ /**
+ * 临时文件目录
+ */
+ private File tmpDirFile;
+ private int retrySleepMillis = 1000;
+ private int maxRetryTimes = 5;
+
+ @Override
+ public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) {
+ try {
+ return SHA1.gen(this.configStorage.getToken(), timestamp, nonce, data)
+ .equals(msgSignature);
+ } catch (Exception e) {
+ this.log.error("Checking signature failed, and the reason is :" + e.getMessage());
+ return false;
+ }
+ }
+
+ @Override
+ public String getSuiteAccessToken() throws WxErrorException {
+ return getSuiteAccessToken(false);
+ }
+
+ @Override
+ public String getSuiteTicket() throws WxErrorException {
+ return getSuiteTicket(false);
+ }
+
+ @Override
+ public String getSuiteTicket(boolean forceRefresh) throws WxErrorException {
+// suite ticket由微信服务器推送,不能强制刷新
+// if (forceRefresh) {
+// this.configStorage.expireSuiteTicket();
+// }
+
+ if (this.configStorage.isSuiteTicketExpired()) {
+// 本地suite ticket 不存在或者过期
+ WxError wxError = WxError.fromJson("{\"errcode\":40085, \"errmsg\":\"invaild suite ticket\"}", WxType.CP);
+ throw new WxErrorException(wxError);
+ }
+ return this.configStorage.getSuiteTicket();
+ }
+
+
+ @Override
+ public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException {
+ Map params = new HashMap<>(2);
+ params.put("js_code", jsCode);
+ params.put("grant_type", "authorization_code");
+
+ String result = this.get(configStorage.getApiUrl(JSCODE_TO_SESSION_URL), Joiner.on("&").withKeyValueSeparator("=").join(params));
+ return WxCpMaJsCode2SessionResult.fromJson(result);
+ }
+
+
+ @Override
+ public WxAccessToken getCorpToken(String authCorpid, String permanentCode) throws WxErrorException {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("auth_corpid", authCorpid);
+ jsonObject.addProperty("permanent_code", permanentCode);
+ String result = post(configStorage.getApiUrl(GET_CORP_TOKEN), jsonObject.toString());
+
+ return WxAccessToken.fromJson(result);
+ }
+
+
+ @Override
+ public WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("auth_code", authCode);
+
+ String result = post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
+ jsonObject = new JsonParser().parse(result).getAsJsonObject();
+ WxCpTpCorp wxCpTpCorp = WxCpTpCorp.fromJson(jsonObject.get("auth_corp_info").getAsString());
+ wxCpTpCorp.setPermanentCode(jsonObject.get("permanent_code").getAsString());
+ return wxCpTpCorp;
+ }
+
+ @Override
+ public String get(String url, String queryParam) throws WxErrorException {
+ return execute(SimpleGetRequestExecutor.create(this), url, queryParam);
+ }
+
+ @Override
+ public String post(String url, String postData) throws WxErrorException {
+ return execute(SimplePostRequestExecutor.create(this), url, postData);
+ }
+
+ /**
+ * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求.
+ */
+ @Override
+ public T execute(RequestExecutor executor, String uri, E data) throws WxErrorException {
+ int retryTimes = 0;
+ do {
+ try {
+ return this.executeInternal(executor, uri, data);
+ } catch (WxErrorException e) {
+ if (retryTimes + 1 > this.maxRetryTimes) {
+ this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
+ //最后一次重试失败后,直接抛出异常,不再等待
+ throw new RuntimeException("微信服务端异常,超出重试次数");
+ }
+
+ WxError error = e.getError();
+ /*
+ * -1 系统繁忙, 1000ms后重试
+ */
+ if (error.getErrorCode() == -1) {
+ int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
+ try {
+ this.log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
+ Thread.sleep(sleepMillis);
+ } catch (InterruptedException e1) {
+ Thread.currentThread().interrupt();
+ }
+ } else {
+ throw e;
+ }
+ }
+ } while (retryTimes++ < this.maxRetryTimes);
+
+ this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
+ throw new RuntimeException("微信服务端异常,超出重试次数");
+ }
+
+ protected T executeInternal(RequestExecutor executor, String uri, E data) throws WxErrorException {
+ E dataForLog = DataUtils.handleDataWithSecret(data);
+
+ if (uri.contains("suite_access_token=")) {
+ throw new IllegalArgumentException("uri参数中不允许有suite_access_token: " + uri);
+ }
+ String suiteAccessToken = getSuiteAccessToken(false);
+
+ String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "suite_access_token=" + suiteAccessToken;
+
+ try {
+ T result = executor.execute(uriWithAccessToken, data);
+ this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
+ return result;
+ } catch (WxErrorException e) {
+ WxError error = e.getError();
+ /*
+ * 发生以下情况时尝试刷新suite_access_token
+ * 42009 suite_access_token已过期
+ */
+ if (error.getErrorCode() == 42009) {
+ // 强制设置wxCpTpConfigStorage它的suite access token过期了,这样在下一次请求里就会刷新suite access token
+ this.configStorage.expireSuiteAccessToken();
+ return execute(executor, uri, data);
+ }
+
+ if (error.getErrorCode() != 0) {
+ this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
+ throw new WxErrorException(error, e);
+ }
+ return null;
+ } catch (IOException e) {
+ this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void setWxCpTpConfigStorage(WxCpTpConfigStorage wxConfigProvider) {
+ this.configStorage = wxConfigProvider;
+ this.initHttp();
+ }
+
+ @Override
+ public void setRetrySleepMillis(int retrySleepMillis) {
+ this.retrySleepMillis = retrySleepMillis;
+ }
+
+
+ @Override
+ public void setMaxRetryTimes(int maxRetryTimes) {
+ this.maxRetryTimes = maxRetryTimes;
+ }
+
+ public File getTmpDirFile() {
+ return this.tmpDirFile;
+ }
+
+ public void setTmpDirFile(File tmpDirFile) {
+ this.tmpDirFile = tmpDirFile;
+ }
+
+ @Override
+ public RequestHttp, ?> getRequestHttp() {
+ return this;
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
index 10c417729e..2dc5ca8755 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
@@ -1,11 +1,8 @@
package me.chanjar.weixin.cp.api.impl;
-import java.util.List;
-
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
-
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpAgentService;
@@ -13,6 +10,8 @@
import me.chanjar.weixin.cp.bean.WxCpAgent;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import java.util.List;
+
/**
*
@@ -37,13 +36,14 @@ public WxCpAgent get(Integer agentId) throws WxErrorException {
throw new IllegalArgumentException("缺少agentid参数");
}
- String responseContent = this.mainService.get(String.format(WxCpAgentService.GET_AGENT, agentId), null);
+ String responseContent = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpAgentService.GET_AGENT), agentId), null);
return WxCpAgent.fromJson(responseContent);
}
@Override
public void set(WxCpAgent agentInfo) throws WxErrorException {
- String responseContent = this.mainService.post(WxCpAgentService.AGENT_SET, agentInfo.toJson());
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpAgentService.AGENT_SET);
+ String responseContent = this.mainService.post(url, agentInfo.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
@@ -52,7 +52,8 @@ public void set(WxCpAgent agentInfo) throws WxErrorException {
@Override
public List list() throws WxErrorException {
- String responseContent = this.mainService.get(WxCpAgentService.AGENT_LIST, null);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpAgentService.AGENT_LIST);
+ String responseContent = this.mainService.get(url, null);
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
index 0b1fb59381..1bf809502b 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
@@ -47,7 +47,7 @@ public String chatCreate(String name, String owner, List users, String c
if (StringUtils.isNotBlank(chatId)) {
data.put("chatid", chatId);
}
- String result = this.cpService.post(APPCHAT_CREATE, WxGsonBuilder.create().toJson(data));
+ String result = this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_CREATE), WxGsonBuilder.create().toJson(data));
return new JsonParser().parse(result).getAsJsonObject().get("chatid").getAsString();
}
@@ -76,7 +76,7 @@ public void chatUpdate(String chatId, String name, String owner, List us
data.put("del_user_list", usersToDelete);
}
- this.cpService.post(APPCHAT_UPDATE, WxGsonBuilder.create().toJson(data));
+ this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_UPDATE), WxGsonBuilder.create().toJson(data));
}
@Override
@@ -86,7 +86,7 @@ public void update(String chatId, String name, String owner, List usersT
@Override
public WxCpChat chatGet(String chatId) throws WxErrorException {
- String result = this.cpService.get(APPCHAT_GET_CHATID + chatId, null);
+ String result = this.cpService.get(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_GET_CHATID + chatId), null);
return WxCpGsonBuilder.create()
.fromJson(JSON_PARSER.parse(result).getAsJsonObject().getAsJsonObject("chat_info").toString(), WxCpChat.class);
}
@@ -98,7 +98,7 @@ public WxCpChat get(String chatId) throws WxErrorException {
@Override
public void sendMsg(WxCpAppChatMessage message) throws WxErrorException {
- this.cpService.post(WxCpChatService.APPCHAT_SEND, message.toJson());
+ this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(WxCpChatService.APPCHAT_SEND), message.toJson());
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
index 09ded1b8b3..ce6f02ae5f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
@@ -1,7 +1,5 @@
package me.chanjar.weixin.cp.api.impl;
-import java.util.List;
-
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
@@ -12,6 +10,8 @@
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import java.util.List;
+
/**
*
* 部门管理接口
@@ -29,25 +29,27 @@ public WxCpDepartmentServiceImpl(WxCpService mainService) {
@Override
public Long create(WxCpDepart depart) throws WxErrorException {
- String responseContent = this.mainService.post(WxCpDepartmentService.DEPARTMENT_CREATE, depart.toJson());
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_CREATE);
+ String responseContent = this.mainService.post(url, depart.toJson());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("id"));
}
@Override
public void update(WxCpDepart group) throws WxErrorException {
- this.mainService.post(WxCpDepartmentService.DEPARTMENT_UPDATE, group.toJson());
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_UPDATE);
+ this.mainService.post(url, group.toJson());
}
@Override
public void delete(Long departId) throws WxErrorException {
- String url = String.format(WxCpDepartmentService.DEPARTMENT_DELETE, departId);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_DELETE), departId);
this.mainService.get(url, null);
}
@Override
public List list(Long id) throws WxErrorException {
- String url = WxCpDepartmentService.DEPARTMENT_LIST;
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_LIST);
if (id != null) {
url += "?id=" + id;
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java
index 7a3dc444cf..fa31a033ba 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java
@@ -1,18 +1,19 @@
package me.chanjar.weixin.cp.api.impl;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.UUID;
-
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
+import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpService;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.UUID;
+
/**
*
* 媒体管理接口.
@@ -37,7 +38,7 @@ public WxMediaUploadResult upload(String mediaType, String fileType, InputStream
@Override
public WxMediaUploadResult upload(String mediaType, File file) throws WxErrorException {
return this.mainService.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()),
- MEDIA_UPLOAD_URL + mediaType, file);
+ this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_UPLOAD_URL + mediaType), file);
}
@Override
@@ -45,7 +46,7 @@ public File download(String mediaId) throws WxErrorException {
return this.mainService.execute(
BaseMediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(),
this.mainService.getWxCpConfigStorage().getTmpDirFile()),
- MEDIA_GET_URL, "media_id=" + mediaId);
+ this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_GET_URL), "media_id=" + mediaId);
}
@Override
@@ -53,13 +54,13 @@ public File getJssdkFile(String mediaId) throws WxErrorException {
return this.mainService.execute(
BaseMediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(),
this.mainService.getWxCpConfigStorage().getTmpDirFile()),
- JSSDK_MEDIA_GET_URL, "media_id=" + mediaId);
+ this.mainService.getWxCpConfigStorage().getApiUrl(JSSDK_MEDIA_GET_URL), "media_id=" + mediaId);
}
@Override
public String uploadImg(File file) throws WxErrorException {
final WxMediaUploadResult result = this.mainService
- .execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), IMG_UPLOAD_URL, file);
+ .execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD_URL), file);
return result.getUrl();
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
index d33ade0191..a03d600145 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
@@ -2,6 +2,7 @@
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpMenuService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
@@ -28,7 +29,8 @@ public void create(WxMenu menu) throws WxErrorException {
@Override
public void create(Integer agentId, WxMenu menu) throws WxErrorException {
- this.mainService.post(String.format(WxCpMenuService.MENU_CREATE, agentId), menu.toJson());
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpMenuService.MENU_CREATE), agentId);
+ this.mainService.post(url, menu.toJson());
}
@Override
@@ -38,7 +40,7 @@ public void delete() throws WxErrorException {
@Override
public void delete(Integer agentId) throws WxErrorException {
- String url = String.format(WxCpMenuService.MENU_DELETE, agentId);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpMenuService.MENU_DELETE), agentId);
this.mainService.get(url, null);
}
@@ -49,7 +51,7 @@ public WxMenu get() throws WxErrorException {
@Override
public WxMenu get(Integer agentId) throws WxErrorException {
- String url = String.format(WxCpMenuService.MENU_GET, agentId);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpMenuService.MENU_GET), agentId);
try {
String resultContent = this.mainService.get(url, null);
return WxCpGsonBuilder.create().fromJson(resultContent, WxMenu.class);
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
index 6ff91fc35a..aedc9ab24d 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
@@ -69,7 +69,7 @@ public WxCpOauth2UserInfo getUserInfo(String code) throws WxErrorException {
@Override
public WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErrorException {
- String responseText = this.mainService.get(String.format(WxCpOAuth2Service.URL_GET_USER_INFO, code, agentId), null);
+ String responseText = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOAuth2Service.URL_GET_USER_INFO), code, agentId), null);
JsonElement je = new JsonParser().parse(responseText);
JsonObject jo = je.getAsJsonObject();
@@ -86,7 +86,7 @@ public WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErr
public WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("user_ticket", userTicket);
- String responseText = this.mainService.post(WxCpOAuth2Service.URL_GET_USER_DETAIL, param.toString());
+ String responseText = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOAuth2Service.URL_GET_USER_DETAIL), param.toString());
return WxCpGsonBuilder.create().fromJson(responseText, WxCpUserDetail.class);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
index cc3b274495..c0f6ddaab6 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
@@ -59,7 +59,7 @@ public List getCheckinData(Integer openCheckinDataType, Date st
jsonObject.add("useridlist", jsonArray);
- String responseContent = this.mainService.post(WxCpOaService.GET_CHECKIN_DATA, jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_CHECKIN_DATA), jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -88,7 +88,7 @@ public List getCheckinOption(Date datetime, List user
jsonObject.addProperty("datetime", datetime.getTime() / 1000L);
jsonObject.add("useridlist", jsonArray);
- String responseContent = this.mainService.post(WxCpOaService.GET_CHECKIN_OPTION, jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_CHECKIN_OPTION), jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
@@ -108,7 +108,7 @@ public WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long
jsonObject.addProperty("next_spnum", nextSpnum);
}
- String responseContent = this.mainService.post(WxCpOaService.GET_APPROVAL_DATA, jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_APPROVAL_DATA), jsonObject.toString());
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class);
}
@@ -140,7 +140,7 @@ public List getDialRecord(Date startTime, Date endTime, Integer
jsonObject.addProperty("end_time", endtimestamp);
}
- String responseContent = this.mainService.post(WxCpOaService.GET_DIAL_RECORD, jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_DIAL_RECORD), jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
index 11a183b507..6dea258b99 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
@@ -48,7 +48,8 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
synchronized (this.globalAccessTokenRefreshLock) {
- String url = String.format(WxCpService.GET_TOKEN, this.configStorage.getCorpId(), this.configStorage.getCorpSecret());
+ String url = String.format(this.configStorage.getApiUrl(WxCpService.GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret());
+
try {
HttpGet httpGet = new HttpGet(url);
if (this.httpProxy != null) {
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
index d5d08900b9..f1c5c8419a 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
@@ -1,6 +1,10 @@
package me.chanjar.weixin.cp.api.impl;
-import jodd.http.*;
+import jodd.http.HttpConnectionProvider;
+import jodd.http.HttpRequest;
+import jodd.http.HttpResponse;
+import jodd.http.JoddHttp;
+import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.error.WxError;
@@ -39,7 +43,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
synchronized (this.globalAccessTokenRefreshLock) {
- HttpRequest request = HttpRequest.get(String.format(WxCpService.GET_TOKEN, this.configStorage.getCorpId(), this.configStorage.getCorpSecret()));
+ HttpRequest request = HttpRequest.get(String.format(this.configStorage.getApiUrl(WxCpService.GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret()));
if (this.httpProxy != null) {
httpClient.useProxy(this.httpProxy);
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
index f4cc540f3c..4280174dc4 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
@@ -8,7 +8,12 @@
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
-import okhttp3.*;
+import okhttp3.Authenticator;
+import okhttp3.Credentials;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.Route;
import java.io.IOException;
@@ -45,7 +50,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
OkHttpClient client = getRequestHttpClient();
//请求的request
Request request = new Request.Builder()
- .url(String.format(WxCpService.GET_TOKEN, this.configStorage.getCorpId(), this.configStorage.getCorpSecret()))
+ .url(String.format(this.configStorage.getApiUrl(WxCpService.GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret()))
.get()
.build();
String resultContent = null;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java
index 413436207f..ee0db6da9f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImpl.java
@@ -1,6 +1,10 @@
package me.chanjar.weixin.cp.api.impl;
-import com.google.gson.*;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
@@ -32,27 +36,31 @@ public WxCpTagServiceImpl(WxCpService mainService) {
public String create(String tagName) throws WxErrorException {
JsonObject o = new JsonObject();
o.addProperty("tagname", tagName);
- String responseContent = this.mainService.post(WxCpTagService.TAG_CREATE, o.toString());
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_CREATE);
+ String responseContent = this.mainService.post(url, o.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
}
@Override
public void update(String tagId, String tagName) throws WxErrorException {
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_UPDATE);
JsonObject o = new JsonObject();
o.addProperty("tagid", tagId);
o.addProperty("tagname", tagName);
- this.mainService.post(WxCpTagService.TAG_UPDATE, o.toString());
+ this.mainService.post(url, o.toString());
}
@Override
public void delete(String tagId) throws WxErrorException {
- this.mainService.get(String.format(WxCpTagService.TAG_DELETE, tagId), null);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_DELETE), tagId);
+ this.mainService.get(url, null);
}
@Override
public List listAll() throws WxErrorException {
- String responseContent = this.mainService.get(WxCpTagService.TAG_LIST, null);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_LIST);
+ String responseContent = this.mainService.get(url, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -64,7 +72,8 @@ public List listAll() throws WxErrorException {
@Override
public List listUsersByTagId(String tagId) throws WxErrorException {
- String responseContent = this.mainService.get(String.format(WxCpTagService.TAG_GET, tagId), null);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_GET), tagId);
+ String responseContent = this.mainService.get(url, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -76,20 +85,22 @@ public List listUsersByTagId(String tagId) throws WxErrorException {
@Override
public WxCpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List userIds, List partyIds) throws WxErrorException {
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_ADDTAGUSERS);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tagid", tagId);
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
- return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(WxCpTagService.TAG_ADDTAGUSERS, jsonObject.toString()));
+ return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
}
@Override
public WxCpTagAddOrRemoveUsersResult removeUsersFromTag(String tagId, List userIds, List partyIds) throws WxErrorException {
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_DELTAGUSERS);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tagid", tagId);
this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);
- return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(WxCpTagService.TAG_DELTAGUSERS, jsonObject.toString()));
+ return WxCpTagAddOrRemoveUsersResult.fromJson(this.mainService.post(url, jsonObject.toString()));
}
private void addUserIdsAndPartyIdsToJson(List userIds, List partyIds, JsonObject jsonObject) {
@@ -116,7 +127,8 @@ public WxCpTagGetResult get(String tagId) throws WxErrorException {
throw new IllegalArgumentException("缺少tagId参数");
}
- String responseContent = this.mainService.get(String.format(WxCpTagService.TAG_GET, tagId), null);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_GET), tagId);
+ String responseContent = this.mainService.get(url, null);
return WxCpTagGetResult.fromJson(responseContent);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java
index e70a7d376a..a2efabb497 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java
@@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
+import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpTaskCardService;
@@ -33,6 +34,7 @@ public void update(List userIds, String taskId, String clickedKey) throw
data.put("task_id", taskId);
data.put("clicked_key", clickedKey);
- this.mainService.post(MESSAGE_UPDATE_TASKCARD, WxGsonBuilder.create().toJson(data));
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(MESSAGE_UPDATE_TASKCARD);
+ this.mainService.post(url, WxGsonBuilder.create().toJson(data));
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java
index f673a622bd..04bc0a5f6e 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTpServiceApacheHttpClientImpl.java
@@ -52,7 +52,7 @@ public String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException
synchronized (this.globalSuiteAccessTokenRefreshLock) {
try {
- HttpPost httpPost = new HttpPost(WxCpTpService.GET_SUITE_TOKEN);
+ HttpPost httpPost = new HttpPost(configStorage.getApiUrl(WxCpTpService.GET_SUITE_TOKEN));
if (this.httpProxy != null) {
RequestConfig config = RequestConfig.custom()
.setProxy(this.httpProxy).build();
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
index b3b0909522..c38a680125 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
@@ -1,8 +1,5 @@
package me.chanjar.weixin.cp.api.impl;
-import java.util.List;
-import java.util.Map;
-
import com.google.common.collect.Maps;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -11,6 +8,7 @@
import com.google.gson.JsonPrimitive;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
@@ -18,6 +16,9 @@
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import java.util.List;
+import java.util.Map;
+
/**
*
* Created by BinaryWang on 2017/6/24.
@@ -34,23 +35,26 @@ public WxCpUserServiceImpl(WxCpService mainService) {
@Override
public void authenticate(String userId) throws WxErrorException {
- this.mainService.get(WxCpUserService.URL_AUTHENTICATE + userId, null);
+ this.mainService.get(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_AUTHENTICATE + userId), null);
}
@Override
public void create(WxCpUser user) throws WxErrorException {
- this.mainService.post(WxCpUserService.URL_USER_CREATE, user.toJson());
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_USER_CREATE);
+ this.mainService.post(url, user.toJson());
}
@Override
public void update(WxCpUser user) throws WxErrorException {
- this.mainService.post(WxCpUserService.URL_USER_UPDATE, user.toJson());
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_USER_UPDATE);
+ this.mainService.post(url, user.toJson());
}
@Override
public void delete(String... userIds) throws WxErrorException {
if (userIds.length == 1) {
- this.mainService.get(WxCpUserService.URL_USER_DELETE + userIds[0], null);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_USER_DELETE + userIds[0]);
+ this.mainService.get(url, null);
return;
}
@@ -66,7 +70,8 @@ public void delete(String... userIds) throws WxErrorException {
@Override
public WxCpUser getById(String userid) throws WxErrorException {
- String responseContent = this.mainService.get(WxCpUserService.URL_USER_GET + userid, null);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_USER_GET + userid);
+ String responseContent = this.mainService.get(url, null);
return WxCpUser.fromJson(responseContent);
}
@@ -82,7 +87,8 @@ public List listByDepartment(Long departId, Boolean fetchChild, Intege
params += "&status=0";
}
- String responseContent = this.mainService.get(WxCpUserService.URL_USER_LIST + departId, params);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_USER_LIST + departId);
+ String responseContent = this.mainService.get(url, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("userlist"),
@@ -103,7 +109,8 @@ public List listSimpleByDepartment(Long departId, Boolean fetchChild,
params += "&status=0";
}
- String responseContent = this.mainService.get(WxCpUserService.URL_USER_SIMPLE_LIST + departId, params);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_USER_SIMPLE_LIST + departId);
+ String responseContent = this.mainService.get(url, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -140,18 +147,20 @@ public WxCpInviteResult invite(List userIds, List partyIds, List
jsonObject.add("tag", jsonArray);
}
- return WxCpInviteResult.fromJson(this.mainService.post(WxCpUserService.URL_BATCH_INVITE, jsonObject.toString()));
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_BATCH_INVITE);
+ return WxCpInviteResult.fromJson(this.mainService.post(url, jsonObject.toString()));
}
@Override
public Map userId2Openid(String userId, Integer agentId) throws WxErrorException {
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_CONVERT_TO_OPENID);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
if (agentId != null) {
jsonObject.addProperty("agentid", agentId);
}
- String responseContent = this.mainService.post(WxCpUserService.URL_CONVERT_TO_OPENID, jsonObject.toString());
+ String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
Map result = Maps.newHashMap();
if (tmpJsonElement.getAsJsonObject().get("openid") != null) {
@@ -169,14 +178,16 @@ public Map userId2Openid(String userId, Integer agentId) throws
public String openid2UserId(String openid) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("openid", openid);
- String responseContent = this.mainService.post(WxCpUserService.URL_CONVERT_TO_USERID, jsonObject.toString());
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_CONVERT_TO_USERID);
+ String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
}
@Override
public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException {
- String responseContent = this.mainService.get(WxCpUserService.URL_GET_EXTERNAL_CONTACT + userId, null);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpUserService.URL_GET_EXTERNAL_CONTACT + userId);
+ String responseContent = this.mainService.get(url, null);
return WxCpUserExternalContactInfo.fromJson(responseContent);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpConfigStorage.java
index e13738142f..a75ad1dfb1 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpConfigStorage.java
@@ -12,6 +12,22 @@
*/
public interface WxCpConfigStorage {
+ /**
+ * 设置企业微信服务器 baseUrl.
+ *
+ * 默认值是 https://qyapi.weixin.qq.com , 如果使用默认值,则不需要调用 setBaseApiUrl
+ *
+ * @param baseUrl 企业微信服务器 Url
+ */
+ void setBaseApiUrl(String baseUrl);
+
+ /**
+ * 读取企业微信 API Url.
+ *
+ * 支持私有化企业微信服务器.
+ */
+ String getApiUrl(String path);
+
String getAccessToken();
boolean isAccessTokenExpired();
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpInMemoryConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpInMemoryConfigStorage.java
index a501edeb6e..31e2a211d5 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpInMemoryConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpInMemoryConfigStorage.java
@@ -39,6 +39,21 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
+ protected volatile String baseApiUrl;
+
+ @Override
+ public void setBaseApiUrl(String baseUrl) {
+ this.baseApiUrl = baseUrl;
+ }
+
+ @Override
+ public String getApiUrl(String path) {
+ if (baseApiUrl == null) {
+ baseApiUrl = "https://qyapi.weixin.qq.com";
+ }
+ return baseApiUrl + path;
+ }
+
@Override
public String getAccessToken() {
return this.accessToken;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java
index 7c72de0e1b..b8deef1d51 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpJedisConfigStorage.java
@@ -38,6 +38,21 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage {
private volatile File tmpDirFile;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
+ protected volatile String baseApiUrl;
+
+ @Override
+ public void setBaseApiUrl(String baseUrl) {
+ this.baseApiUrl = baseUrl;
+ }
+
+ @Override
+ public String getApiUrl(String path) {
+ if (baseApiUrl == null) {
+ baseApiUrl = "https://qyapi.weixin.qq.com";
+ }
+ return baseApiUrl + path;
+ }
+
public WxCpJedisConfigStorage(JedisPool jedisPool) {
this.jedisPool = jedisPool;
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpConfigStorage.java
index a132dd1024..44ef4e17be 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpConfigStorage.java
@@ -1,72 +1,88 @@
-package me.chanjar.weixin.cp.config;
-
-import me.chanjar.weixin.common.bean.WxAccessToken;
-import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
-
-import java.io.File;
-
-/**
- * 微信客户端(第三方应用)配置存储
- *
- * @author zhenjun cai
- */
-public interface WxCpTpConfigStorage {
-
- String getSuiteAccessToken();
-
- boolean isSuiteAccessTokenExpired();
-
- /**
- * 强制将suite access token过期掉
- */
- void expireSuiteAccessToken();
-
- void updateSuiteAccessToken(WxAccessToken suiteAccessToken);
-
- void updateSuiteAccessToken(String suiteAccessToken, int expiresIn);
-
- String getSuiteTicket();
-
- boolean isSuiteTicketExpired();
-
- /**
- * 强制将suite ticket过期掉
- */
- void expireSuiteTicket();
-
- /**
- * 应该是线程安全的
- */
- void updateSuiteTicket(String suiteTicket, int expiresInSeconds);
-
- String getCorpId();
-
- String getCorpSecret();
-
- String getSuiteId();
-
- String getSuiteSecret();
-
- String getToken();
-
- String getAesKey();
-
- long getExpiresTime();
-
- String getHttpProxyHost();
-
- int getHttpProxyPort();
-
- String getHttpProxyUsername();
-
- String getHttpProxyPassword();
-
- File getTmpDirFile();
-
- /**
- * http client builder
- *
- * @return ApacheHttpClientBuilder
- */
- ApacheHttpClientBuilder getApacheHttpClientBuilder();
-}
+package me.chanjar.weixin.cp.config;
+
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
+
+import java.io.File;
+
+/**
+ * 微信客户端(第三方应用)配置存储
+ *
+ * @author zhenjun cai
+ */
+public interface WxCpTpConfigStorage {
+
+ /**
+ * 设置企业微信服务器 baseUrl.
+ *
+ * 默认值是 https://qyapi.weixin.qq.com , 如果使用默认值,则不需要调用 setBaseApiUrl
+ *
+ * @param baseUrl 企业微信服务器 Url
+ */
+ void setBaseApiUrl(String baseUrl);
+
+ /**
+ * 读取企业微信 API Url.
+ *
+ * 支持私有化企业微信服务器.
+ */
+ String getApiUrl(String path);
+
+ String getSuiteAccessToken();
+
+ boolean isSuiteAccessTokenExpired();
+
+ /**
+ * 强制将suite access token过期掉
+ */
+ void expireSuiteAccessToken();
+
+ void updateSuiteAccessToken(WxAccessToken suiteAccessToken);
+
+ void updateSuiteAccessToken(String suiteAccessToken, int expiresIn);
+
+ String getSuiteTicket();
+
+ boolean isSuiteTicketExpired();
+
+ /**
+ * 强制将suite ticket过期掉
+ */
+ void expireSuiteTicket();
+
+ /**
+ * 应该是线程安全的
+ */
+ void updateSuiteTicket(String suiteTicket, int expiresInSeconds);
+
+ String getCorpId();
+
+ String getCorpSecret();
+
+ String getSuiteId();
+
+ String getSuiteSecret();
+
+ String getToken();
+
+ String getAesKey();
+
+ long getExpiresTime();
+
+ String getHttpProxyHost();
+
+ int getHttpProxyPort();
+
+ String getHttpProxyUsername();
+
+ String getHttpProxyPassword();
+
+ File getTmpDirFile();
+
+ /**
+ * http client builder
+ *
+ * @return ApacheHttpClientBuilder
+ */
+ ApacheHttpClientBuilder getApacheHttpClientBuilder();
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpInMemoryConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpInMemoryConfigStorage.java
index c135c95b7f..6da47f5b72 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpInMemoryConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpInMemoryConfigStorage.java
@@ -1,230 +1,245 @@
-package me.chanjar.weixin.cp.config;
-
-import me.chanjar.weixin.common.bean.WxAccessToken;
-import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
-import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
-
-import java.io.File;
-
-/**
- * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
- *
- * @author Daniel Qian
- */
-public class WxCpTpInMemoryConfigStorage implements WxCpTpConfigStorage {
- protected volatile String corpId;
- protected volatile String corpSecret;
-
- protected volatile String suiteId;
- protected volatile String suiteSecret;
-
- protected volatile String token;
- protected volatile String suiteAccessToken;
- protected volatile String aesKey;
- protected volatile long expiresTime;
-
- protected volatile String oauth2redirectUri;
-
- protected volatile String httpProxyHost;
- protected volatile int httpProxyPort;
- protected volatile String httpProxyUsername;
- protected volatile String httpProxyPassword;
-
- protected volatile String suiteTicket;
- protected volatile long suiteTicketExpiresTime;
-
-
- protected volatile File tmpDirFile;
-
- private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
-
- @Override
- public String getSuiteAccessToken() {
- return this.suiteAccessToken;
- }
-
- public void setSuiteAccessToken(String suiteAccessToken) {
- this.suiteAccessToken = suiteAccessToken;
- }
-
- @Override
- public boolean isSuiteAccessTokenExpired() {
- return System.currentTimeMillis() > this.expiresTime;
- }
-
- @Override
- public void expireSuiteAccessToken() {
- this.expiresTime = 0;
- }
-
- @Override
- public synchronized void updateSuiteAccessToken(WxAccessToken suiteAccessToken) {
- updateSuiteAccessToken(suiteAccessToken.getAccessToken(), suiteAccessToken.getExpiresIn());
- }
-
- @Override
- public synchronized void updateSuiteAccessToken(String suiteAccessToken, int expiresInSeconds) {
- this.suiteAccessToken = suiteAccessToken;
- this.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
- }
-
- @Override
- public String getCorpId() {
- return this.corpId;
- }
-
- public void setCorpId(String corpId) {
- this.corpId = corpId;
- }
-
- @Override
- public String getCorpSecret() {
- return this.corpSecret;
- }
-
- public void setCorpSecret(String corpSecret) {
- this.corpSecret = corpSecret;
- }
-
- @Override
- public String getSuiteTicket() {
- return this.suiteTicket;
- }
-
- public void setSuiteTicket(String suiteTicket) {
- this.suiteTicket = suiteTicket;
- }
-
- public long getSuiteTicketExpiresTime() {
- return this.suiteTicketExpiresTime;
- }
-
- public void setSuiteTicketExpiresTime(long suiteTicketExpiresTime) {
- this.suiteTicketExpiresTime = suiteTicketExpiresTime;
- }
-
- @Override
- public boolean isSuiteTicketExpired() {
- return System.currentTimeMillis() > this.suiteTicketExpiresTime;
- }
-
- @Override
- public synchronized void updateSuiteTicket(String suiteTicket, int expiresInSeconds) {
- this.suiteTicket = suiteTicket;
- // 预留200秒的时间
- this.suiteTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
- }
-
- @Override
- public void expireSuiteTicket() {
- this.suiteTicketExpiresTime = 0;
- }
-
- @Override
- public String getSuiteId() {
- return this.suiteId;
- }
-
- public void setSuiteId(String corpId) {
- this.suiteId = corpId;
- }
-
- @Override
- public String getSuiteSecret() {
- return this.suiteSecret;
- }
-
- public void setSuiteSecret(String corpSecret) {
- this.suiteSecret = corpSecret;
- }
-
- @Override
- public String getToken() {
- return this.token;
- }
-
- public void setToken(String token) {
- this.token = token;
- }
-
- @Override
- public long getExpiresTime() {
- return this.expiresTime;
- }
-
- public void setExpiresTime(long expiresTime) {
- this.expiresTime = expiresTime;
- }
-
- @Override
- public String getAesKey() {
- return this.aesKey;
- }
-
- public void setAesKey(String aesKey) {
- this.aesKey = aesKey;
- }
-
- public void setOauth2redirectUri(String oauth2redirectUri) {
- this.oauth2redirectUri = oauth2redirectUri;
- }
-
- @Override
- public String getHttpProxyHost() {
- return this.httpProxyHost;
- }
-
- public void setHttpProxyHost(String httpProxyHost) {
- this.httpProxyHost = httpProxyHost;
- }
-
- @Override
- public int getHttpProxyPort() {
- return this.httpProxyPort;
- }
-
- public void setHttpProxyPort(int httpProxyPort) {
- this.httpProxyPort = httpProxyPort;
- }
-
- @Override
- public String getHttpProxyUsername() {
- return this.httpProxyUsername;
- }
-
- public void setHttpProxyUsername(String httpProxyUsername) {
- this.httpProxyUsername = httpProxyUsername;
- }
-
- @Override
- public String getHttpProxyPassword() {
- return this.httpProxyPassword;
- }
-
- public void setHttpProxyPassword(String httpProxyPassword) {
- this.httpProxyPassword = httpProxyPassword;
- }
-
- @Override
- public String toString() {
- return WxCpGsonBuilder.create().toJson(this);
- }
-
- @Override
- public File getTmpDirFile() {
- return this.tmpDirFile;
- }
-
- public void setTmpDirFile(File tmpDirFile) {
- this.tmpDirFile = tmpDirFile;
- }
-
- @Override
- public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
- return this.apacheHttpClientBuilder;
- }
-
- public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
- this.apacheHttpClientBuilder = apacheHttpClientBuilder;
- }
-}
+package me.chanjar.weixin.cp.config;
+
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
+import java.io.File;
+
+/**
+ * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
+ *
+ * @author Daniel Qian
+ */
+public class WxCpTpInMemoryConfigStorage implements WxCpTpConfigStorage {
+ protected volatile String corpId;
+ protected volatile String corpSecret;
+
+ protected volatile String suiteId;
+ protected volatile String suiteSecret;
+
+ protected volatile String token;
+ protected volatile String suiteAccessToken;
+ protected volatile String aesKey;
+ protected volatile long expiresTime;
+
+ protected volatile String oauth2redirectUri;
+
+ protected volatile String httpProxyHost;
+ protected volatile int httpProxyPort;
+ protected volatile String httpProxyUsername;
+ protected volatile String httpProxyPassword;
+
+ protected volatile String suiteTicket;
+ protected volatile long suiteTicketExpiresTime;
+
+
+ protected volatile File tmpDirFile;
+
+ private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
+
+ protected volatile String baseApiUrl;
+
+ @Override
+ public void setBaseApiUrl(String baseUrl) {
+ this.baseApiUrl = baseUrl;
+ }
+
+ @Override
+ public String getApiUrl(String path) {
+ if (baseApiUrl == null) {
+ baseApiUrl = "https://qyapi.weixin.qq.com";
+ }
+ return baseApiUrl + path;
+ }
+
+ @Override
+ public String getSuiteAccessToken() {
+ return this.suiteAccessToken;
+ }
+
+ public void setSuiteAccessToken(String suiteAccessToken) {
+ this.suiteAccessToken = suiteAccessToken;
+ }
+
+ @Override
+ public boolean isSuiteAccessTokenExpired() {
+ return System.currentTimeMillis() > this.expiresTime;
+ }
+
+ @Override
+ public void expireSuiteAccessToken() {
+ this.expiresTime = 0;
+ }
+
+ @Override
+ public synchronized void updateSuiteAccessToken(WxAccessToken suiteAccessToken) {
+ updateSuiteAccessToken(suiteAccessToken.getAccessToken(), suiteAccessToken.getExpiresIn());
+ }
+
+ @Override
+ public synchronized void updateSuiteAccessToken(String suiteAccessToken, int expiresInSeconds) {
+ this.suiteAccessToken = suiteAccessToken;
+ this.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
+ }
+
+ @Override
+ public String getCorpId() {
+ return this.corpId;
+ }
+
+ public void setCorpId(String corpId) {
+ this.corpId = corpId;
+ }
+
+ @Override
+ public String getCorpSecret() {
+ return this.corpSecret;
+ }
+
+ public void setCorpSecret(String corpSecret) {
+ this.corpSecret = corpSecret;
+ }
+
+ @Override
+ public String getSuiteTicket() {
+ return this.suiteTicket;
+ }
+
+ public void setSuiteTicket(String suiteTicket) {
+ this.suiteTicket = suiteTicket;
+ }
+
+ public long getSuiteTicketExpiresTime() {
+ return this.suiteTicketExpiresTime;
+ }
+
+ public void setSuiteTicketExpiresTime(long suiteTicketExpiresTime) {
+ this.suiteTicketExpiresTime = suiteTicketExpiresTime;
+ }
+
+ @Override
+ public boolean isSuiteTicketExpired() {
+ return System.currentTimeMillis() > this.suiteTicketExpiresTime;
+ }
+
+ @Override
+ public synchronized void updateSuiteTicket(String suiteTicket, int expiresInSeconds) {
+ this.suiteTicket = suiteTicket;
+ // 预留200秒的时间
+ this.suiteTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
+ }
+
+ @Override
+ public void expireSuiteTicket() {
+ this.suiteTicketExpiresTime = 0;
+ }
+
+ @Override
+ public String getSuiteId() {
+ return this.suiteId;
+ }
+
+ public void setSuiteId(String corpId) {
+ this.suiteId = corpId;
+ }
+
+ @Override
+ public String getSuiteSecret() {
+ return this.suiteSecret;
+ }
+
+ public void setSuiteSecret(String corpSecret) {
+ this.suiteSecret = corpSecret;
+ }
+
+ @Override
+ public String getToken() {
+ return this.token;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+
+ @Override
+ public long getExpiresTime() {
+ return this.expiresTime;
+ }
+
+ public void setExpiresTime(long expiresTime) {
+ this.expiresTime = expiresTime;
+ }
+
+ @Override
+ public String getAesKey() {
+ return this.aesKey;
+ }
+
+ public void setAesKey(String aesKey) {
+ this.aesKey = aesKey;
+ }
+
+ public void setOauth2redirectUri(String oauth2redirectUri) {
+ this.oauth2redirectUri = oauth2redirectUri;
+ }
+
+ @Override
+ public String getHttpProxyHost() {
+ return this.httpProxyHost;
+ }
+
+ public void setHttpProxyHost(String httpProxyHost) {
+ this.httpProxyHost = httpProxyHost;
+ }
+
+ @Override
+ public int getHttpProxyPort() {
+ return this.httpProxyPort;
+ }
+
+ public void setHttpProxyPort(int httpProxyPort) {
+ this.httpProxyPort = httpProxyPort;
+ }
+
+ @Override
+ public String getHttpProxyUsername() {
+ return this.httpProxyUsername;
+ }
+
+ public void setHttpProxyUsername(String httpProxyUsername) {
+ this.httpProxyUsername = httpProxyUsername;
+ }
+
+ @Override
+ public String getHttpProxyPassword() {
+ return this.httpProxyPassword;
+ }
+
+ public void setHttpProxyPassword(String httpProxyPassword) {
+ this.httpProxyPassword = httpProxyPassword;
+ }
+
+ @Override
+ public String toString() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+ @Override
+ public File getTmpDirFile() {
+ return this.tmpDirFile;
+ }
+
+ public void setTmpDirFile(File tmpDirFile) {
+ this.tmpDirFile = tmpDirFile;
+ }
+
+ @Override
+ public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
+ return this.apacheHttpClientBuilder;
+ }
+
+ public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
+ this.apacheHttpClientBuilder = apacheHttpClientBuilder;
+ }
+}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java
index a2dc46e826..9fabe55068 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java
@@ -2,6 +2,7 @@
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpService;
@@ -14,7 +15,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
/**
@@ -70,7 +70,7 @@ public static class MockTest {
@Test
public void testGet() throws Exception {
String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"agentid\": 9,\"name\": \"测试应用\",\"square_logo_url\": \"http://wx.qlogo.cn/mmhead/alksjf;lasdjf;lasjfuodiuj3rj2o34j/0\",\"description\": \"这是一个企业号应用\",\"allow_userinfos\": {\"user\": [{\"userid\": \"0009854\"}, {\"userid\": \"1723\"}, {\"userid\": \"5625\"}]},\"allow_partys\": {\"partyid\": [42762742]},\"allow_tags\": {\"tagid\": [23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7]},\"close\": 0,\"redirect_domain\": \"weixin.com.cn\",\"report_location_flag\": 0,\"isreportenter\": 0,\"home_url\": \"\"}";
- when(wxService.get(String.format(WxCpAgentService.GET_AGENT, 9), null)).thenReturn(returnJson);
+ when(wxService.get(String.format(wxService.getWxCpConfigStorage().getApiUrl(WxCpAgentService.GET_AGENT), 9), null)).thenReturn(returnJson);
when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService));
WxCpAgentService wxAgentService = this.wxService.getAgentService();
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java
index c4c8b3ccb5..858fde203c 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpTagServiceImplTest.java
@@ -17,7 +17,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
/**
@@ -83,7 +82,7 @@ public void testDelete() throws Exception {
public void testGet() throws WxErrorException {
String apiResultJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"userlist\": [{\"userid\": \"0124035\",\"name\": \"王五\"},{\"userid\": \"0114035\",\"name\": \"梦雪\"}],\"partylist\": [9576,9567,9566],\"tagname\": \"测试标签-001\"}";
WxCpService wxService = mock(WxCpService.class);
- when(wxService.get(String.format(WxCpTagService.TAG_GET, 150), null)).thenReturn(apiResultJson);
+ when(wxService.get(String.format(wxService.getWxCpConfigStorage().getApiUrl(WxCpTagService.TAG_GET), 150), null)).thenReturn(apiResultJson);
when(wxService.getTagService()).thenReturn(new WxCpTagServiceImpl(wxService));
WxCpTagService wxCpTagService = wxService.getTagService();
From 07d0656deca2a11364e2cf3c73aa2092c7210290 Mon Sep 17 00:00:00 2001
From: Binary Wang
Date: Sun, 2 Jun 2019 15:23:11 +0800
Subject: [PATCH 11/74] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?=
=?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=8E=A5=E5=8F=A3=E5=9C=B0=E5=9D=80=E5=B8=B8?=
=?UTF-8?q?=E9=87=8F=E4=BC=98=E5=8C=96=E9=87=8D=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../weixin/cp/api/WxCpAgentService.java | 4 -
.../weixin/cp/api/WxCpChatService.java | 4 -
.../weixin/cp/api/WxCpDepartmentService.java | 4 -
.../weixin/cp/api/WxCpMediaService.java | 4 -
.../weixin/cp/api/WxCpMenuService.java | 3 -
.../weixin/cp/api/WxCpOAuth2Service.java | 3 -
.../chanjar/weixin/cp/api/WxCpOaService.java | 4 -
.../me/chanjar/weixin/cp/api/WxCpService.java | 10 --
.../chanjar/weixin/cp/api/WxCpTagService.java | 7 --
.../weixin/cp/api/WxCpTaskCardService.java | 1 -
.../chanjar/weixin/cp/api/WxCpTpService.java | 4 -
.../weixin/cp/api/WxCpUserService.java | 12 --
.../cp/api/impl/BaseWxCpServiceImpl.java | 37 +++---
.../cp/api/impl/BaseWxCpTpServiceImpl.java | 69 ++++++------
.../cp/api/impl/WxCpAgentServiceImpl.java | 16 +--
.../cp/api/impl/WxCpChatServiceImpl.java | 16 +--
.../api/impl/WxCpDepartmentServiceImpl.java | 19 ++--
.../cp/api/impl/WxCpMediaServiceImpl.java | 20 ++--
.../cp/api/impl/WxCpMenuServiceImpl.java | 18 +--
.../cp/api/impl/WxCpOAuth2ServiceImpl.java | 14 ++-
.../weixin/cp/api/impl/WxCpOaServiceImpl.java | 23 ++--
.../impl/WxCpServiceApacheHttpClientImpl.java | 8 +-
.../cp/api/impl/WxCpServiceJoddHttpImpl.java | 13 ++-
.../cp/api/impl/WxCpServiceOkHttpImpl.java | 18 ++-
.../cp/api/impl/WxCpServiceOnTpImpl.java | 70 ++++++------
.../cp/api/impl/WxCpTagServiceImpl.java | 35 +++---
.../cp/api/impl/WxCpTaskCardServiceImpl.java | 6 +-
.../WxCpTpServiceApacheHttpClientImpl.java | 4 +-
.../weixin/cp/api/impl/WxCpTpServiceImpl.java | 24 ++--
.../cp/api/impl/WxCpUserServiceImpl.java | 40 +++----
.../weixin/cp/bean/WxCpAppChatMessage.java | 2 +-
.../weixin/cp/bean/WxCpXmlMessage.java | 2 +-
.../weixin/cp/config/WxCpConfigStorage.java | 16 ++-
.../cp/config/WxCpInMemoryConfigStorage.java | 4 +-
.../cp/config/WxCpJedisConfigStorage.java | 3 +-
.../weixin/cp/constant/WxCpApiPathConsts.java | 106 ++++++++++++++++++
.../weixin/cp/{ => constant}/WxCpConsts.java | 2 +-
.../cp/api/impl/WxCpAgentServiceImplTest.java | 4 +-
.../cp/api/impl/WxCpChatServiceImplTest.java | 2 +-
.../cp/api/impl/WxCpTagServiceImplTest.java | 3 +-
.../weixin/cp/bean/WxCpXmlMessageTest.java | 2 +-
.../weixin/cp/demo/WxCpDemoServer.java | 2 +-
42 files changed, 348 insertions(+), 310 deletions(-)
create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
rename weixin-java-cp/src/main/java/me/chanjar/weixin/cp/{ => constant}/WxCpConsts.java (99%)
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
index 7dad7b6c76..d57ca56c21 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java
@@ -15,10 +15,6 @@
* @author huansinho
*/
public interface WxCpAgentService {
- String GET_AGENT = "/cgi-bin/agent/get?agentid=%d";
- String AGENT_SET = "/cgi-bin/agent/set";
- String AGENT_LIST = "/cgi-bin/agent/list";
-
/**
*
* 获取企业号应用信息
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
index 58ab329f01..741ee906d5 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpChatService.java
@@ -12,10 +12,6 @@
* @author gaigeshen
*/
public interface WxCpChatService {
- String APPCHAT_CREATE = "/cgi-bin/appchat/create";
- String APPCHAT_UPDATE = "/cgi-bin/appchat/update";
- String APPCHAT_GET_CHATID = "/cgi-bin/appchat/get?chatid=";
- String APPCHAT_SEND = "/cgi-bin/appchat/send";
@Deprecated
String chatCreate(String name, String owner, List users, String chatId) throws WxErrorException;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
index 8aa7ca353a..c86816b7f2 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java
@@ -14,10 +14,6 @@
* @author Binary Wang
*/
public interface WxCpDepartmentService {
- String DEPARTMENT_CREATE = "/cgi-bin/department/create";
- String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
- String DEPARTMENT_DELETE = "/cgi-bin/department/delete?id=%d";
- String DEPARTMENT_LIST = "/cgi-bin/department/list";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java
index 67c67ec625..a51e04e175 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMediaService.java
@@ -16,10 +16,6 @@
* @author Binary Wang
*/
public interface WxCpMediaService {
- String MEDIA_GET_URL = "/cgi-bin/media/get";
- String MEDIA_UPLOAD_URL = "/cgi-bin/media/upload?type=";
- String IMG_UPLOAD_URL = "/cgi-bin/media/uploadimg";
- String JSSDK_MEDIA_GET_URL = "/cgi-bin/media/get/jssdk";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
index 7c0a01e595..309b981211 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMenuService.java
@@ -12,9 +12,6 @@
* @author Binary Wang
*/
public interface WxCpMenuService {
- String MENU_CREATE = "/cgi-bin/menu/create?agentid=%d";
- String MENU_DELETE = "/cgi-bin/menu/delete?agentid=%d";
- String MENU_GET = "/cgi-bin/menu/get?agentid=%d";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
index 39d2163e7b..7c42ea63fc 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOAuth2Service.java
@@ -13,9 +13,6 @@
* @author Binary Wang
*/
public interface WxCpOAuth2Service {
- String URL_GET_USER_INFO = "/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
- String URL_GET_USER_DETAIL = "/cgi-bin/user/getuserdetail";
- String URL_OAUTH_2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
index 5cca9e7788..c6f90d3e64 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java
@@ -16,10 +16,6 @@
* @date 2019-04-06 10:52
*/
public interface WxCpOaService {
- String GET_CHECKIN_DATA = "/cgi-bin/checkin/getcheckindata";
- String GET_CHECKIN_OPTION = "/cgi-bin/checkin/getcheckinoption";
- String GET_APPROVAL_DATA = "/cgi-bin/corp/getapprovaldata";
- String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record";
/**
*
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 12ae987b1b..aeb7ff0956 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
@@ -17,16 +17,6 @@
* @author chanjaster
*/
public interface WxCpService {
- String GET_JSAPI_TICKET = "/cgi-bin/get_jsapi_ticket";
- String GET_AGENT_CONFIG_TICKET = "/cgi-bin/ticket/get?&type=agent_config";
- String MESSAGE_SEND = "/cgi-bin/message/send";
- String GET_CALLBACK_IP = "/cgi-bin/getcallbackip";
- String BATCH_REPLACE_PARTY = "/cgi-bin/batch/replaceparty";
- String BATCH_REPLACE_USER = "/cgi-bin/batch/replaceuser";
- String BATCH_GET_RESULT = "/cgi-bin/batch/getresult?jobid=";
- String JSCODE_TO_SESSION_URL = "/cgi-bin/miniprogram/jscode2session";
- String GET_TOKEN = "/cgi-bin/gettoken?&corpid=%s&corpsecret=%s";
-
/**
*
* 验证推送过来的消息的正确性
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
index ee1b526d64..78f1d79139 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTagService.java
@@ -17,13 +17,6 @@
* @author Binary Wang
*/
public interface WxCpTagService {
- String TAG_CREATE = "/cgi-bin/tag/create";
- String TAG_UPDATE = "/cgi-bin/tag/update";
- String TAG_DELETE = "/cgi-bin/tag/delete?tagid=%s";
- String TAG_LIST = "/cgi-bin/tag/list";
- String TAG_GET = "/cgi-bin/tag/get?tagid=%s";
- String TAG_ADDTAGUSERS = "/cgi-bin/tag/addtagusers";
- String TAG_DELTAGUSERS = "/cgi-bin/tag/deltagusers";
/**
* 创建标签.
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
index b6ebdc1202..5bf50d36dc 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java
@@ -14,7 +14,6 @@
* @date 2019-05-16
*/
public interface WxCpTaskCardService {
- String MESSAGE_UPDATE_TASKCARD = "/cgi-bin/message/update_taskcard";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
index 6c52bcfde6..40ffcf55e2 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTpService.java
@@ -15,10 +15,6 @@
* @author zhenjun cai
*/
public interface WxCpTpService {
- String JSCODE_TO_SESSION_URL = "/cgi-bin/service/miniprogram/jscode2session";
- String GET_CORP_TOKEN = "/cgi-bin/service/get_corp_token";
- String GET_PERMANENT_CODE = "/cgi-bin/service/get_permanent_code";
- String GET_SUITE_TOKEN = "/cgi-bin/service/get_suite_token";
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
index 4289ae94c7..4561ecb35c 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
@@ -17,18 +17,6 @@
* @author Binary Wang
*/
public interface WxCpUserService {
- String URL_AUTHENTICATE = "/cgi-bin/user/authsucc?userid=";
- String URL_USER_CREATE = "/cgi-bin/user/create";
- String URL_USER_UPDATE = "/cgi-bin/user/update";
- String URL_USER_DELETE = "/cgi-bin/user/delete?userid=";
- String URL_USER_BATCH_DELETE = "/cgi-bin/user/batchdelete";
- String URL_USER_GET = "/cgi-bin/user/get?userid=";
- String URL_USER_LIST = "/cgi-bin/user/list?department_id=";
- String URL_USER_SIMPLE_LIST = "/cgi-bin/user/simplelist?department_id=";
- String URL_BATCH_INVITE = "/cgi-bin/batch/invite";
- String URL_CONVERT_TO_OPENID = "/cgi-bin/user/convert_to_openid";
- String URL_CONVERT_TO_USERID = "/cgi-bin/user/convert_to_userid";
- String URL_GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";
/**
*
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 e0bab1d90e..9db88b7c0e 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
@@ -5,6 +5,7 @@
import com.google.gson.JsonElement;
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.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
@@ -33,6 +34,7 @@
import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,12 +43,13 @@
import java.util.HashMap;
import java.util.Map;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.*;
+
/**
* @author chanjarster
*/
+@Slf4j
public abstract class BaseWxCpServiceImpl implements WxCpService, RequestHttp {
- protected final Logger log = LoggerFactory.getLogger(this.getClass());
-
private WxCpUserService userService = new WxCpUserServiceImpl(this);
private WxCpChatService chatService = new WxCpChatServiceImpl(this);
private WxCpDepartmentService departmentService = new WxCpDepartmentServiceImpl(this);
@@ -90,7 +93,7 @@ public boolean checkSignature(String msgSignature, String timestamp, String nonc
return SHA1.gen(this.configStorage.getToken(), timestamp, nonce, data)
.equals(msgSignature);
} catch (Exception e) {
- this.log.error("Checking signature failed, and the reason is :" + e.getMessage());
+ log.error("Checking signature failed, and the reason is :" + e.getMessage());
return false;
}
}
@@ -114,7 +117,7 @@ public String getAgentJsapiTicket(boolean forceRefresh) throws WxErrorException
if (this.configStorage.isAgentJsapiTicketExpired()) {
synchronized (this.globalAgentJsapiTicketRefreshLock) {
if (this.configStorage.isAgentJsapiTicketExpired()) {
- String responseContent = this.get(this.configStorage.getApiUrl(WxCpService.GET_AGENT_CONFIG_TICKET), null);
+ String responseContent = this.get(this.configStorage.getApiUrl(GET_AGENT_CONFIG_TICKET), null);
JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
this.configStorage.updateAgentJsapiTicket(jsonObject.get("ticket").getAsString(),
jsonObject.get("expires_in").getAsInt());
@@ -139,7 +142,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
if (this.configStorage.isJsapiTicketExpired()) {
synchronized (this.globalJsapiTicketRefreshLock) {
if (this.configStorage.isJsapiTicketExpired()) {
- String responseContent = this.get(this.configStorage.getApiUrl(WxCpService.GET_JSAPI_TICKET), null);
+ String responseContent = this.get(this.configStorage.getApiUrl(GET_JSAPI_TICKET), null);
JsonObject tmpJsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
this.configStorage.updateJsapiTicket(tmpJsonObject.get("ticket").getAsString(),
tmpJsonObject.get("expires_in").getAsInt());
@@ -180,7 +183,7 @@ public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorExce
message.setAgentId(this.getWxCpConfigStorage().getAgentId());
}
- return WxCpMessageSendResult.fromJson(this.post(this.configStorage.getApiUrl(WxCpService.MESSAGE_SEND), message.toJson()));
+ return WxCpMessageSendResult.fromJson(this.post(this.configStorage.getApiUrl(MESSAGE_SEND), message.toJson()));
}
@Override
@@ -189,13 +192,13 @@ public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorEx
params.put("js_code", jsCode);
params.put("grant_type", "authorization_code");
- String result = this.get(this.configStorage.getApiUrl(JSCODE_TO_SESSION_URL), Joiner.on("&").withKeyValueSeparator("=").join(params));
+ String result = this.get(this.configStorage.getApiUrl(JSCODE_TO_SESSION), Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxCpMaJsCode2SessionResult.fromJson(result);
}
@Override
public String[] getCallbackIp() throws WxErrorException {
- String responseContent = get(this.configStorage.getApiUrl(WxCpService.GET_CALLBACK_IP), null);
+ String responseContent = get(this.configStorage.getApiUrl(GET_CALLBACK_IP), null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
String[] ips = new String[jsonArray.size()];
@@ -226,7 +229,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro
return this.executeInternal(executor, uri, data);
} catch (WxErrorException e) {
if (retryTimes + 1 > this.maxRetryTimes) {
- this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
+ log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
//最后一次重试失败后,直接抛出异常,不再等待
throw new RuntimeException("微信服务端异常,超出重试次数");
}
@@ -238,7 +241,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro
if (error.getErrorCode() == -1) {
int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
try {
- this.log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
+ log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
Thread.sleep(sleepMillis);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
@@ -249,7 +252,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro
}
} while (retryTimes++ < this.maxRetryTimes);
- this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
+ log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
throw new RuntimeException("微信服务端异常,超出重试次数");
}
@@ -265,7 +268,7 @@ protected T executeInternal(RequestExecutor executor, String uri, E
try {
T result = executor.execute(uriWithAccessToken, data);
- this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
+ log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
return result;
} catch (WxErrorException e) {
WxError error = e.getError();
@@ -282,12 +285,12 @@ protected T executeInternal(RequestExecutor executor, String uri, E
}
if (error.getErrorCode() != 0) {
- this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
+ log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
throw new WxErrorException(error, e);
}
return null;
} catch (IOException e) {
- this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
+ log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
throw new RuntimeException(e);
}
}
@@ -339,19 +342,19 @@ public WxSessionManager getSessionManager() {
public String replaceParty(String mediaId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_id", mediaId);
- return post(this.configStorage.getApiUrl(WxCpService.BATCH_REPLACE_PARTY), jsonObject.toString());
+ return post(this.configStorage.getApiUrl(BATCH_REPLACE_PARTY), jsonObject.toString());
}
@Override
public String replaceUser(String mediaId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_id", mediaId);
- return post(this.configStorage.getApiUrl(WxCpService.BATCH_REPLACE_USER), jsonObject.toString());
+ return post(this.configStorage.getApiUrl(BATCH_REPLACE_USER), jsonObject.toString());
}
@Override
public String getTaskResult(String joinId) throws WxErrorException {
- String url = this.configStorage.getApiUrl(WxCpService.BATCH_GET_RESULT + joinId);
+ String url = this.configStorage.getApiUrl(BATCH_GET_RESULT + joinId);
return get(url, null);
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java
index f3714516cf..92c6ac2985 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java
@@ -1,17 +1,9 @@
package me.chanjar.weixin.cp.api.impl;
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.google.common.base.Joiner;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
+import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.error.WxError;
@@ -22,34 +14,37 @@
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
-import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpTpService;
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
import me.chanjar.weixin.cp.bean.WxCpTpCorp;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
/**
* @author zhenjun cai
*/
+@Slf4j
public abstract class BaseWxCpTpServiceImpl implements WxCpTpService, RequestHttp {
- protected final Logger log = LoggerFactory.getLogger(this.getClass());
/**
- * 全局的是否正在刷新access token的锁
+ * 全局的是否正在刷新access token的锁.
*/
protected final Object globalSuiteAccessTokenRefreshLock = new Object();
/**
- * 全局的是否正在刷新jsapi_ticket的锁
+ * 全局的是否正在刷新jsapi_ticket的锁.
*/
protected final Object globalSuiteTicketRefreshLock = new Object();
-
protected WxCpTpConfigStorage configStorage;
-
/**
- * 临时文件目录
+ * 临时文件目录.
*/
private File tmpDirFile;
private int retrySleepMillis = 1000;
@@ -61,7 +56,7 @@ public boolean checkSignature(String msgSignature, String timestamp, String nonc
return SHA1.gen(this.configStorage.getToken(), timestamp, nonce, data)
.equals(msgSignature);
} catch (Exception e) {
- this.log.error("Checking signature failed, and the reason is :" + e.getMessage());
+ log.error("Checking signature failed, and the reason is :" + e.getMessage());
return false;
}
}
@@ -83,11 +78,11 @@ public String getSuiteTicket(boolean forceRefresh) throws WxErrorException {
// this.configStorage.expireSuiteTicket();
// }
- if (this.configStorage.isSuiteTicketExpired()) {
-// 本地suite ticket 不存在或者过期
- WxError wxError = WxError.fromJson("{\"errcode\":40085, \"errmsg\":\"invaild suite ticket\"}", WxType.CP);
- throw new WxErrorException(wxError);
- }
+ if (this.configStorage.isSuiteTicketExpired()) {
+ // 本地suite ticket 不存在或者过期
+ WxError wxError = WxError.fromJson("{\"errcode\":40085, \"errmsg\":\"invaild suite ticket\"}", WxType.CP);
+ throw new WxErrorException(wxError);
+ }
return this.configStorage.getSuiteTicket();
}
@@ -98,28 +93,28 @@ public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorEx
params.put("js_code", jsCode);
params.put("grant_type", "authorization_code");
- String result = this.get(configStorage.getApiUrl(JSCODE_TO_SESSION_URL), Joiner.on("&").withKeyValueSeparator("=").join(params));
+ String result = this.get(configStorage.getApiUrl(WxCpApiPathConsts.Tp.JSCODE_TO_SESSION), Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxCpMaJsCode2SessionResult.fromJson(result);
}
@Override
public WxAccessToken getCorpToken(String authCorpid, String permanentCode) throws WxErrorException {
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("auth_corpid", authCorpid);
- jsonObject.addProperty("permanent_code", permanentCode);
- String result = post(configStorage.getApiUrl(GET_CORP_TOKEN), jsonObject.toString());
-
- return WxAccessToken.fromJson(result);
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("auth_corpid", authCorpid);
+ jsonObject.addProperty("permanent_code", permanentCode);
+ String result = post(configStorage.getApiUrl(WxCpApiPathConsts.Tp.GET_CORP_TOKEN), jsonObject.toString());
+
+ return WxAccessToken.fromJson(result);
}
-
+
@Override
public WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("auth_code", authCode);
- String result = post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
+ String result = post(configStorage.getApiUrl(WxCpApiPathConsts.Tp.GET_PERMANENT_CODE), jsonObject.toString());
jsonObject = new JsonParser().parse(result).getAsJsonObject();
WxCpTpCorp wxCpTpCorp = WxCpTpCorp.fromJson(jsonObject.get("auth_corp_info").getAsString());
wxCpTpCorp.setPermanentCode(jsonObject.get("permanent_code").getAsString());
@@ -147,7 +142,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro
return this.executeInternal(executor, uri, data);
} catch (WxErrorException e) {
if (retryTimes + 1 > this.maxRetryTimes) {
- this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
+ log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
//最后一次重试失败后,直接抛出异常,不再等待
throw new RuntimeException("微信服务端异常,超出重试次数");
}
@@ -159,7 +154,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro
if (error.getErrorCode() == -1) {
int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
try {
- this.log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
+ log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
Thread.sleep(sleepMillis);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
@@ -170,7 +165,7 @@ public T execute(RequestExecutor executor, String uri, E data) thro
}
} while (retryTimes++ < this.maxRetryTimes);
- this.log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
+ log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
throw new RuntimeException("微信服务端异常,超出重试次数");
}
@@ -186,7 +181,7 @@ protected T executeInternal(RequestExecutor executor, String uri, E
try {
T result = executor.execute(uriWithAccessToken, data);
- this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
+ log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
return result;
} catch (WxErrorException e) {
WxError error = e.getError();
@@ -201,12 +196,12 @@ protected T executeInternal(RequestExecutor executor, String uri, E
}
if (error.getErrorCode() != 0) {
- this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
+ log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
throw new WxErrorException(error, e);
}
return null;
} catch (IOException e) {
- this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
+ log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
throw new RuntimeException(e);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
index 2dc5ca8755..6a9b774691 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
@@ -3,6 +3,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
+import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpAgentService;
@@ -12,6 +13,8 @@
import java.util.List;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Agent.*;
+
/**
*
@@ -21,14 +24,11 @@
*
* @author huansinho
*/
+@RequiredArgsConstructor
public class WxCpAgentServiceImpl implements WxCpAgentService {
private static final JsonParser JSON_PARSER = new JsonParser();
- private WxCpService mainService;
-
- public WxCpAgentServiceImpl(WxCpService mainService) {
- this.mainService = mainService;
- }
+ private final WxCpService mainService;
@Override
public WxCpAgent get(Integer agentId) throws WxErrorException {
@@ -36,13 +36,13 @@ public WxCpAgent get(Integer agentId) throws WxErrorException {
throw new IllegalArgumentException("缺少agentid参数");
}
- String responseContent = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpAgentService.GET_AGENT), agentId), null);
+ String responseContent = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET), agentId), null);
return WxCpAgent.fromJson(responseContent);
}
@Override
public void set(WxCpAgent agentInfo) throws WxErrorException {
- String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpAgentService.AGENT_SET);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_SET);
String responseContent = this.mainService.post(url, agentInfo.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
@@ -52,7 +52,7 @@ public void set(WxCpAgent agentInfo) throws WxErrorException {
@Override
public List list() throws WxErrorException {
- String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpAgentService.AGENT_LIST);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_LIST);
String responseContent = this.mainService.get(url, null);
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() != 0) {
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
index 1bf809502b..bd5baf01dd 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
@@ -1,12 +1,14 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonParser;
+import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.cp.api.WxCpChatService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpAppChatMessage;
import me.chanjar.weixin.cp.bean.WxCpChat;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.StringUtils;
@@ -14,24 +16,18 @@
import java.util.List;
import java.util.Map;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Chat.*;
+
/**
* 群聊服务实现.
*
* @author gaigeshen
*/
+@RequiredArgsConstructor
public class WxCpChatServiceImpl implements WxCpChatService {
private static final JsonParser JSON_PARSER = new JsonParser();
private final WxCpService cpService;
- /**
- * 创建群聊服务实现的实例.
- *
- * @param cpService 企业微信的服务
- */
- WxCpChatServiceImpl(WxCpService cpService) {
- this.cpService = cpService;
- }
-
@Override
public String chatCreate(String name, String owner, List users, String chatId) throws WxErrorException {
Map data = new HashMap<>(4);
@@ -98,7 +94,7 @@ public WxCpChat get(String chatId) throws WxErrorException {
@Override
public void sendMsg(WxCpAppChatMessage message) throws WxErrorException {
- this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(WxCpChatService.APPCHAT_SEND), message.toJson());
+ this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_SEND), message.toJson());
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
index ce6f02ae5f..fb2224e335 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
@@ -3,15 +3,19 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
+import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.List;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Department.*;
+
/**
*
* 部门管理接口
@@ -20,16 +24,13 @@
*
* @author Binary Wang
*/
+@RequiredArgsConstructor
public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
- private WxCpService mainService;
-
- public WxCpDepartmentServiceImpl(WxCpService mainService) {
- this.mainService = mainService;
- }
+ private final WxCpService mainService;
@Override
public Long create(WxCpDepart depart) throws WxErrorException {
- String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_CREATE);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_CREATE);
String responseContent = this.mainService.post(url, depart.toJson());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("id"));
@@ -37,19 +38,19 @@ public Long create(WxCpDepart depart) throws WxErrorException {
@Override
public void update(WxCpDepart group) throws WxErrorException {
- String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_UPDATE);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE);
this.mainService.post(url, group.toJson());
}
@Override
public void delete(Long departId) throws WxErrorException {
- String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_DELETE), departId);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_DELETE), departId);
this.mainService.get(url, null);
}
@Override
public List list(Long id) throws WxErrorException {
- String url = this.mainService.getWxCpConfigStorage().getApiUrl(WxCpDepartmentService.DEPARTMENT_LIST);
+ String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_LIST);
if (id != null) {
url += "?id=" + id;
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java
index fa31a033ba..05e13cfc8a 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java
@@ -1,19 +1,22 @@
package me.chanjar.weixin.cp.api.impl;
+import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
-import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Media.*;
+
/**
*
* 媒体管理接口.
@@ -22,12 +25,9 @@
*
* @author Binary Wang
*/
+@RequiredArgsConstructor
public class WxCpMediaServiceImpl implements WxCpMediaService {
- private WxCpService mainService;
-
- public WxCpMediaServiceImpl(WxCpService mainService) {
- this.mainService = mainService;
- }
+ private final WxCpService mainService;
@Override
public WxMediaUploadResult upload(String mediaType, String fileType, InputStream inputStream)
@@ -38,7 +38,7 @@ public WxMediaUploadResult upload(String mediaType, String fileType, InputStream
@Override
public WxMediaUploadResult upload(String mediaType, File file) throws WxErrorException {
return this.mainService.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()),
- this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_UPLOAD_URL + mediaType), file);
+ this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_UPLOAD + mediaType), file);
}
@Override
@@ -46,7 +46,7 @@ public File download(String mediaId) throws WxErrorException {
return this.mainService.execute(
BaseMediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(),
this.mainService.getWxCpConfigStorage().getTmpDirFile()),
- this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_GET_URL), "media_id=" + mediaId);
+ this.mainService.getWxCpConfigStorage().getApiUrl(MEDIA_GET), "media_id=" + mediaId);
}
@Override
@@ -54,13 +54,13 @@ public File getJssdkFile(String mediaId) throws WxErrorException {
return this.mainService.execute(
BaseMediaDownloadRequestExecutor.create(this.mainService.getRequestHttp(),
this.mainService.getWxCpConfigStorage().getTmpDirFile()),
- this.mainService.getWxCpConfigStorage().getApiUrl(JSSDK_MEDIA_GET_URL), "media_id=" + mediaId);
+ this.mainService.getWxCpConfigStorage().getApiUrl(JSSDK_MEDIA_GET), "media_id=" + mediaId);
}
@Override
public String uploadImg(File file) throws WxErrorException {
final WxMediaUploadResult result = this.mainService
- .execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD_URL), file);
+ .execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD), file);
return result.getUrl();
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
index a03d600145..85abe71f45 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMenuServiceImpl.java
@@ -1,12 +1,15 @@
package me.chanjar.weixin.cp.api.impl;
+import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.WxCpConsts;
import me.chanjar.weixin.cp.api.WxCpMenuService;
import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Menu.*;
+
/**
*
* 菜单管理相关接口.
@@ -15,12 +18,9 @@
*
* @author Binary Wang
*/
+@RequiredArgsConstructor
public class WxCpMenuServiceImpl implements WxCpMenuService {
- private WxCpService mainService;
-
- public WxCpMenuServiceImpl(WxCpService mainService) {
- this.mainService = mainService;
- }
+ private final WxCpService mainService;
@Override
public void create(WxMenu menu) throws WxErrorException {
@@ -29,7 +29,7 @@ public void create(WxMenu menu) throws WxErrorException {
@Override
public void create(Integer agentId, WxMenu menu) throws WxErrorException {
- String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpMenuService.MENU_CREATE), agentId);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(MENU_CREATE), agentId);
this.mainService.post(url, menu.toJson());
}
@@ -40,7 +40,7 @@ public void delete() throws WxErrorException {
@Override
public void delete(Integer agentId) throws WxErrorException {
- String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpMenuService.MENU_DELETE), agentId);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(MENU_DELETE), agentId);
this.mainService.get(url, null);
}
@@ -51,7 +51,7 @@ public WxMenu get() throws WxErrorException {
@Override
public WxMenu get(Integer agentId) throws WxErrorException {
- String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpMenuService.MENU_GET), agentId);
+ String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(MENU_GET), agentId);
try {
String resultContent = this.mainService.get(url, null);
return WxCpGsonBuilder.create().fromJson(resultContent, WxMenu.class);
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
index aedc9ab24d..2005bc36eb 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOAuth2ServiceImpl.java
@@ -4,6 +4,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
+import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.URIUtil;
@@ -12,10 +13,13 @@
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
import me.chanjar.weixin.cp.bean.WxCpUserDetail;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.*;
import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.SNSAPI_PRIVATEINFO;
import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.SNSAPI_USERINFO;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.OAuth2.*;
/**
*
@@ -25,7 +29,7 @@
*
* @author Binary Wang
*/
-@AllArgsConstructor
+@RequiredArgsConstructor
public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service {
private final WxCpService mainService;
@@ -39,12 +43,12 @@ public String buildAuthorizationUrl(String state) {
@Override
public String buildAuthorizationUrl(String redirectUri, String state) {
- return this.buildAuthorizationUrl(redirectUri, state, WxConsts.OAuth2Scope.SNSAPI_BASE);
+ return this.buildAuthorizationUrl(redirectUri, state, SNSAPI_BASE);
}
@Override
public String buildAuthorizationUrl(String redirectUri, String state, String scope) {
- StringBuilder url = new StringBuilder(WxCpOAuth2Service.URL_OAUTH_2_AUTHORIZE);
+ StringBuilder url = new StringBuilder(URL_OAUTH2_AUTHORIZE);
url.append("?appid=").append(this.mainService.getWxCpConfigStorage().getCorpId());
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectUri));
url.append("&response_type=code");
@@ -69,7 +73,7 @@ public WxCpOauth2UserInfo getUserInfo(String code) throws WxErrorException {
@Override
public WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErrorException {
- String responseText = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOAuth2Service.URL_GET_USER_INFO), code, agentId), null);
+ String responseText = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(GET_USER_INFO), code, agentId), null);
JsonElement je = new JsonParser().parse(responseText);
JsonObject jo = je.getAsJsonObject();
@@ -86,7 +90,7 @@ public WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErr
public WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("user_ticket", userTicket);
- String responseText = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOAuth2Service.URL_GET_USER_DETAIL), param.toString());
+ String responseText = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_USER_DETAIL), param.toString());
return WxCpGsonBuilder.create().fromJson(responseText, WxCpUserDetail.class);
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
index c0f6ddaab6..5d7d758c08 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java
@@ -5,6 +5,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
+import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpOaService;
import me.chanjar.weixin.cp.api.WxCpService;
@@ -12,25 +13,25 @@
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
import me.chanjar.weixin.cp.bean.WxCpDialRecord;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.Date;
import java.util.List;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
+
/**
* @author Element
* @date 2019-04-06 11:20
*/
+@RequiredArgsConstructor
public class WxCpOaServiceImpl implements WxCpOaService {
- private WxCpService mainService;
-
- public WxCpOaServiceImpl(WxCpService mainService) {
- this.mainService = mainService;
- }
+ private final WxCpService mainService;
@Override
- public List getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime, List userIdList) throws WxErrorException {
-
+ public List getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime,
+ List userIdList) throws WxErrorException {
if (startTime == null || endTime == null) {
throw new RuntimeException("starttime and endtime can't be null");
}
@@ -59,7 +60,7 @@ public List getCheckinData(Integer openCheckinDataType, Date st
jsonObject.add("useridlist", jsonArray);
- String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_CHECKIN_DATA), jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_DATA), jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
@@ -88,7 +89,7 @@ public List getCheckinOption(Date datetime, List user
jsonObject.addProperty("datetime", datetime.getTime() / 1000L);
jsonObject.add("useridlist", jsonArray);
- String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_CHECKIN_OPTION), jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_OPTION), jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
@@ -108,7 +109,7 @@ public WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long
jsonObject.addProperty("next_spnum", nextSpnum);
}
- String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_APPROVAL_DATA), jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DATA), jsonObject.toString());
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class);
}
@@ -140,7 +141,7 @@ public List getDialRecord(Date startTime, Date endTime, Integer
jsonObject.addProperty("end_time", endtimestamp);
}
- String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(WxCpOaService.GET_DIAL_RECORD), jsonObject.toString());
+ String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_DIAL_RECORD), jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create()
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
index 6dea258b99..d181af6749 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java
@@ -8,8 +8,8 @@
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
-import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -23,8 +23,8 @@
* @author someone
*/
public class WxCpServiceApacheHttpClientImpl extends BaseWxCpServiceImpl {
- protected CloseableHttpClient httpClient;
- protected HttpHost httpProxy;
+ private CloseableHttpClient httpClient;
+ private HttpHost httpProxy;
@Override
public CloseableHttpClient getRequestHttpClient() {
@@ -48,7 +48,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
synchronized (this.globalAccessTokenRefreshLock) {
- String url = String.format(this.configStorage.getApiUrl(WxCpService.GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret());
+ String url = String.format(this.configStorage.getApiUrl(WxCpApiPathConsts.GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret());
try {
HttpGet httpGet = new HttpGet(url);
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
index f1c5c8419a..cc76e9cf4c 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java
@@ -10,16 +10,15 @@
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType;
-import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
/**
* @author someone
*/
public class WxCpServiceJoddHttpImpl extends BaseWxCpServiceImpl {
- protected HttpConnectionProvider httpClient;
- protected ProxyInfo httpProxy;
-
+ private HttpConnectionProvider httpClient;
+ private ProxyInfo httpProxy;
@Override
public HttpConnectionProvider getRequestHttpClient() {
@@ -43,7 +42,8 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
}
synchronized (this.globalAccessTokenRefreshLock) {
- HttpRequest request = HttpRequest.get(String.format(this.configStorage.getApiUrl(WxCpService.GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret()));
+ HttpRequest request = HttpRequest.get(String.format(this.configStorage.getApiUrl(WxCpApiPathConsts.GET_TOKEN),
+ this.configStorage.getCorpId(), this.configStorage.getCorpSecret()));
if (this.httpProxy != null) {
httpClient.useProxy(this.httpProxy);
}
@@ -64,7 +64,8 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
@Override
public void initHttp() {
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
- httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword());
+ httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(),
+ configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword());
}
httpClient = JoddHttp.httpConnectionProvider;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
index 4280174dc4..596dc0608e 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java
@@ -1,25 +1,23 @@
package me.chanjar.weixin.cp.api.impl;
+import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
-import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
-import okhttp3.Authenticator;
-import okhttp3.Credentials;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-import okhttp3.Route;
+import okhttp3.*;
import java.io.IOException;
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.GET_TOKEN;
+
/**
* @author someone
*/
+@Slf4j
public class WxCpServiceOkHttpImpl extends BaseWxCpServiceImpl {
private OkHttpClient httpClient;
private OkHttpProxyInfo httpProxy;
@@ -50,7 +48,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
OkHttpClient client = getRequestHttpClient();
//请求的request
Request request = new Request.Builder()
- .url(String.format(this.configStorage.getApiUrl(WxCpService.GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret()))
+ .url(String.format(this.configStorage.getApiUrl(GET_TOKEN), this.configStorage.getCorpId(), this.configStorage.getCorpSecret()))
.get()
.build();
String resultContent = null;
@@ -58,7 +56,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
Response response = client.newCall(request).execute();
resultContent = response.body().string();
} catch (IOException e) {
- this.log.error(e.getMessage(), e);
+ log.error(e.getMessage(), e);
}
WxError error = WxError.fromJson(resultContent, WxType.CP);
@@ -74,7 +72,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
@Override
public void initHttp() {
- this.log.debug("WxCpServiceOkHttpImpl initHttp");
+ log.debug("WxCpServiceOkHttpImpl initHttp");
//设置代理
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
httpProxy = OkHttpProxyInfo.httpProxy(configStorage.getHttpProxyHost(),
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java
index 1b7a67c6ea..35eab626a7 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOnTpImpl.java
@@ -1,37 +1,33 @@
-package me.chanjar.weixin.cp.api.impl;
-
-import me.chanjar.weixin.common.bean.WxAccessToken;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.api.WxCpTpService;
-
-/**
- *