public async Task <string> singleDepartment(int Id) { DingTalkManager dingTalkManager = new DingTalkManager(); var result = await dingTalkManager.SingleDepartment(Id); return(result); }
public async Task <NewErrorModel> GetSpaceId() { DingTalkManager dingTalkManager = new DingTalkManager(); var result = await dingTalkManager.GetSpaceId(DTConfig.AgentId); DingPanModel dingPanModel = JsonConvert.DeserializeObject <DingPanModel>(result); if (dingPanModel != null && dingPanModel.errcode == 0) { return(new NewErrorModel() { data = dingPanModel.spaceid, error = new Error(0, "读取成功!", "") { }, }); } else { return(new NewErrorModel() { error = new Error(dingPanModel.errcode, dingPanModel.errmsg, "") { }, }); } }
public AttachmentInfo DownloadTempMediaFile(HttpContext context) { YZRequest request = new YZRequest(context); string url = request.GetString("mediaUrl"); string ext = request.GetString("ext", null); return(DingTalkManager.DownloadTempMediaFile(url, ext)); }
public async Task <Dictionary <string, string> > GetChildDeptByDeptId(string deptId) { Dictionary <string, string> keyValuePairs = new Dictionary <string, string>(); string[] vs = deptId.Split(','); foreach (var item in vs) { DingTalkManager dingTalkManager = new DingTalkManager(); var result = await dingTalkManager.GetChildDeptByDeptId(item); keyValuePairs.Add(item, result); } return(keyValuePairs); }
public async Task <Dictionary <int, string> > GetDeptUserListByDeptId(List <int> deptIdList) { Dictionary <int, string> keyValuePairs = new Dictionary <int, string>(); if (deptIdList != null) { foreach (var item in deptIdList.Distinct()) { DingTalkManager dingTalkManager = new DingTalkManager(); var result = await dingTalkManager.GetDeptUserListByDeptId(item); keyValuePairs.Add(item, result); } } return(keyValuePairs); }
public async Task <Object> SendVote(string Url, int Id) { try { using (DDContext context = new DDContext()) { Vote vote = context.Vote.Find(Id); string title = vote.Title; string ApplyMan = vote.ApplyMan; DingTalkManager dtManager = new DingTalkManager(); var AccessToken = await dtManager.GetAccessToken(); AccessTokenResponseModel accessTokenResponseModel = JsonConvert.DeserializeObject <AccessTokenResponseModel>(AccessToken); IDingTalkClient client = new DefaultDingTalkClient("https://eco.taobao.com/router/rest"); CorpMessageCorpconversationAsyncsendRequest req = new CorpMessageCorpconversationAsyncsendRequest(); req.Msgtype = "oa"; req.AgentId = long.Parse(DTConfig.AgentId); req.DeptIdList = "1"; req.ToAllUser = true; req.Msgcontent = "{\"message_url\": \"http://dingtalk.com\",\"head\": {\"bgcolor\": \"FFBBBBBB\",\"text\": \"投票通知\"},\"body\": {\"title\": \"正文标题\",\"form\": [],\"content\": \"11111111111\",\"author\": \"李四 \"}}"; CorpMessageCorpconversationAsyncsendResponse rsp = client.Execute(req, accessTokenResponseModel.access_token); Console.WriteLine(rsp.Body); } return(new ErrorModel() { errorCode = 0, errorMessage = "成功" }); } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }
public DingTalkServersController() { dtManager = new DingTalkManager(); }
public async Task <object> PostFile(FileModel fileModel) { try { string result = ""; if (fileModel != null) { string Base64String = fileModel.Base64String.Replace("data:image/png;base64,", ""); byte[] FileContent = Convert.FromBase64String(Base64String); string ImageFilePath = AppDomain.CurrentDomain.BaseDirectory + "UploadFile\\Images\\ChangeImages\\"; string PdfFilePath = AppDomain.CurrentDomain.BaseDirectory + "UploadFile\\Flies\\"; string FileName = Path.GetFileName(fileModel.FileName.Substring(0, fileModel.FileName.Length - 4)); string Err = ""; bool upres = WriteFile(ImageFilePath, FileContent, FileName + ".png", out Err); if (upres) { //清除文件 File.Delete(PdfFilePath + FileName + ".PDF"); //生成PDF PDFHelper.ConvertJpgToPdf(ImageFilePath + FileName + ".png", PdfFilePath + FileName + ".PDF"); //上盯盘 string fileName = PdfFilePath + FileName + ".PDF"; var uploadFileModel = new UploadMediaRequestModel() { FileName = fileName, MediaType = UploadMediaType.File }; DingTalkManager dingTalkManager = new DingTalkManager(); string UploadFileResult = await dingTalkManager.UploadFile(uploadFileModel); FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(UploadFileResult); //替换数据库MediaId using (DDContext context = new DDContext()) { Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == fileModel.TaskId && t.NodeId == 0).First(); tasks.MediaIdPDF = tasks.MediaIdPDF.Replace(fileModel.OldMediaId, fileSendModel.Media_Id); result = tasks.MediaIdPDF; context.Entry <Tasks>(tasks).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } else { result = "上传文件写入失败:" + Err; } } else { result = "上传的文件信息不存在!"; } return(new ErrorModel() { errorCode = 0, errorMessage = "保存成功", Content = result }); } catch (Exception ex) { return(new ErrorModel() { errorCode = 1, errorMessage = ex.Message }); } }