Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【企业微信】新增将代开发应用或第三方应用获取的密文open_userid转换为明文userid的接口 #2834

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -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号发布。若需要获取其他字段,参见「适配建议」。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -240,6 +241,20 @@ public WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList<String> useridL
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;


}
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ interface User {
* 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.
Expand Down