From f67333a06ad464fb27c162b328d58ca5e037ea3a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 2 Jun 2019 12:19:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83=E5=8C=96=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=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 feea8acbd..30214a478 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 @@ import java.util.List; * @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 95f747e35..bbfc0fdd4 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 8af1d3041..3f80d693a 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 @@ import me.chanjar.weixin.cp.bean.WxCpDepart;
  * @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 068c037a4..be7b4b7e5 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 @@ import me.chanjar.weixin.common.error.WxErrorException;
  * @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 e8cf874eb..000000000
--- 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 000000000..26922c0ee --- /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 364723db8..13d2e9dc4 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.bean.WxCpMessageSendResult; 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 9624f9e40..a570a80b1 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 @@ import java.util.List;
  * @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 038c2dd3b..1e1077014 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 @@ import java.util.List;
  * @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 741d27de5..6e0d63fb2 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 310a1efa5..091c68759 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 @@ import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo; * @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 3eb99b79d..d9c88b47a 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 abstract class BaseWxCpServiceImpl implements WxCpService, RequestH
   }
 
   @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 3a977b81d..10c417729 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 class WxCpAgentServiceImpl implements WxCpAgentService {
       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 class WxCpAgentServiceImpl implements WxCpAgentService {
 
   @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 05d298c9a..0b1fb5938 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 class WxCpChatServiceImpl implements WxCpChatService {
 
   @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 481115fa5..09ded1b8b 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 class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
 
   @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 f58eff476..d33ade019 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 @@ import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
 
 /**
  * 
- * 菜单管理相关接口
+ * 菜单管理相关接口.
  * 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 class WxCpMenuServiceImpl implements WxCpMenuService { @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 class WxCpMenuServiceImpl implements WxCpMenuService { @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 class WxCpMenuServiceImpl implements WxCpMenuService { @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 2d1ca6ab0..cc3b27449 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.JsonObject; 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 @@ import java.util.List; /** * @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 class WxCpOAServiceImpl implements WxCpOAService { 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 class WxCpOAServiceImpl implements WxCpOAService { 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 class WxCpOAServiceImpl implements WxCpOAService { @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 class WxCpOAServiceImpl implements WxCpOAService { 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 class WxCpOAServiceImpl implements WxCpOAService { } @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 class WxCpOAServiceImpl implements WxCpOAService { 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 class WxCpOAServiceImpl implements WxCpOAService { 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 86e237168..11a183b50 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.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.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 org.apache.http.impl.client.CloseableHttpClient; import java.io.IOException; +/** + * @author someone + */ public class WxCpServiceApacheHttpClientImpl extends BaseWxCpServiceImpl { protected CloseableHttpClient httpClient; protected HttpHost httpProxy; @@ -45,9 +48,7 @@ public class WxCpServiceApacheHttpClientImpl extends BaseWxCpServiceImplBinary Wang *
+ * + * @author Binary Wang */ public class WxCpTagServiceImpl implements WxCpTagService { private WxCpService mainService; @@ -33,33 +30,29 @@ public class WxCpTagServiceImpl implements WxCpTagService { @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 class WxCpTagServiceImpl implements WxCpTagService { @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 class WxCpTagServiceImpl implements WxCpTagService { @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 @@ public class WxCpTagServiceImpl implements WxCpTagService { @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 3011320d5..e70a7d376 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 class WxCpTaskCardServiceImpl implements WxCpTaskCardService { 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 0b8a134d4..f673a622b 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 84a16f349..b3b090952 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 @@ import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; * @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 class WxCpUserServiceImpl implements WxCpUserService { @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 class WxCpUserServiceImpl implements WxCpUserService { 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 class WxCpUserServiceImpl implements WxCpUserService { @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 class WxCpUserServiceImpl implements WxCpUserService { 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 class WxCpUserServiceImpl implements WxCpUserService { @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 class WxCpUserServiceImpl implements WxCpUserService { 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 class WxCpUserServiceImpl implements WxCpUserService { @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 28cc4807a..244419b06 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 4ce497243..a2dc46e82 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.ApiTestModule; 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 class WxCpAgentServiceImplTest { @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 9497a5626..4810cd81d 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 @@ import static org.assertj.core.api.Assertions.assertThat; * @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 5a6e8ccab..c4c8b3ccb 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 @@ import static org.testng.Assert.assertNotEquals; /** *
- *
  * 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 class WxCpTagServiceImplTest { 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 class WxCpTagServiceImplTest { 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 b39e76fdb..73793a23f 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 @@ package com.github.binarywang.wxpay.bean.request; 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 @@ import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.ALL_S * @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 78bb789d2..bf29a55b3 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.constant.WxPayConstants.TradeType; 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 @@ import org.apache.commons.lang3.StringUtils; @NoArgsConstructor @AllArgsConstructor @XStreamAlias("xml") +@Accessors(chain = true) public class WxPayUnifiedOrderRequest extends BaseWxPayRequest { private static final long serialVersionUID = 4611350167813931828L;