|
@@ -33,10 +33,11 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
public class WeiXinCorpController {
|
|
|
//中转的服务器获取部门详情
|
|
|
- public static final String TRANSMIT_SERVER_GET_DEPTDETAIL = "http://47.101.180.183:10010/wxcorp/getCorpDeptDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
|
|
|
- public static final String TRANSMIT_SERVER_GET_DEPTMEMBDETAIL = "http://47.101.180.183:10010/wxcorp/getDeptUserDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
|
|
|
- public static final String TRANSMIT_SERVER_GET_CONTACT_TOKEN = "http://47.101.180.183:10010/wxcorp/getCorpConcactAccessToken?corpid=CORPID&contactSecret=CONTACT_SECRET";
|
|
|
- public static final String TRANSMIT_SERVER_GET_USERDETAIL = "http://47.101.180.183:10010/wxcorp/getUserInfoFromTranServer?accessToken=ACCESS_TOKEN&userId=USERID&deptId=DEPTID";
|
|
|
+ public static final String TRANSMIT_SERVER_STR = "SERVER_IP_PORT";
|
|
|
+ public static final String TRANSMIT_SERVER_GET_DEPTDETAIL = "http://SERVER_IP_PORT/wxcorp/getCorpDeptDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
|
|
|
+ public static final String TRANSMIT_SERVER_GET_DEPTMEMBDETAIL = "http://SERVER_IP_PORT/wxcorp/getDeptUserDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
|
|
|
+ public static final String TRANSMIT_SERVER_GET_CONTACT_TOKEN = "http://SERVER_IP_PORT/wxcorp/getCorpConcactAccessToken?corpid=CORPID&contactSecret=CONTACT_SECRET";
|
|
|
+ public static final String TRANSMIT_SERVER_GET_USERDETAIL = "http://SERVER_IP_PORT/wxcorp/getUserInfoFromTranServer?accessToken=ACCESS_TOKEN&userId=USERID&deptId=DEPTID";
|
|
|
|
|
|
public static final String POST_CONVERT_USERID = "https://qyapi.weixin.qq.com/cgi-bin/batch/userid_to_openuserid?access_token=ACCESS_TOKEN";
|
|
|
|
|
@@ -375,7 +376,7 @@ public class WeiXinCorpController {
|
|
|
String curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
|
|
|
org.json.JSONArray departmentArray = jsonObject.getJSONArray("department");
|
|
|
Integer curUserWXDeptid = departmentArray.getInt(departmentArray.length() - 1);
|
|
|
- JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
+ JSONObject userObj = remoteGetUserDetail(wxCorpInfo, remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
if (userObj != null) {
|
|
|
//成功获取到通讯录的个人详情
|
|
|
Long id = SnowFlake.nextId();
|
|
@@ -430,7 +431,7 @@ public class WeiXinCorpController {
|
|
|
System.out.println("部门未变更,不处理");
|
|
|
}
|
|
|
if (curUserWXDeptid != 0) {
|
|
|
- JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
+ JSONObject userObj = remoteGetUserDetail(wxCorpInfo, remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
if (userObj != null) {
|
|
|
//成功获取到通讯录的个人详情
|
|
|
JSONArray department = userObj.getJSONArray("department");
|
|
@@ -478,7 +479,7 @@ public class WeiXinCorpController {
|
|
|
department.setCompanyId(companyId);
|
|
|
department.setCorpwxDeptid(deptId);
|
|
|
department.setCorpwxDeptpid(parentDeptId);
|
|
|
- JSONObject deptJson = remoteGetDeptDetail(remoteCorpConcactAccessToken, deptId);
|
|
|
+ JSONObject deptJson = remoteGetDeptDetail(wxCorpInfo, remoteCorpConcactAccessToken, deptId);
|
|
|
if (deptJson != null) {
|
|
|
//成功获取到了
|
|
|
String name = deptJson.getString("name");
|
|
@@ -512,7 +513,7 @@ public class WeiXinCorpController {
|
|
|
//发生了部门名称变化
|
|
|
System.out.println("部门名称变化了,请处理==企业微信部门id="+deptId);
|
|
|
String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
- String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", remoteCorpConcactAccessToken).replace("DEPTID", ""+deptId);
|
|
|
+ String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace(TRANSMIT_SERVER_STR, wxCorpInfo.getContactServer()).replace("ACCESS_TOKEN", remoteCorpConcactAccessToken).replace("DEPTID", ""+deptId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
System.out.println("部门返回数据:"+result);
|
|
|
JSONObject resultObj = JSONObject.parseObject(JSONObject.parseObject(result).getString("data"));
|
|
@@ -1422,7 +1423,7 @@ public class WeiXinCorpController {
|
|
|
//获取远程的带姓名的详情,通过企业通讯录的token获取
|
|
|
JSONArray remoteUnAUserList = null;
|
|
|
if (unAssignedUserList.size() > 0) {
|
|
|
- remoteUnAUserList = remoteGetDeptUserDetail(corpContactAccessToken, companyRootDeptId);
|
|
|
+ remoteUnAUserList = remoteGetDeptUserDetail(wxCorpInfo, corpContactAccessToken, companyRootDeptId);
|
|
|
//做id转化
|
|
|
List<String> userIds = new ArrayList<>();
|
|
|
for (int i=0;i<remoteUnAUserList.size(); i++) {
|
|
@@ -1521,7 +1522,7 @@ public class WeiXinCorpController {
|
|
|
department.setCorpwxDeptid(cutDeptJson.getInteger("id"));
|
|
|
department.setCorpwxDeptpid(cutDeptJson.getInteger("parentid"));
|
|
|
System.out.println("开始远程获取部门详情=====");
|
|
|
- String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", corpContactAccessToken).replace("DEPTID", ""+deptId);
|
|
|
+ String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace(TRANSMIT_SERVER_STR, wxCorpInfo.getContactServer()).replace("ACCESS_TOKEN", corpContactAccessToken).replace("DEPTID", ""+deptId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
System.out.println("部门返回数据:"+result);
|
|
|
JSONObject resultObj = JSONObject.parseObject(JSONObject.parseObject(result).getString("data"));
|
|
@@ -1578,7 +1579,7 @@ public class WeiXinCorpController {
|
|
|
JSONArray userList = getDeptUserInfo(curCorpAccessToken, deptId);
|
|
|
JSONArray remoteDeptUserList = null;
|
|
|
if (userList.size() > 0) {
|
|
|
- remoteDeptUserList = remoteGetDeptUserDetail(corpContactAccessToken, deptId);
|
|
|
+ remoteDeptUserList = remoteGetDeptUserDetail(wxCorpInfo, corpContactAccessToken, deptId);
|
|
|
//做id转化
|
|
|
List<String> userIds = new ArrayList<>();
|
|
|
for (int p=0;p<remoteDeptUserList.size(); p++) {
|
|
@@ -1991,8 +1992,8 @@ public class WeiXinCorpController {
|
|
|
return new HttpRespMsg();
|
|
|
}
|
|
|
|
|
|
- private JSONObject remoteGetDeptDetail(String accessToken, int deptId) {
|
|
|
- String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", accessToken).replace("DEPTID", ""+deptId);
|
|
|
+ private JSONObject remoteGetDeptDetail(WxCorpInfo wxCorpInfo, String accessToken, int deptId) {
|
|
|
+ String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace(TRANSMIT_SERVER_STR, wxCorpInfo.getContactServer()).replace("ACCESS_TOKEN", accessToken).replace("DEPTID", ""+deptId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
System.out.println("部门返回数据:"+result);
|
|
|
JSONObject resultObj = JSONObject.parseObject(JSONObject.parseObject(result).getString("data"));
|
|
@@ -2005,15 +2006,15 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private JSONArray remoteGetDeptUserDetail(String accessToken, int deptId) {
|
|
|
- String url = TRANSMIT_SERVER_GET_DEPTMEMBDETAIL.replace("ACCESS_TOKEN", accessToken).replace("DEPTID", ""+deptId);
|
|
|
+ private JSONArray remoteGetDeptUserDetail(WxCorpInfo wxCorpInfo, String accessToken, int deptId) {
|
|
|
+ String url = TRANSMIT_SERVER_GET_DEPTMEMBDETAIL.replace(TRANSMIT_SERVER_STR, wxCorpInfo.getContactServer()).replace("ACCESS_TOKEN", accessToken).replace("DEPTID", ""+deptId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
System.out.println("远程部门人员详情:"+result);
|
|
|
JSONArray obj = JSONObject.parseArray(JSONObject.parseObject(result).getString("data"));
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
|
- private JSONObject remoteGetUserDetail(String accessToken, String userId, Integer deptId, String curCorpAccessToken) {
|
|
|
+ private JSONObject remoteGetUserDetail(WxCorpInfo wxCorpInfo, String accessToken, String userId, Integer deptId, String curCorpAccessToken) {
|
|
|
// String url = TRANSMIT_SERVER_GET_USERDETAIL.replace("ACCESS_TOKEN", accessToken).replace("USERID", userId)
|
|
|
// .replace("DEPTID", deptId+"");
|
|
|
// System.out.println("请求URL="+url);
|
|
@@ -2021,7 +2022,7 @@ public class WeiXinCorpController {
|
|
|
// System.out.println("远程人员详情:"+result);
|
|
|
// JSONObject obj = JSONObject.parseObject(JSONObject.parseObject(result).getString("data"));
|
|
|
// return obj;
|
|
|
- JSONArray remoteDeptUserList = remoteGetDeptUserDetail(accessToken, deptId);
|
|
|
+ JSONArray remoteDeptUserList = remoteGetDeptUserDetail(wxCorpInfo, accessToken, deptId);
|
|
|
//做id转化
|
|
|
List<String> userIds = new ArrayList<>();
|
|
|
for (int i=0;i<remoteDeptUserList.size(); i++) {
|
|
@@ -2052,7 +2053,7 @@ public class WeiXinCorpController {
|
|
|
|
|
|
//通过中转服务器,调用通讯录的accessToken
|
|
|
private String getRemoteCorpConcactAccessToken(WxCorpInfo corpInfo) throws Exception {
|
|
|
- String url = TRANSMIT_SERVER_GET_CONTACT_TOKEN.replace("CORPID", corpInfo.getCorpid()).replace("CONTACT_SECRET", corpInfo.getContactSecret());
|
|
|
+ String url = TRANSMIT_SERVER_GET_CONTACT_TOKEN.replace(TRANSMIT_SERVER_STR, corpInfo.getContactServer()).replace("CORPID", corpInfo.getCorpid()).replace("CONTACT_SECRET", corpInfo.getContactSecret());
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
System.out.println("远程获取Contact AccessToken:"+result);
|
|
|
JSONObject obj = JSONObject.parseObject(result);
|