Ejemplo n.º 1
0
        /// <summary>
        /// 上传媒体文件 用于上传图片、语音媒体资源文件以及普通文件(如doc、ppt),接口返回媒体资源标识media_id。请注意:media_id是可复用的,同一个media_id多次使用。 media_id对应的资源文件,仅能在钉钉客户端内使用。
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="type">媒体文件类型,分别有图片(image)、语音(voice)、普通文件(file)</param>
        /// <param name="media">form-data中媒体文件标识,有filename、filelength、content-type等信息</param>
        /// <returns></returns>
        public OapiMediaUploadResponse Upload(string accessToken, string type, FileItem media)
        {
            IDingTalkClient        client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/media/upload");
            OapiMediaUploadRequest request = new OapiMediaUploadRequest();

            request.Type  = type;
            request.Media = media;
            OapiMediaUploadResponse response = client.Execute(request, accessToken);

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取AccessToken ToDo钉钉配置
        /// </summary>
        /// <returns></returns>
        //private string GetAccessToken()
        //{
        //    DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        //    OapiGettokenRequest request = new OapiGettokenRequest();
        //    request.Appkey = "ding7xespi5yumrzraaq";
        //    request.Appsecret = "idKPu4wVaZjBKo6oUvxcwSQB7tExjEbPaBpVpCEOGlcZPsH4BDx-sKilG726-nC3";
        //    request.SetHttpMethod("GET");
        //    OapiGettokenResponse response = client.Execute(request);
        //    return response.AccessToken;
        //}

        /// <summary>
        /// 上传图片并返回MeadiaId
        /// </summary>
        public object UpdateAndGetMediaId(string path)
        {
            IDingTalkClient        client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/media/upload");
            OapiMediaUploadRequest request = new OapiMediaUploadRequest();

            request.Type  = "image";
            request.Media = new Top.Api.Util.FileItem($@"{path}");
            DingDingAppConfig       ddConfig    = _dingDingAppService.GetDingDingConfigByApp(DingDingAppEnum.任务拜访);
            string                  accessToken = _dingDingAppService.GetAccessToken(ddConfig.Appkey, ddConfig.Appsecret);
            OapiMediaUploadResponse response    = client.Execute(request, accessToken);

            return(response);
        }