mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 #2834 【企业微信】新增将代开发应用或第三方应用获取的密文open_userid转换为明文userid的接口
This commit is contained in:
parent
8a161cfa2c
commit
bb65189fb8
@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpOpenUseridToUseridResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult;
|
||||
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
|
||||
@ -233,6 +234,24 @@ public interface WxCpUserService {
|
||||
*/
|
||||
WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList<String> useridList) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* open_userid转换为userid
|
||||
* 将代开发应用或第三方应用获取的密文open_userid转换为明文userid
|
||||
* <pre>
|
||||
* 文档地址:<a href="https://developer.work.weixin.qq.com/document/path/95884#userid%E8%BD%AC%E6%8D%A2">https://developer.work.weixin.qq.com/document/path/95884#userid%E8%BD%AC%E6%8D%A2</a>
|
||||
*
|
||||
* 权限说明:
|
||||
*
|
||||
* 需要使用自建应用或基础应用的access_token
|
||||
* 成员需要同时在access_token和source_agentid所对应应用的可见范围内
|
||||
* </pre>
|
||||
* @param openUseridList open_userid列表,最多不超过1000个。必须是source_agentid对应的应用所获取
|
||||
* @param sourceAgentId 企业授权的代开发自建应用或第三方应用的agentid
|
||||
* @return the WxCpOpenUseridToUseridResult
|
||||
* @throws WxErrorException the wx error exception
|
||||
*/
|
||||
WxCpOpenUseridToUseridResult openUseridToUserid(List<String> openUseridList, String sourceAgentId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取成员ID列表
|
||||
* 获取企业成员的userid与对应的部门ID列表,预计于2022年8月8号发布。若需要获取其他字段,参见「适配建议」。
|
||||
|
@ -11,6 +11,7 @@ import me.chanjar.weixin.common.util.json.GsonParser;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.api.WxCpUserService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpOpenUseridToUseridResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult;
|
||||
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
|
||||
@ -240,6 +241,20 @@ public class WxCpUserServiceImpl implements WxCpUserService {
|
||||
return WxCpUseridToOpenUseridResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpOpenUseridToUseridResult openUseridToUserid(List<String> openUseridList, String sourceAgentId) throws WxErrorException {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String openUserid : openUseridList) {
|
||||
jsonArray.add(openUserid);
|
||||
}
|
||||
jsonObject.add("open_userid_list", jsonArray);
|
||||
jsonObject.addProperty("source_agentid", sourceAgentId);
|
||||
String url = this.mainService.getWxCpConfigStorage().getApiUrl(OPEN_USERID_TO_USERID);
|
||||
String responseContent = this.mainService.post(url, jsonObject.toString());
|
||||
return WxCpOpenUseridToUseridResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpDeptUserResult getUserListId(String cursor, Integer limit) throws WxErrorException {
|
||||
String apiUrl = this.mainService.getWxCpConfigStorage().getApiUrl(USER_LIST_ID);
|
||||
|
@ -0,0 +1,40 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* userid转换
|
||||
* 将代开发应用或第三方应用获取的密文open_userid转换为明文userid
|
||||
* 中间对象
|
||||
* @author yiyingcanfeng
|
||||
*/
|
||||
@Data
|
||||
public class WxCpOpenUseridToUserid implements Serializable {
|
||||
private static final long serialVersionUID = 1714909184316350423L;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* From json wx cp open userid to userid result.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the wx cp open userid to userid result.
|
||||
*/
|
||||
public static WxCpOpenUseridToUserid fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpOpenUseridToUserid.class);
|
||||
}
|
||||
|
||||
@SerializedName("userid")
|
||||
private String userid;
|
||||
|
||||
@SerializedName("open_userid")
|
||||
private String openUserid;
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* userid转换
|
||||
* 将代开发应用或第三方应用获取的密文open_userid转换为明文userid
|
||||
* @author yiyingcanfeng
|
||||
*/
|
||||
@Data
|
||||
public class WxCpOpenUseridToUseridResult implements Serializable {
|
||||
private static final long serialVersionUID = 5179329535139861515L;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* From json wx cp open userid to userid result.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the wx cp open userid to userid result
|
||||
*/
|
||||
public static WxCpOpenUseridToUseridResult fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpOpenUseridToUseridResult.class);
|
||||
}
|
||||
|
||||
@SerializedName("errcode")
|
||||
private Integer errCode;
|
||||
|
||||
@SerializedName("errmsg")
|
||||
private String errMsg;
|
||||
|
||||
@SerializedName("userid_list")
|
||||
private List<WxCpUseridToOpenUserid> useridList;
|
||||
|
||||
@SerializedName("invalid_open_userid_list")
|
||||
private List<String> invalidOpenUseridList;
|
||||
|
||||
|
||||
}
|
@ -931,6 +931,10 @@ public interface WxCpApiPathConsts {
|
||||
* The constant USERID_TO_OPEN_USERID.
|
||||
*/
|
||||
String USERID_TO_OPEN_USERID = "/cgi-bin/batch/userid_to_openuserid";
|
||||
/**
|
||||
* The constant OPEN_USERID_TO_USERID.
|
||||
*/
|
||||
String OPEN_USERID_TO_USERID = "/cgi-bin/batch/openuserid_to_userid";
|
||||
|
||||
/**
|
||||
* The constant USER_LIST_ID.
|
||||
|
Loading…
Reference in New Issue
Block a user