项目作者: imhuzi

项目描述 :
企业微信 JAVA SDK
高级语言: Java
项目地址: git://github.com/imhuzi/qiye-wechat.git
创建时间: 2021-03-18T08:08:24Z
项目社区:https://github.com/imhuzi/qiye-wechat

开源协议:

下载


介绍

争取 做最好用的 企业微信 SDK, 帮助开发者 以最方便 最省时间的方式接入企业微信。qiye-wechat-sdk 基于 Figen 封装, 覆盖 企业微信 所有API

Quick Start

Spring Boot 项目

Spring Boot 项目 使用步骤如下:

  1. 引入maven依赖
    1. <dependency>
    2. <groupId>chat.qiye.wechat</groupId>
    3. <artifactId>qiye-wechat-spring-boot-starter</artifactId>
    4. <version>1.0.0-SNAPSHOT</version>
    5. </dependency>
  2. 在 application.yaml 中加入 如下配置
    ```yaml
    qiye:
    wechat:
    corp-id: ww5f09c98e13dfce02
    apps:
    • app-id: 1000015
      agent-id: 1000015
      app-type: app
      secret: VYa3q7u-XkhQno-ROferY3mD16eFy_-h62pHJ0qM58I
    • app-id: contact
      agent-id: 88
      app-type: contact
      secret: okDLF2MXt3QRGfAQ2cENzNUxfLd3c-_vn60etURj0SY
  1. 3. 使用 相关 Api Bean
  2. ```java
  3. @RestController
  4. public class DeptController {
  5. @Resource
  6. ContactDeptApi contactDeptApi;
  7. @GetMapping("/list")
  8. public ContactDeptListResp list(@RequestParam(defaultValue = "0") Integer id) {
  9. return contactDeptApi.list(id);
  10. }
  11. }

普通java项目 配置

普通 的Java 项目使用步骤如下:

  1. 引入maven依赖

    1. <dependency>
    2. <groupId>chat.qiye.wechat</groupId>
    3. <artifactId>qiye-wechat-sdk</artifactId>
    4. <version>1.0.0-SNAPSHOT</version>
    5. </dependency>
    6. <dependency>
    7. <groupId>org.apache.logging.log4j</groupId>
    8. <artifactId>log4j-core</artifactId>
    9. <optional>true</optional>
    10. </dependency>
    11. <dependency>
    12. <groupId>org.apache.logging.log4j</groupId>
    13. <artifactId>log4j-1.2-api</artifactId>
    14. <optional>true</optional>
    15. </dependency>
    16. <dependency>
    17. <groupId>org.apache.logging.log4j</groupId>
    18. <artifactId>log4j-slf4j-impl</artifactId>
    19. <optional>true</optional>
    20. </dependency>
    21. <dependency>
    22. <groupId>commons-logging</groupId>
    23. <artifactId>commons-logging</artifactId>
    24. </dependency>
  2. 在 resources 目录下 放一个 qiye-wechat.properties 配置文件
    ```properties

    应用配置

    qiye.wecaht.appId=1000015
    qiye.wecaht.agentId=1000015
    qiye.wecaht.secret=VYa3q7u-XkhQno-ROferY3mD16eFy_-h62pHJ0qM58I
    qiye.wecaht.corpId=ww5f09c98e13dfce02
    qiye.wecaht.homeUrl=http://baidu.com
    qiye.wecaht.eventToken=ss
    qiye.wecaht.eventEncodingAesKey=sddd

系统 应用配置格式, 系统应用ID参考 chat.qiye.wechat.sdk.constant.AppTypeEnum

qiye.wecaht.系统应用ID.appId=contact

qiye.wecaht.系统应用ID.agentId=88

qiye.wecaht.系统应用ID.secret=okDLF2M1tkQRGfAQ2cENzNUxfLd3c-_vn60etURj0SY

qiye.wecaht.系统应用ID.corpId=ww5f09c98e13dfce02 # 可选,未配置使用 qiye.wecaht.corpId

qiye.wecaht.系统应用ID.homeUrl=http://baidu.com

qiye.wecaht.系统应用ID.eventToken=ss

qiye.wecaht.系统应用ID.eventEncodingAesKey=sddd

系统-通讯录应用

qiye.wecaht.contact.appId=contact
qiye.wecaht.contact.agentId=88
qiye.wecaht.contact.secret=okDLF2MXt3QRGfAQ2cENzNUxfLd3c-_vn60etURj0SY
qiye.wecaht.contact.corpId=ww5f09c98e13dfce02
qiye.wecaht.contact.homeUrl=http://baidu.com
qiye.wecaht.contact.eventToken=ss
qiye.wecaht.contact.eventEncodingAesKey=sddd

  1. 3. API调用
  2. ```java
  3. public class MainClass {
  4. public static void main(String[] args) {
  5. // 获取Api实例, 所有封装的Api 都在 chat.qiye.wechat.sdk.api 包下,并以Api结尾
  6. ContactDeptApi contactDeptApi = ApiFactory.getApiBean(ContactDeptApi.class, new ApiConfigurationDefaultProvider());
  7. // 查询 通讯录 部门列表
  8. List<ContactDeptVo> deptVoList = contactDeptApi.list(0).getDepartment();
  9. System.out.println("DeptList:" + deptVoList);
  10. // 创建部门
  11. ContactDeptVo contactDeptVo = new ContactDeptVo();
  12. contactDeptVo.setId(2);
  13. contactDeptVo.setName("测试部");
  14. contactDeptVo.setNameEn("test");
  15. contactDeptVo.setParentid(1);
  16. ContactDeptCreateResp resp = contactDeptApi.create(contactDeptVo);
  17. if (resp.success()) {
  18. RespStatus ret = contactDeptApi.delete(resp.getId());
  19. System.out.println("delete result:" + ret);
  20. }
  21. }
  22. }

进阶配置

多个企业微信内部应用

多个企业微信服务商应用

系统应用ID

系统应用 默认是 没有应用ID 但是 系统应用有单独的 secret,为了能够识别 系统应用的 secret 特此 对系统应用的id 进行统一定义,在配置文件中 配置时,需遵守如下名称

  1. DEFAULT("app", "自建应用"),
  2. APP_CONTACT("contact", "通讯录"),
  3. APP_CUSTOMER("customer", "客户关系"),
  4. APP_CUSTOMER_SERVICE("customer_service", "微信客服"),
  5. APP_MEETING("meeting", "会议"),
  6. APP_SCHEDULE("schedule", "日程"),
  7. APP_PUBLIC_PHONE("public_phone", "公费电话"),
  8. APP_WX_DRIVE("wx_drive", "微盘"),
  9. APP_LIVING("living", "直播"),
  10. APP_CHECK_IN("check_in", "打卡"),
  11. APP_APPROVAL("approval", "审批"),
  12. APP_REPORT("report", "汇报"),
  13. APP_MEETING_ROOM("meeting_room", "会议室"),
  14. APP_PSTNCC("pstncc", "紧急通知"),
  15. APP_SCHOOL_CONTACT("school_contact", "家校通讯录");