main
黄海 2 years ago
parent 035eff915e
commit 0668b851c3

@ -3,6 +3,7 @@ package UnitTest;
import com.alibaba.druid.filter.stat.StatFilter;
import com.dsideal.FengHuang.DingTalk.Model;
import com.dsideal.FengHuang.DingTalk.OrgPerson;
import com.dsideal.FengHuang.DingTalk.RolePerson;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.DingTalk.Common;
import com.jfinal.kit.PropKit;
@ -79,7 +80,25 @@ public class TestDingTalk {
// OrgPerson.syncPerson(accessToken, rOrg);
//删除单位下所有人员(开发测试时使用)
OrgPerson.delBureauPerson(accessToken, rOrg);
// OrgPerson.delBureauPerson(accessToken, rOrg);
//创建角色组
//RolePerson.createRoleGroup(accessToken, "义务教育阶段角色组"); ---> 3779920123
long groupId = 3779920123L;
//获取指定角色组下有哪些角色
RolePerson.getRoleList(accessToken, groupId);
// RolePerson.createRole(accessToken, "校长", groupId);
// RolePerson.createRole(accessToken, "副校长", groupId);
// RolePerson.createRole(accessToken, "教导主任", groupId);
// RolePerson.createRole(accessToken, "后勤主任", groupId);
// RolePerson.createRole(accessToken, "班主任", groupId);
// RolePerson.createRole(accessToken, "普通教师", groupId);
//
// RolePerson.getRoleList(accessToken, groupId);
//System.out.println(RolePerson.getRolePersonList(accessToken,role_id));
CommonUtil.Print("恭喜,所有操作成功完成!");
}

@ -1,43 +1,92 @@
package com.dsideal.FengHuang.DingTalk;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.taobao.api.ApiException;
import java.util.ArrayList;
import java.util.List;
public class RolePerson {
//暂未改修改,因为我们的角色与测试架构的角色存在冲突,不能在人家的环境中实现全部测试功能,需要搭建自己的专用服务器+架构
public static void createRoleGroup(String access_token, String group_name) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role_group");
OapiRoleAddrolegroupRequest req = new OapiRoleAddrolegroupRequest();
req.setName(group_name);
OapiRoleAddrolegroupResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
//创建成功后需要将角色组信息记录到自己的表中钉钉未提供查询有哪些角色组的API
//groupId --> write to --->database
}
/**
*
*
*
* @param accessToken
* @param access_token
* @param group_id
* @throws ApiException
*/
public static void getRoleList(String accessToken) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/list");
OapiRoleListRequest req = new OapiRoleListRequest();
req.setSize(20L);
req.setOffset(0L);
OapiRoleListResponse rsp = client.execute(req, accessToken);
public static void getRoleList(String access_token, long group_id) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/getrolegroup");
OapiRoleGetrolegroupRequest req = new OapiRoleGetrolegroupRequest();
req.setGroupId(group_id);
OapiRoleGetrolegroupResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
public static void createRole(String access_token, String role_name, long group_id) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role");
OapiRoleAddRoleRequest req = new OapiRoleAddRoleRequest();
req.setRoleName(role_name);
req.setGroupId(group_id);
OapiRoleAddRoleResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
*
*
* @param accessToken
* @param access_token
* @param role_id
* @throws ApiException
*/
public static void getRolePersonList(String accessToken) throws ApiException {
public static List<String> getRolePersonList(String access_token, long role_id) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/simplelist");
OapiRoleSimplelistRequest req = new OapiRoleSimplelistRequest();
req.setRoleId(1203141L);
List<String> res = new ArrayList<>();
long start = 0;
while (true) {
OapiRoleSimplelistRequest req = new OapiRoleSimplelistRequest();
req.setRoleId(role_id);
req.setSize(20L);
req.setOffset(start);
OapiRoleSimplelistResponse rsp = client.execute(req, access_token);
JSONObject jo = JSONObject.parseObject(rsp.getBody());
System.out.println(jo);
break;
}
return res;
}
/**
*
*
* @param accessToken
* @throws ApiException
*/
public static void getRoleList(String accessToken) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/list");
OapiRoleListRequest req = new OapiRoleListRequest();
req.setSize(20L);
req.setOffset(0L);
OapiRoleSimplelistResponse rsp = client.execute(req, accessToken);
OapiRoleListResponse rsp = client.execute(req, accessToken);
System.out.println(rsp.getBody());
}
public static void createRole(String accessToken) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role");
OapiRoleAddRoleRequest req = new OapiRoleAddRoleRequest();
@ -64,20 +113,21 @@ public class RolePerson {
System.out.println(rsp.getBody());
}
public static void addRolePerson(String accessToken) throws ApiException {
public static void addRolePerson(String accessToken, String role_id, String ids) throws ApiException {
//一次最多20个人员
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/addrolesforemps");
OapiRoleAddrolesforempsRequest req = new OapiRoleAddrolesforempsRequest();
req.setRoleIds("1507113584,1507113589");
req.setUserIds("user1,user2");
req.setRoleIds(role_id);
req.setUserIds(ids);
OapiRoleAddrolesforempsResponse rsp = client.execute(req, accessToken);
System.out.println(rsp.getBody());
}
public static void delRolePerson(String accessToken) throws ApiException {
public static void delRolePerson(String accessToken, String role_id, String ids) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/removerolesforemps");
OapiRoleRemoverolesforempsRequest req = new OapiRoleRemoverolesforempsRequest();
req.setRoleIds("1507113578");
req.setUserIds("user100,user101");
req.setRoleIds(role_id);
req.setUserIds(ids);
OapiRoleRemoverolesforempsResponse rsp = client.execute(req, accessToken);
System.out.println(rsp.getBody());
}

Loading…
Cancel
Save