php获取钉钉用户信息demo,钉钉免登陆,并获取用户信息

【实例简介】

该程序集成了 PC端(手机端一样,js部分 换成 dd. 就可以了) 钉钉免登陆,并且获取用户信息

【实例截图】

【核心代码】

Dingding

├── Dingding

│   ├── bin

│   │   ├── Dingding.dll

│   │   ├── Dingding.dll.config

│   │   ├── Dingding.pdb

│   │   ├── Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll

│   │   ├── Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xml

│   │   ├── Newtonsoft.Json.dll

│   │   ├── Newtonsoft.Json.xml

│   │   └── roslyn

│   │   ├── csc.exe

│   │   ├── csc.exe.config

│   │   ├── csc.rsp

│   │   ├── csi.exe

│   │   ├── csi.exe.config

│   │   ├── csi.rsp

│   │   ├── Microsoft.Build.Tasks.CodeAnalysis.dll

│   │   ├── Microsoft.CodeAnalysis.CSharp.dll

│   │   ├── Microsoft.CodeAnalysis.CSharp.Scripting.dll

│   │   ├── Microsoft.CodeAnalysis.dll

│   │   ├── Microsoft.CodeAnalysis.Scripting.dll

│   │   ├── Microsoft.CodeAnalysis.VisualBasic.dll

│   │   ├── Microsoft.CSharp.Core.targets

│   │   ├── Microsoft.DiaSymReader.Native.amd64.dll

│   │   ├── Microsoft.DiaSymReader.Native.x86.dll

│   │   ├── Microsoft.VisualBasic.Core.targets

│   │   ├── Microsoft.Win32.Primitives.dll

│   │   ├── System.AppContext.dll

│   │   ├── System.Collections.Immutable.dll

│   │   ├── System.Console.dll

│   │   ├── System.Diagnostics.FileVersionInfo.dll

│   │   ├── System.Diagnostics.Process.dll

│   │   ├── System.Diagnostics.StackTrace.dll

│   │   ├── System.IO.Compression.dll

│   │   ├── System.IO.FileSystem.dll

│   │   ├── System.IO.FileSystem.DriveInfo.dll

│   │   ├── System.IO.FileSystem.Primitives.dll

│   │   ├── System.IO.Pipes.dll

│   │   ├── System.Reflection.Metadata.dll

│   │   ├── System.Security.AccessControl.dll

│   │   ├── System.Security.Claims.dll

│   │   ├── System.Security.Cryptography.Algorithms.dll

│   │   ├── System.Security.Cryptography.Encoding.dll

│   │   ├── System.Security.Cryptography.Primitives.dll

│   │   ├── System.Security.Cryptography.X509Certificates.dll

│   │   ├── System.Security.Principal.Windows.dll

│   │   ├── System.Text.Encoding.CodePages.dll

│   │   ├── System.Threading.Thread.dll

│   │   ├── System.ValueTuple.dll

│   │   ├── System.Xml.ReaderWriter.dll

│   │   ├── System.Xml.XmlDocument.dll

│   │   ├── System.Xml.XPath.dll

│   │   ├── System.Xml.XPath.XDocument.dll

│   │   ├── vbc.exe

│   │   ├── vbc.exe.config

│   │   ├── vbc.rsp

│   │   ├── VBCSCompiler.exe

│   │   └── VBCSCompiler.exe.config

│   ├── default.aspx

│   ├── default.aspx.cs

│   ├── default.aspx.designer.cs

│   ├── Dingding.csproj

│   ├── Dingding.csproj.user

│   ├── getUserInfo.aspx

│   ├── getUserInfo.aspx.cs

│   ├── getUserInfo.aspx.designer.cs

│   ├── Helper

│   │   ├── CookHelper.cs

│   │   ├── GuidHelper.cs

│   │   ├── HttpHelper.cs

│   │   ├── JsonHelper.cs

│   │   ├── MD5Helper.cs

│   │   └── RequsertHelper.cs

│   ├── js

│   │   └── jquery-1.10.2.min.js

│   ├── Model

│   │   ├── Access_Sdk.cs

│   │   ├── Access_Sign.cs

│   │   ├── Access_Ticket.cs

│   │   ├── Access_Token.cs

│   │   ├── Access_UserInfo.cs

│   │   ├── Dingding_User.cs

│   │   └── Result

│   │   ├── ResultCode.cs

│   │   └── ResultInfo.cs

│   ├── obj

│   │   └── Debug

│   │   ├── DesignTimeResolveAssemblyReferencesInput.cache

│   │   ├── Dingding.csproj.CopyComplete

│   │   ├── Dingding.csproj.CoreCompileInputs.cache

│   │   ├── Dingding.csproj.FileListAbsolute.txt

│   │   ├── Dingding.csprojResolveAssemblyReference.cache

│   │   ├── Dingding.dll

│   │   ├── Dingding.pdb

│   │   ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

│   │   ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

│   │   └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

│   ├── packages.config

│   ├── Properties

│   │   └── AssemblyInfo.cs

│   ├── Service

│   │   └── DingdingService.cs

│   ├── Web.config

│   ├── Web.Debug.config

│   └── Web.Release.config

└── Dingding.sln

11 directories, 95 files

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值