tjx
2025-11-26 3ba118feb585368de68b0a1cf583e192c313a8a6
新增企业微信的接口
已修改2个文件
36 ■■■■■ 文件已修改
src/main/java/com/gs/xky/config/DataAcquisitionConfiguration.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gs/xky/service/WorkWXService.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gs/xky/config/DataAcquisitionConfiguration.java
@@ -45,4 +45,6 @@
    public static final String CORPID = "wwabe21b935901a7d8";
    public static final String CORPSECRET = "Z-7fNbZjrd80ypz69U14j8FMxI_fpUxcT6PksxlvKaY";
    public static final String TXL_CORPSECRET = "T64bdcV7fo0hvW10W3NJYmGUmlBYxYMfiW6EiUJ9VPM";
}
src/main/java/com/gs/xky/service/WorkWXService.java
@@ -61,8 +61,38 @@
        }
    }
    public String getContactAccessToken() throws IOException {
        String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s",
                DataAcquisitionConfiguration.CORPID,
                DataAcquisitionConfiguration.TXL_CORPSECRET);
        Request request = new Request.Builder()
                .url(url)
                .get()
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                log.error("获取企业微信通讯录access_token失败,HTTP状态码: {}", response.code());
                throw new IOException("获取通讯录access_token失败: " + response.message());
            }
            String responseBody = response.body().string();
            WorkWXTokenResponse tokenResponse = objectMapper.readValue(responseBody, WorkWXTokenResponse.class);
            if (tokenResponse.getErrcode() != 0) {
                log.error("获取企业微信通讯录access_token失败,错误码: {}, 错误信息: {}",
                        tokenResponse.getErrcode(), tokenResponse.getErrmsg());
                throw new IOException("获取通讯录access_token失败: " + tokenResponse.getErrmsg());
            }
            log.info("成功获取企业微信通讯录access_token,有效期: {}秒", tokenResponse.getExpiresIn());
            return tokenResponse.getAccessToken();
        }
    }
    public String getUserIdByMobile(String mobile) throws IOException {
        String accessToken = getAccessToken();
        String accessToken = getContactAccessToken();
        String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/user/getuserid?access_token=%s", accessToken);
        Map<String, Object> requestBody = new HashMap<>();
@@ -101,7 +131,7 @@
    }
    public List<WorkWXUser> getUserList() throws IOException {
        String accessToken = getAccessToken();
        String accessToken = getContactAccessToken();
        String url = String.format(
                "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=%s&department_id=1&fetch_child=1",
                accessToken);