main
黄海 2 years ago
parent 4e2926c418
commit d3a6890740

@ -280,6 +280,13 @@
<artifactId>kafka-clients</artifactId>
<version>3.4.0</version>
</dependency>
<!--手机号生成器-->
<!--https://github.com/binarywang/java-testdata-generator-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>java-testdata-generator</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>

@ -1,278 +1,41 @@
package UnitTest;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dingtalkoauth2_1_0.models.*;
import com.aliyun.tea.TeaException;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.alibaba.druid.filter.stat.StatFilter;
import com.dsideal.FengHuang.Util.DingTalkUtil;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.redis.Redis;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.taobao.api.ApiException;
import java.util.ArrayList;
import java.util.List;
public class TestDingTalk {
/**
* 使 Token Client
*
* @return Client
* @throws Exception
*/
private static com.aliyun.dingtalkoauth2_1_0.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
config.protocol = "https";
config.regionId = "central";
return new com.aliyun.dingtalkoauth2_1_0.Client(config);
}
/*
AccessToken
2023-06-06
*/
public static String getAccessToken(String appKey, String appSecret) throws Exception {
final String KEY = "DingTalkAccessToken";
if (!Redis.use().exists(KEY)) {
String accessToken = null;
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest()
.setAppKey(appKey)
.setAppSecret(appSecret);
try {
GetAccessTokenResponse res = client.getAccessToken(getAccessTokenRequest);
accessToken = res.getBody().getAccessToken();
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
}
Redis.use().setex(KEY, 5400, accessToken);//5400:一个半小时过期
return accessToken;
} else {
return Redis.use().get(KEY);
}
}
/*
JsApiToken->ticket
2023-06-06
*/
public static String getJsApiToken(String access_token) throws Exception {
final String KEY = "DingTalkJsApiToken";
if (!Redis.use().exists(KEY)) {
String jsApiToken = null;
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
com.aliyun.dingtalkoauth2_1_0.models.CreateJsapiTicketHeaders createJsapiTicketHeaders = new com.aliyun.dingtalkoauth2_1_0.models.CreateJsapiTicketHeaders();
createJsapiTicketHeaders.xAcsDingtalkAccessToken = access_token;
try {
CreateJsapiTicketResponse res = client.createJsapiTicketWithOptions(createJsapiTicketHeaders, new com.aliyun.teautil.models.RuntimeOptions());
jsApiToken = res.getBody().getJsapiTicket();
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
}
Redis.use().setex(KEY, 5400, jsApiToken);//5400:一个半小时过期
return jsApiToken;
} else {
return Redis.use().get(KEY);
}
}
/*
SsoToken
2023-06-06
*/
public static String getSsoToken(String corpId, String ssoSecret) throws Exception {
final String KEY = "DingTalkSsoToken";
if (!Redis.use().exists(KEY)) {
String ssoToken = null;
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
GetSsoAccessTokenRequest getSsoAccessTokenRequest = new GetSsoAccessTokenRequest()
.setCorpid(corpId)
.setSsoSecret(ssoSecret);
try {
GetSsoAccessTokenResponse res = client.getSsoAccessToken(getSsoAccessTokenRequest);
ssoToken = res.getBody().getAccessToken();
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
}
Redis.use().setex(KEY, 5400, ssoToken);//5400:一个半小时过期
return ssoToken;
} else {
return Redis.use().get(KEY);
}
}
/**
*
*
* @param access_token
* @param userId
* @return
*/
public static String getPerson(String access_token, String userId) {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
OapiV2UserGetRequest req = new OapiV2UserGetRequest();
req.setUserid(userId);
req.setLanguage("zh_CN");
OapiV2UserGetResponse rsp = client.execute(req, access_token);
return rsp.getBody();
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
public static String getPersonToken(String appKey, String appSecret) throws Exception {
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
GetUserTokenRequest getUserTokenRequest = new GetUserTokenRequest()
.setClientId(appKey)
.setClientSecret(appSecret)
//.setCode("abcd")
.setRefreshToken("abcd")
.setGrantType("authorization_code");
try {
GetUserTokenResponse res = client.getUserToken(getUserTokenRequest);
System.out.println(res.getBody().getAccessToken());
System.out.println(res.getBody().getRefreshToken());
} catch (TeaException err) {
System.out.println(err);
} catch (Exception _err) {
System.out.println(_err);
}
return null;
}
public static void createPerson(String access_token) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/create");
OapiV2UserCreateRequest req = new OapiV2UserCreateRequest();
req.setUserid("002");
req.setName("小钉");
req.setSeniorMode(false);
req.setMobile("185xxxxxxxx");
req.setTitle("教职人员");
req.setEmail("test@xx.com");
req.setOrgEmail("test@xxx.com");
req.setOrgEmailType("profession");
ArrayList<OapiV2UserCreateRequest.DeptTitle> deptTitles = new ArrayList<>();
OapiV2UserCreateRequest.DeptTitle deptTitle = new OapiV2UserCreateRequest.DeptTitle();
//deptTitle.setDeptId(4868821xxL);
deptTitle.setTitle("测试");
OapiV2UserCreateRequest.DeptTitle deptTitle1 = new OapiV2UserCreateRequest.DeptTitle();
// deptTitle1.setDeptId(6099161xxL);
deptTitle1.setTitle("专员");
deptTitles.add(deptTitle);
deptTitles.add(deptTitle1);
req.setDeptTitleList(deptTitles);
req.setHideMobile(false);
req.setTelephone("010-8xxxxx6-2345");
req.setJobNumber("100828");
req.setHiredDate(1615219200000L);
req.setWorkPlace("未来park");
req.setRemark("备注备注");
//req.setDeptIdList("4868821xx,6099161xx");
List<OapiV2UserCreateRequest.DeptOrder> deptOrderList = new ArrayList<OapiV2UserCreateRequest.DeptOrder>();
OapiV2UserCreateRequest.DeptOrder deptOrder = new OapiV2UserCreateRequest.DeptOrder();
//deptOrder.setDeptId(4868821xxL);
// deptOrder.setOrder(1L);
OapiV2UserCreateRequest.DeptOrder deptOrder1 = new OapiV2UserCreateRequest.DeptOrder();
//deptOrder1.setDeptId(6099161xxL);
//deptOrder1.setOrder(1L);
deptOrderList.add(deptOrder);
deptOrderList.add(deptOrder1);
req.setDeptOrderList(deptOrderList);
req.setExtension("{\"爱好\":\"[爱好](http://test.com?userid=#userid#&corpid=#corpid#)\"}");
req.setManagerUserid("001");
req.setLoginEmail("test@xxx.com");
OapiV2UserCreateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
*
* @param access_token
* @throws ApiException
*/
public static long createDept(String access_token, String deptName, long parentId, long orderId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/create");
OapiV2DepartmentCreateRequest req = new OapiV2DepartmentCreateRequest();
req.setParentId(parentId);
req.setOrder(orderId);
req.setName(deptName);
OapiV2DepartmentCreateResponse rsp = client.execute(req, access_token);
JSONObject jo = JSONObject.parseObject(rsp.getBody());
if (jo.getLong("errcode") > 0) {
return -1;
}
return jo.getJSONObject("result").getLong("dept_id");
}
/**
*
*
* @param access_token
* @param deptId
* @throws ApiException
*/
public static void delDept(String access_token, long deptId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/delete");
OapiV2DepartmentDeleteRequest req = new OapiV2DepartmentDeleteRequest();
req.setDeptId(deptId);
OapiV2DepartmentDeleteResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
* @param access_token
* @param deptId
* @param deptName
* @param orderId
* @throws ApiException
*/
public static void updateDept(String access_token, long deptId,String deptName,long orderId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/update");
OapiV2DepartmentUpdateRequest req = new OapiV2DepartmentUpdateRequest();
req.setDeptId(deptId);
req.setOrder(orderId);
req.setName(deptName);
req.setLanguage("zh_CN");
OapiV2DepartmentUpdateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
* @param access_token
* @throws ApiException
*/
public static void getDeptList(String access_token) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
req.setDeptId(1L);
req.setLanguage("zh_CN");
OapiV2DepartmentListsubResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
public static DruidPlugin createDruidPlugin(String url, String username, String password, String driverClass) {
DruidPlugin druidPlugin = new DruidPlugin(url, username, password, driverClass);
//最大连接池数量
druidPlugin.setMaxActive(20);
//最小连接池数量
druidPlugin.setMinIdle(1);
//初始化时建立物理连接的个数默认为0
druidPlugin.setInitialSize(1);
//获取连接时最大等待时间单位毫秒。配置了maxWait之后缺省启用公平锁并发效率会有所下降如果需要可以通过配置useUnfairLock属性为true使用非公平锁。
druidPlugin.setMaxWait(60000);
//如果连接空闲时间大于等于minEvictableIdleTimeMillis则关闭物理连接。
druidPlugin.setTimeBetweenEvictionRunsMillis(60000);
//连接保持空闲而不被驱逐的最小时间
druidPlugin.setMinEvictableIdleTimeMillis(300000);
//建议配置为true不影响性能并且保证安全性。申请连接的时候检测如果空闲时间大于timeBetweenEvictionRunsMillis执行validationQuery检测连接是否有效。
druidPlugin.setTestWhileIdle(true);
//申请连接时执行validationQuery检测连接是否有效做了这个配置会降低性能。默认为true
druidPlugin.setTestOnBorrow(false);
//归还连接时执行validationQuery检测连接是否有效做了这个配置会降低性能。默认为true
druidPlugin.setTestOnReturn(false);
//数据监控
druidPlugin.addFilter(new StatFilter());
return druidPlugin;
}
public static void main(String[] args_) throws Exception {
@ -283,49 +46,62 @@ public class TestDingTalk {
final String appKey = PropKit.get("appKey");
String appSecret = PropKit.get("appSecret");
DruidPlugin druid = createDruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim(), PropKit.get("driverClassName"));
druid.start();
ActiveRecordPlugin arp = new ActiveRecordPlugin(druid);
arp.setDevMode(false);
arp.setDialect(new MysqlDialect());
arp.start();
// 用于缓存模块的redis服务
RedisPlugin redis = new RedisPlugin("myRedis", PropKit.get("redis_ip"), PropKit.getInt("redis_port"), 10 * 1000);
redis.start();
String accessToken = getAccessToken(appKey, appSecret);
System.out.println("accessToken=" + accessToken);
String jsApiToken = getJsApiToken(accessToken);
System.out.println("ticket=" + jsApiToken);
String SsoToken = getSsoToken(corpId, ssoSecret);
System.out.println("ssoToken=" + SsoToken);
String res = getPerson(accessToken, "manager3180");
System.out.println(res);
//TODO
//getPersonToken(appKey, appSecret);
//TODO
//createPerson(accessToken);
//创建部门
long dept_id = createDept(accessToken, "黄海的测试部门A", 1, 1);
if (dept_id == -1) {
System.out.println("部门名称已存在,无法创建!");
}
// 钉钉开发踩坑:请求的部门 id 不在授权范围内 http://roc.havemail.cn/archives/595.html
getDeptList(accessToken);
//修改部门
updateDept(accessToken,dept_id,"黄海的测试部门B",2);
//查询看一下
getDeptList(accessToken);
//删除部门
delDept(accessToken, dept_id);
//查询看一下
getDeptList(accessToken);
//通过云平台查询到的学校、部门、教师、学生、班级等信息,需要写入到钉钉中来,并且获取到钉钉返回的唯一主键,回写到云平台的表中去
//通过云平台查询到的学校、部门、教师等信息,需要写入到钉钉中来,并且获取到钉钉返回的唯一主键,回写到云平台的表中去
//这样处理,才能保证下次再来同步数据时,找到相同的唯一主键
String accessToken = DingTalkUtil.getAccessToken(appKey, appSecret);
//1、读取云平台数据创建学校
/*
ID
ALTER TABLE `dsideal_db`.`t_base_organization`
ADD COLUMN `dingtalk_dept_id` bigint NULL COMMENT 'ID' AFTER `zydz`,
ADD INDEX(`dingtalk_dept_id`);
*/
String sql = "select org_id,org_name from t_base_organization where org_name = '长春市教育局'";
Record record = Db.findFirst(sql);
int orgId = record.getInt("org_id");
//单位需要清空一下这个属性
sql = "update t_base_organization set dingtalk_dept_id=null where org_id=?";
Db.update(sql, orgId);
// 学校及学校下的部门
sql = "select org_id,org_name,parent_id,sort_id from t_base_organization where bureau_id=? order by org_id";
List<Record> list = Db.find(sql, orgId);
for (int i = 0; i < list.size(); i++) {
orgId = list.get(i).getInt("org_id");
int yptParentId = list.get(i).getInt("parent_id");
if (yptParentId == -1) yptParentId = orgId;
String dept_name = list.get(i).getStr("org_name");
sql = "select dingtalk_dept_id from t_base_organization where org_id=?";
Record r = Db.findFirst(sql, yptParentId);
long dingtalk_dept_id;
if (r.get("dingtalk_dept_id") == null) {
dingtalk_dept_id = 1;
} else {
dingtalk_dept_id = r.getLong("dingtalk_dept_id");
}
long sortId = list.get(i).getLong("sort_id");
//创建
long dt_dept_id = DingTalkUtil.createDept(accessToken, dept_name, dingtalk_dept_id, sortId);
//回写
sql = "update t_base_organization set dingtalk_dept_id=? where org_id=?";
Db.update(sql, dt_dept_id, orgId);
}
System.out.println("恭喜,所有操作成功完成!");
}
}

@ -0,0 +1,268 @@
package com.dsideal.FengHuang.Util;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dingtalkoauth2_1_0.models.*;
import com.aliyun.tea.TeaException;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.jfinal.plugin.redis.Redis;
import com.taobao.api.ApiException;
public class DingTalkUtil {
/**
* 使 Token Client
*
* @return Client
* @throws Exception
*/
private static com.aliyun.dingtalkoauth2_1_0.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
config.protocol = "https";
config.regionId = "central";
return new com.aliyun.dingtalkoauth2_1_0.Client(config);
}
/*
AccessToken
2023-06-06
*/
public static String getAccessToken(String appKey, String appSecret) throws Exception {
final String KEY = "DingTalkAccessToken";
if (!Redis.use().exists(KEY)) {
String accessToken = null;
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest()
.setAppKey(appKey)
.setAppSecret(appSecret);
try {
GetAccessTokenResponse res = client.getAccessToken(getAccessTokenRequest);
accessToken = res.getBody().getAccessToken();
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
}
Redis.use().setex(KEY, 5400, accessToken);//5400:一个半小时过期
return accessToken;
} else {
return Redis.use().get(KEY);
}
}
/*
JsApiToken->ticket
2023-06-06
*/
public static String getJsApiToken(String access_token) throws Exception {
final String KEY = "DingTalkJsApiToken";
if (!Redis.use().exists(KEY)) {
String jsApiToken = null;
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
com.aliyun.dingtalkoauth2_1_0.models.CreateJsapiTicketHeaders createJsapiTicketHeaders = new com.aliyun.dingtalkoauth2_1_0.models.CreateJsapiTicketHeaders();
createJsapiTicketHeaders.xAcsDingtalkAccessToken = access_token;
try {
CreateJsapiTicketResponse res = client.createJsapiTicketWithOptions(createJsapiTicketHeaders, new com.aliyun.teautil.models.RuntimeOptions());
jsApiToken = res.getBody().getJsapiTicket();
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
}
Redis.use().setex(KEY, 5400, jsApiToken);//5400:一个半小时过期
return jsApiToken;
} else {
return Redis.use().get(KEY);
}
}
/*
SsoToken
2023-06-06
*/
public static String getSsoToken(String corpId, String ssoSecret) throws Exception {
final String KEY = "DingTalkSsoToken";
if (!Redis.use().exists(KEY)) {
String ssoToken = null;
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
GetSsoAccessTokenRequest getSsoAccessTokenRequest = new GetSsoAccessTokenRequest()
.setCorpid(corpId)
.setSsoSecret(ssoSecret);
try {
GetSsoAccessTokenResponse res = client.getSsoAccessToken(getSsoAccessTokenRequest);
ssoToken = res.getBody().getAccessToken();
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
}
}
Redis.use().setex(KEY, 5400, ssoToken);//5400:一个半小时过期
return ssoToken;
} else {
return Redis.use().get(KEY);
}
}
/**
*
*
* @param access_token
* @param userId
* @return
*/
public static String getPerson(String access_token, String userId) {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
OapiV2UserGetRequest req = new OapiV2UserGetRequest();
req.setUserid(userId);
req.setLanguage("zh_CN");
OapiV2UserGetResponse rsp = client.execute(req, access_token);
return rsp.getBody();
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
public static String getPersonToken(String appKey, String appSecret) throws Exception {
com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
GetUserTokenRequest getUserTokenRequest = new GetUserTokenRequest()
.setClientId(appKey)
.setClientSecret(appSecret)
//.setCode("abcd")
.setRefreshToken("abcd")
.setGrantType("authorization_code");
try {
GetUserTokenResponse res = client.getUserToken(getUserTokenRequest);
System.out.println(res.getBody().getAccessToken());
System.out.println(res.getBody().getRefreshToken());
} catch (TeaException err) {
System.out.println(err);
} catch (Exception _err) {
System.out.println(_err);
}
return null;
}
/**
*
*
* @param access_token
* @throws ApiException
*/
public static long createDept(String access_token, String deptName, long parentId, long orderId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/create");
OapiV2DepartmentCreateRequest req = new OapiV2DepartmentCreateRequest();
req.setParentId(parentId);
req.setOrder(orderId);
req.setName(deptName);
OapiV2DepartmentCreateResponse rsp = client.execute(req, access_token);
JSONObject jo = JSONObject.parseObject(rsp.getBody());
if (jo.getLong("errcode") > 0) {
return -1;
}
return jo.getJSONObject("result").getLong("dept_id");
}
/**
*
*
* @param access_token
* @param deptId
* @throws ApiException
*/
public static void delDept(String access_token, long deptId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/delete");
OapiV2DepartmentDeleteRequest req = new OapiV2DepartmentDeleteRequest();
req.setDeptId(deptId);
OapiV2DepartmentDeleteResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
*
* @param access_token
* @param deptId
* @param deptName
* @param orderId
* @throws ApiException
*/
public static void updateDept(String access_token, long deptId, String deptName, long orderId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/update");
OapiV2DepartmentUpdateRequest req = new OapiV2DepartmentUpdateRequest();
req.setDeptId(deptId);
req.setOrder(orderId);
req.setName(deptName);
req.setLanguage("zh_CN");
OapiV2DepartmentUpdateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
*
* @param access_token
* @throws ApiException
*/
public static void getDeptList(String access_token, long dept_id) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
req.setDeptId(dept_id);
req.setLanguage("zh_CN");
OapiV2DepartmentListsubResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
*
* @param access_token
* @param deptId
* @param userId
* @param personName
* @param tel
* @param zhiWei
* @throws ApiException
*/
public static void createPerson(String access_token, String deptId, String userId, String personName, String tel, String zhiWei) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/create");
OapiV2UserCreateRequest req = new OapiV2UserCreateRequest();
req.setUserid(userId);
req.setName(personName);
req.setMobile(tel);
req.setTitle(zhiWei);
req.setDeptIdList(deptId);
OapiV2UserCreateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
/**
*
*
* @param access_token
* @param userId
* @throws ApiException
*/
public static void delPerson(String access_token, String userId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/delete");
OapiV2UserDeleteRequest req = new OapiV2UserDeleteRequest();
req.setUserid(userId);
OapiV2UserDeleteResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
}

@ -10,3 +10,10 @@ appSecret=hnxZ93QqkGJpRyBziaR2vlbOPZo1U9eeqj73DfFuFnIxIUHNPbMR2DkIol9oGteh
redis_ip=10.10.14.169
# redis port
redis_port=18890
# 数据库信息
driverClassName=com.mysql.cj.jdbc.Driver
user=root
password=DsideaL147258369
jdbcUrl=jdbc:mysql://10.10.14.199:22066/dsideal_db?rewriteBatchedStatements=true&useUnicode=true&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

@ -10,3 +10,10 @@ appSecret=hnxZ93QqkGJpRyBziaR2vlbOPZo1U9eeqj73DfFuFnIxIUHNPbMR2DkIol9oGteh
redis_ip=10.10.14.169
# redis port
redis_port=18890
# 数据库信息
driverClassName=com.mysql.cj.jdbc.Driver
user=root
password=DsideaL147258369
jdbcUrl=jdbc:mysql://10.10.14.199:22066/dsideal_db?rewriteBatchedStatements=true&useUnicode=true&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

Loading…
Cancel
Save