当前位置:网站首页>C nail development: obtain all employee address books and send work notices
C nail development: obtain all employee address books and send work notices
2022-07-02 08:46:00 【Qingshan blog】
Requirements describe :
1. By calling nails api Get information about all employees in the organization ( Mail list ).
2. By calling nails api Send work notices to designated employees .
Implementation steps :
One 、 Nailing Developer Center Configuration
1. Log in to nailing Developer Center Developers log in uniformly in the background - Nail unified identity authentication .
2. establish Enterprise internal application -H5 Microapplication .

3. Set application permissions
Because you need to read all employee information , therefore Scope of authority Select all employees , Address book management Check all permissions .

4. Development management : Set the server exit IP, That is, you need to call api Of IP Address .

Two 、 Code writing
1. Download nail SDK: Nail officials provide a unified SDK, Use SDK You can easily call the server API, Support for multiple languages , Download address : Server side SDK download - Nail open platform .
2. At present, it is not supported to obtain all employees of the enterprise at one time userid value , If developers want to obtain all employees of the enterprise through the interface userid value , Please refer to the following steps :
call Get sub department ID list Interface , Traverse step by step to get the ID.
By calling Get department users userid list Interface , Get the employees of each department separately userid.
Reference resources : Obtain the information of all employees of the enterprise - Nail open platform
3. Interfaces needed
(1) Get sub department ID list - Nail open platform
(2) Get department users userid list - Nail open platform
(3) according to userid Get user details - Nail open platform
(4) Send work notice - Nail open platform
4. Packaged C# class
Put... In the code agentId、appkey、appsecret Replace it with your own application .
using System;
using System.Collections.Generic;
using DingTalk.Api;
using DingTalk.Api.Request;
using DingTalk.Api.Response;
namespace RC114.WinFrom.DutyAlert.Util
{
public class DingDingHelper
{
//【 Enterprise internal application 】 Configuration parameters ( Because obtaining user information requires enterprise internal applications , Application permissions need to be configured ,IP White list, etc )
private static readonly long agentId = ***;
private static readonly string appkey = "******";
private static readonly string appsecret = "******";
private static string _accessToken = "";
private static DateTime _accessTokenTime = DateTime.Now.AddMinutes(-1);
public static string GetAccessToken()
{
// No, AccessToken perhaps AccessToken Be overdue , Then we can get back
if (_accessToken.IsEmpty() || _accessTokenTime < DateTime.Now)
{
var client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
var req = new OapiGettokenRequest { Appkey = appkey, Appsecret = appsecret };
req.SetHttpMethod("Get");
var execute = client.Execute(req);
if (execute.Errcode == 0)
{
_accessToken = execute.AccessToken;
_accessTokenTime = DateTime.Now.AddHours(1);
}
}
return _accessToken;
}
/// <summary>
/// Get all department numbers
/// </summary>
/// <returns></returns>
public static List<long> GetDepartIds()
{
var client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
var req = new OapiV2DepartmentListsubidRequest { DeptId = 1 };
var res = client.Execute(req, GetAccessToken());
if (res.Errcode == 0) return res.Result.DeptIdList;
return new List<long>();
}
/// <summary>
/// Get the user list under the Department ( Only users Id)
/// </summary>
/// <param name="depid"></param>
/// <returns></returns>
public static List<string> GetDepartUserIds(long depid)
{
var client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listid");
var req = new OapiUserListidRequest { DeptId = depid };
var res = client.Execute(req, GetAccessToken());
if (res.Errcode == 0)
{
if (res.Result == null) return new List<string>();
if (res.Result.UseridList == null) return new List<string>();
return res.Result.UseridList;
}
return new List<string>();
}
/// <summary>
/// According to the user UserId Get user information
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public static string GetUserInfoByUserId(string userId)
{
var client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
var req = new OapiV2UserGetRequest();
req.Userid = userId;
req.Language = "zh_CN";
var res = client.Execute(req, GetAccessToken());
if (res.Errcode == 0) return res.Result.ToJson();
return "";
}
/// <summary>
/// Developing documents : https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
/// Send work reminders
/// </summary>
/// <param name="userId"></param>
/// <param name="message"></param>
/// <returns></returns>
public static string SendMsg(string userId, string message)
{
var client =
new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
var request = new OapiMessageCorpconversationAsyncsendV2Request();
request.AgentId = agentId;
request.UseridList = userId;
request.ToAllUser = false;
var msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
msg.Msgtype = "text";
msg.Text = new OapiMessageCorpconversationAsyncsendV2Request.TextDomain();
msg.Text.Content = message;
request.Msg_ = msg;
long taskid = 0;
var res = client.Execute(request, GetAccessToken());
if (res.Errcode == 0)
{
taskid = res.TaskId;
}
if (taskid > 0)
{
var client2 =
new DefaultDingTalkClient(
"https://oapi.dingtalk.com/topapi/message/corpconversation/getsendprogress");
OapiMessageCorpconversationGetsendprogressRequest request2 =
new OapiMessageCorpconversationGetsendprogressRequest();
request2.AgentId = agentId;
request2.TaskId = taskid;
OapiMessageCorpconversationGetsendprogressResponse
response = client2.Execute(request2, GetAccessToken());
if (response.Errcode == 0)
{
return " Send successfully !";
}
switch (response.Errcode)
{
case 143103: return " Enterprise single application message sending person times QPM Transfinite ";
case 143104: return " Enterprises send people per minute QPM Transfinite ";
case 143105: return " The daily push volume of a single application to a single person exceeds the limit ";
case 143106: return " A single application pushes repeated messages to a single person, exceeding the limit ";
case 143203: return "ISV The number of people sent by a single application to a single enterprise QPM Transfinite ";
case 143204: return "ISV A single application is sent to all enterprises QPM Transfinite ";
case 143205: return " The daily push volume of a single application to a single person exceeds the limit ";
case 143206: return " A single application pushes repeated messages to a single person, exceeding the limit ";
case 1430000: return " Receiver is empty ";
case 1430001: return " Unrecognized grantType";
case 1430002: return " Contains prohibited content ";
case 1430003: return " Trigger OAPI System protection ";
case 1430004: return " Super Executive Protection ";
}
}
return "";
}
}
}边栏推荐
猜你喜欢

STM32 new project (refer to punctual atom)

File upload and download performance test based on the locust framework

Chrome debugging

Openfeign is easy to use

Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)

sqli-labs第8关(布尔盲注)

Minecraft group service opening

OpenFeign 簡單使用

Qunhui NAS configuring iSCSI storage

Linux安装Oracle Database 19c
随机推荐
一、Qt的核心类QObject
Nacos 下载启动、配置 MySQL 数据库
sqli-labs第1关
Finishing the interview essentials of secsha system!!!
Qt——如何在QWidget中设置阴影效果
Programming ape learning English - imperative programming
OpenFeign 簡單使用
Use the kaggle training model and download your own training model
Web security -- core defense mechanism
OpenShift 容器平台社区版 OKD 4.10.0部署
C language replaces spaces in strings with%20
整理秒杀系统的面试必备!!!
Web技术发展史
Tensorflow2 keras 分类模型
gocv边界填充
Zipkin is easy to use
Mutex
Web安全--核心防御机制
k8s入门:Helm 构建 MySQL
Sentinel easy to use