钉钉发起实例审批php,钉钉C#发起审批实例demo

钉钉C#发起审批实例demo

钉钉上只有JAVA的demo,虽然也提供了.net的SDK,但是那资料又臭又长,看的头都大了,

这是c#的服务端发起审批的demo,亲测有效

48304ba5e6f9fe08f3fa1abda7d326ab.png

IDingTalkClient client = new DefaultDingTalkClient("https://eco.taobao.com/router/rest");

SmartworkBpmsProcessinstanceCreateRequest req = new SmartworkBpmsProcessinstanceCreateRequest();

req.AgentId = 41605932L;

req.ProcessCode = "PROC-EF6YJL35P2-SCKICSB7P750S0YISYKV3-17IBLGZI-1";

req.OriginatorUserId = "manager432";

req.DeptId = 100L;

req.Approvers = "zhangsan,lisi";

req.CcList = "zhangsan,lisi";

req.CcPosition = "START";

List list2 = new List();

SmartworkBpmsProcessinstanceCreateRequest.FormComponentValueVoDomain obj3 = new SmartworkBpmsProcessinstanceCreateRequest.FormComponentValueVoDomain();

list2.Add(obj3);

obj3.Name = "请假类型";

obj3.Value = "事假";

obj3.ExtValue = "总天数:1";

req.FormComponentValues_ = list2;

SmartworkBpmsProcessinstanceCreateResponse rsp = client.Execute(req, access_token);

Console.WriteLine(rsp.Body);

48304ba5e6f9fe08f3fa1abda7d326ab.png

c#获取钉钉审批信息demo

http://www.zixun119.com/article/459.cshtml

标签:obj3,C#,demo,req,list2,实例,SmartworkBpmsProcessinstanceCreateRequest,new

来源: https://www.cnblogs.com/lonelyxmas/p/12409034.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用C#获取钉钉流程的详细示例代码: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DingTalk.Api; using DingTalk.Api.Request; using DingTalk.Api.Response; namespace DingTalkDemo { class Program { static void Main(string[] args) { // 钉钉开放平台应用的AppKey string appKey = "your app key"; // 钉钉开放平台应用的AppSecret string appSecret = "your app secret"; // 钉钉企业ID string corpId = "your corp id"; // 钉钉企业应用的AgentId string agentId = "your agent id"; // 钉钉企业应用的授权码 string accessToken = GetAccessToken(appKey, appSecret, corpId, agentId); // 获取流程实例列表 string processCode = "your process code"; string startTime = "2021-01-01 00:00:00"; string endTime = "2021-12-31 23:59:59"; int cursor = 0; int size = 20; OapiProcessinstanceListidsRequest req = new OapiProcessinstanceListidsRequest(); req.ProcessCode = processCode; req.StartTime = ConvertDateTimeToInt(startTime); req.EndTime = ConvertDateTimeToInt(endTime); req.Cursor = cursor; req.Size = size; OapiProcessinstanceListidsResponse rsp = GetResponse<OapiProcessinstanceListidsResponse>(req, accessToken); Console.WriteLine(rsp.Body); // 获取流程实例详情 string processInstanceId = "your process instance id"; OapiProcessinstanceGetRequest req2 = new OapiProcessinstanceGetRequest(); req2.ProcessInstanceId = processInstanceId; OapiProcessinstanceGetResponse rsp2 = GetResponse<OapiProcessinstanceGetResponse>(req2, accessToken); Console.WriteLine(rsp2.Body); Console.ReadKey(); } static string GetAccessToken(string appKey, string appSecret, string corpId, string agentId) { IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest req = new OapiGettokenRequest(); req.Appkey = appKey; req.Appsecret = appSecret; req.SetHttpMethod("GET"); OapiGettokenResponse rsp = client.Execute(req); if (rsp.Errcode != 0) { throw new Exception("获取access_token失败,错误码:" + rsp.Errcode + ",错误信息:" + rsp.Errmsg); } string accessToken = rsp.AccessToken; client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/authcorp/scopes"); OapiAuthcorpScopesRequest req2 = new OapiAuthcorpScopesRequest(); req2.MicroappAgentId = agentId; req2.CorpId = corpId; req2.SetHttpMethod("GET"); OapiAuthcorpScopesResponse rsp2 = GetResponse<OapiAuthcorpScopesResponse>(req2, accessToken); if (rsp2.Errcode != 0) { throw new Exception("获取授权码失败,错误码:" + rsp2.Errcode + ",错误信息:" + rsp2.Errmsg); } string authCode = rsp2.AuthScopes.AuthUserid; client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo"); OapiV2UserGetuserinfoRequest req3 = new OapiV2UserGetuserinfoRequest(); req3.SetHttpMethod("GET"); OapiV2UserGetuserinfoResponse rsp3 = GetResponse<OapiV2UserGetuserinfoResponse>(req3, accessToken, authCode); if (rsp3.Errcode != 0) { throw new Exception("获取用户ID失败,错误码:" + rsp3.Errcode + ",错误信息:" + rsp3.Errmsg); } string userId = rsp3.Result.Userid; client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get"); OapiV2UserGetRequest req4 = new OapiV2UserGetRequest(); req4.Userid = userId; req4.SetHttpMethod("GET"); OapiV2UserGetResponse rsp4 = GetResponse<OapiV2UserGetResponse>(req4, accessToken); if (rsp4.Errcode != 0) { throw new Exception("获取用户详情失败,错误码:" + rsp4.Errcode + ",错误信息:" + rsp4.Errmsg); } string accessToken2 = rsp4.Result.AuthAccessToken; return accessToken2; } static T GetResponse<T>(IDingTalkRequest<T> request, string accessToken, string authCode = null) where T : DingTalkResponse { IDingTalkClient client = new DefaultDingTalkClient(request.GetApiName()); request.SetHttpMethod(request.GetHttpMethod()); request.SetAccessToken(accessToken); if (!string.IsNullOrEmpty(authCode)) { request.SetAuthCode(authCode); } return client.Execute(request); } static long ConvertDateTimeToInt(string dateTimeString) { DateTime dt = Convert.ToDateTime(dateTimeString); DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0)); return (long)(dt - dtStart).TotalMilliseconds; } } } ``` 其中,`GetAccessToken`方法用于获取访问钉钉开放平台API的`accessToken`,需要传入应用的`appKey`、`appSecret`、企业ID`corpId`和应用的`agentId`,并调用钉钉开放平台的接口获取授权码和用户ID,最终获取`accessToken`,具体实现可以参考代码。 在获取`accessToken`之后,我们可以通过调用钉钉开放平台提供的API获取流程实例列表和流程实例详情,示例代码中分别演示了如何获取流程实例列表和流程实例详情。 需要注意的是,示例代码中使用了钉钉开放平台的SDK进行API调用,需要在项目中引用相应的SDK,具体可以参考钉钉开放平台的文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值