• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#钉钉钉盘文件管理

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.获取AccessToken

https://ding-doc.dingtalk.com/doc#/serverapi2/eev437

private static string GetAccessToken()
        {
            DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
            OapiGettokenRequest request = new OapiGettokenRequest();
            request.Appkey = "Appkey";//填写对应的Appkey
            request.Appsecret = "Appsecret ";//填写对应的Appsecret 
            request.SetHttpMethod("GET");
            OapiGettokenResponse response = client.Execute(request);

            string result = response.AccessToken;
            return result;
        }

2.上传钉盘文件

单步上传文件,文件大小不得超过8M。

  /// <summary>
        /// 通过钉盘 上传文件
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string UploadFile(string filePath)
        {
            OapiFileUploadSingleRequest request = new OapiFileUploadSingleRequest();
            request.FileSize=(1000L);
            request.AgentId=("AgentId");//填写对应的AgentId
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/file/upload/single?" + WebUtils.BuildQuery(request.GetParameters()));
            // 必须重新new一个请求
            request = new OapiFileUploadSingleRequest();
            request.File=(new FileItem(filePath));
            OapiFileUploadSingleResponse response = client.Execute(request, Get_CorPsecret());
            return response.Body;//返回文件存储id
        }

3.发送文件给用户


        /// <summary>
        /// 通过钉盘里面的文件发送给用户
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="mediaID"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string SendUserMedia(string userID, string mediaID,string fileName)
        {
            OapiCspaceAddToSingleChatRequest request = new OapiCspaceAddToSingleChatRequest();
            request.AgentId= "AgentId";//填写对应的AgentId
            request.Userid=("Userid");//钉钉用户对应ID
            request.MediaId = HttpUtility.UrlEncodeUnicode(mediaID);
            request.FileName= fileName;
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/cspace/add_to_single_chat?" + WebUtils.BuildQuery(request.GetParameters()));
            OapiCspaceAddToSingleChatResponse response = client.Execute(request, Get_CorPsecret());
            return response.Body; 
        }

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
A*寻路算法C++简单实现发布时间:2022-07-14
下一篇:
c++自定义异常类发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap