-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🆕 #2612 【企业微信】增加获取企业活跃成员数和通讯录异步导出的接口
- Loading branch information
1 parent
5d0364f
commit 1030115
Showing
10 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExportService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package me.chanjar.weixin.cp.api; | ||
|
||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.cp.bean.export.WxCpExportRequest; | ||
import me.chanjar.weixin.cp.bean.export.WxCpExportResult; | ||
|
||
/** | ||
* 异步导出接口 | ||
* | ||
* @author <a href="https://github.com/zhongjun96">zhongjun</a> | ||
* @date 2022/4/21 | ||
**/ | ||
public interface WxCpExportService { | ||
|
||
/** | ||
* <pre> | ||
* | ||
* 导出成员 | ||
* | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/export/simple_user?access_token=ACCESS_TOKEN">https://qyapi.weixin.qq.com/cgi-bin/export/simple_user?access_token=ACCESS_TOKEN</a> | ||
* | ||
* 文档地址:<a href="https://developer.work.weixin.qq.com/document/path/94849">https://developer.work.weixin.qq.com/document/path/94849</a> | ||
* </pre> | ||
* | ||
* @param params 导出参数 | ||
* @return jobId 异步任务id | ||
* @throws WxErrorException . | ||
*/ | ||
String simpleUser(WxCpExportRequest params) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* | ||
* 导出成员详情 | ||
* | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/export/user?access_token=ACCESS_TOKEN">https://qyapi.weixin.qq.com/cgi-bin/export/user?access_token=ACCESS_TOKEN</a> | ||
* | ||
* 文档地址:<a href="https://developer.work.weixin.qq.com/document/path/94851">https://developer.work.weixin.qq.com/document/path/94851</a> | ||
* </pre> | ||
* | ||
* @param params 导出参数 | ||
* @return jobId 异步任务id | ||
* @throws WxErrorException . | ||
*/ | ||
String user(WxCpExportRequest params) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* | ||
* 导出部门 | ||
* | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/export/department?access_token=ACCESS_TOKEN">https://qyapi.weixin.qq.com/cgi-bin/export/department?access_token=ACCESS_TOKEN</a> | ||
* | ||
* 文档地址:<a href="https://developer.work.weixin.qq.com/document/path/94852">https://developer.work.weixin.qq.com/document/path/94852</a> | ||
* </pre> | ||
* | ||
* @param params 导出参数 | ||
* @return jobId 异步任务id | ||
* @throws WxErrorException . | ||
*/ | ||
String department(WxCpExportRequest params) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* | ||
* 导出标签成员 | ||
* | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/export/taguser?access_token=ACCESS_TOKEN">https://qyapi.weixin.qq.com/cgi-bin/export/taguser?access_token=ACCESS_TOKEN</a> | ||
* | ||
* 文档地址:<a href="https://developer.work.weixin.qq.com/document/path/94853">https://developer.work.weixin.qq.com/document/path/94853</a> | ||
* </pre> | ||
* | ||
* @param params 导出参数 | ||
* @return jobId 异步任务id | ||
* @throws WxErrorException . | ||
*/ | ||
String tagUser(WxCpExportRequest params) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* | ||
* 获取导出结果 | ||
* | ||
* 请求方式:GET(HTTPS) | ||
* 请求地址:<a href="https://qyapi.weixin.qq.com/cgi-bin/export/get_result?access_token=ACCESS_TOKEN&jobid=jobid_xxxxxxxxxxxxxxx">https://qyapi.weixin.qq.com/cgi-bin/export/get_result?access_token=ACCESS_TOKEN&jobid=jobid_xxxxxxxxxxxxxxx</a> | ||
* | ||
* 文档地址:<a href="https://developer.work.weixin.qq.com/document/path/94854">https://developer.work.weixin.qq.com/document/path/94854</a> | ||
* 返回的url文件下载解密可参考 <a href="https://blog.csdn.net/a201692/article/details/123530529">CSDN</a> | ||
* </pre> | ||
* | ||
* @param jobId 异步任务id | ||
* @return 导出结果 | ||
* @throws WxErrorException . | ||
*/ | ||
WxCpExportResult getResult(String jobId) throws WxErrorException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExportServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package me.chanjar.weixin.cp.api.impl; | ||
|
||
import com.google.gson.JsonObject; | ||
import lombok.RequiredArgsConstructor; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.common.util.json.GsonParser; | ||
import me.chanjar.weixin.cp.api.WxCpExportService; | ||
import me.chanjar.weixin.cp.api.WxCpService; | ||
import me.chanjar.weixin.cp.bean.export.WxCpExportRequest; | ||
import me.chanjar.weixin.cp.bean.export.WxCpExportResult; | ||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | ||
|
||
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Export.*; | ||
|
||
/** | ||
* 异步导出接口 | ||
* | ||
* @author <a href="https://github.com/zhongjun96">zhongjun</a> | ||
* @date 2022/4/21 | ||
**/ | ||
@RequiredArgsConstructor | ||
public class WxCpExportServiceImpl implements WxCpExportService { | ||
|
||
private final WxCpService mainService; | ||
|
||
@Override | ||
public String simpleUser(WxCpExportRequest params) throws WxErrorException { | ||
return export(SIMPLE_USER, params); | ||
} | ||
|
||
@Override | ||
public String user(WxCpExportRequest params) throws WxErrorException { | ||
return export(USER, params); | ||
} | ||
|
||
@Override | ||
public String department(WxCpExportRequest params) throws WxErrorException { | ||
return export(DEPARTMENT, params); | ||
} | ||
|
||
@Override | ||
public String tagUser(WxCpExportRequest params) throws WxErrorException { | ||
return export(TAG_USER, params); | ||
} | ||
|
||
@Override | ||
public WxCpExportResult getResult(String jobId) throws WxErrorException { | ||
String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(GET_RESULT), jobId); | ||
String responseContent = this.mainService.get(url, null); | ||
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpExportResult.class); | ||
} | ||
|
||
private String export(String path, WxCpExportRequest params) throws WxErrorException { | ||
String url = this.mainService.getWxCpConfigStorage().getApiUrl(path); | ||
String responseContent = this.mainService.post(url, params.toJson()); | ||
JsonObject tmpJson = GsonParser.parse(responseContent); | ||
return tmpJson.get("jobid").getAsString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/export/WxCpExportRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package me.chanjar.weixin.cp.bean.export; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 异步导出参数 | ||
* | ||
* @author zhongjun | ||
* @date 2022/4/21 | ||
**/ | ||
@Data | ||
public class WxCpExportRequest implements Serializable { | ||
private static final long serialVersionUID = -8127528999898984359L; | ||
|
||
/** | ||
* base64encode的加密密钥,长度固定为43,base64decode之后即得到AESKey。加密方式采用AES-256-CBC方式,数据采用PKCS#7填充至32字节的倍数;IV初始向量大小为16字节,取AESKey前16字节,详见:<a href="http://tools.ietf.org/html/rfc2315">http://tools.ietf.org/html/rfc2315</a> | ||
*/ | ||
@SerializedName("encoding_aeskey") | ||
private String encodingAesKey; | ||
|
||
/** | ||
* 每块数据的部门数,支持范围[104,106],默认值为10^6 | ||
*/ | ||
@SerializedName("block_size") | ||
private Integer blockSize; | ||
|
||
/** | ||
* 需要导出的标签 | ||
* 导出标签成员时使用 | ||
*/ | ||
@SerializedName("tagid") | ||
private Integer tagId; | ||
|
||
public String toJson() { | ||
return WxCpGsonBuilder.create().toJson(this); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/export/WxCpExportResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package me.chanjar.weixin.cp.bean.export; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import me.chanjar.weixin.cp.bean.WxCpBaseResp; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 异步导出响应 | ||
* | ||
* @author zhongjun | ||
* @date 2022/4/21 | ||
**/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class WxCpExportResult extends WxCpBaseResp { | ||
private static final long serialVersionUID = -8673839248829238966L; | ||
|
||
/** | ||
* 任务状态:0-未处理,1-处理中,2-完成,3-异常失败 | ||
*/ | ||
private Integer status; | ||
|
||
@SerializedName("data_list") | ||
private List<ExportData> dataList; | ||
|
||
|
||
@Data | ||
public static class ExportData { | ||
|
||
/** | ||
* 数据下载链接,支持指定Range头部分段下载。有效期2个小时 | ||
*/ | ||
private String url; | ||
|
||
/** | ||
* 密文数据大小 | ||
*/ | ||
private Integer size; | ||
|
||
/** | ||
* 密文数据md5 | ||
*/ | ||
private String md5; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.