原文:钉钉调用审批流
进入钉钉 “钉钉开放平台” 下载SDK https://ding-doc.dingtalk.com/doc#/faquestions/vzbp02
1 public ActionResult Dingding(string sheetno, long dept, string plant, string Class) { 2 //需填写的主表数据 3 var bill = tApp.GetList().Where(t => t.F_SHEETNO == sheetno).FirstOrDefault(); 4 //需填写的详表数据 5 var details = tDetailApp.GetList(bill.F_Id); 6 7 string accessToken = dingApp.getAccessToken();//AccessToken码 8 9 //获取钉钉用户id:发起人 10 string code = "zhangsan"; 11 var userEntry = userApp.GetList().Where(t => t.F_Account == code).FirstOrDefault(); 12 13 DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create"); 14 OapiProcessinstanceCreateRequest request = new OapiProcessinstanceCreateRequest(); 15 16 request.AgentId = 312711454;//创建的H5微应用的AgentId 17 request.ProcessCode = "PROC-13AFD98D-97F7-4793-8C5D-E612B750BBBC";//在设置审批模板的url中 18 19 List<OapiProcessinstanceCreateRequest.FormComponentValueVoDomain> formComponentValues = new List<OapiProcessinstanceCreateRequest.FormComponentValueVoDomain>(); 20 //单行输入框 21 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain obj1 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 22 obj1.Name = "调拨单号"; 23 obj1.Value = bill.F_SHEETNO; 24 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain obj2 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 25 obj2.Name = "调出部门"; 26 obj2.Value = bill.F_USEDEPTNAME; 27 28 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain obj3 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 29 obj3.Name = "调入部门"; 30 obj3.Value = bill.F_TOUSEDEPTNAME; 31 32 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain obj4 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 33 obj4.Name = ("工厂"); 34 obj4.Value = (plant); 35 36 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain obj5 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 37 obj5.Name = ("资产类别"); 38 obj5.Value = (Class); 39 40 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain vo = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 41 42 var a = ""; 43 foreach (var item in details) 44 { 45 //明细-单行输入框 46 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain ItemName1 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 47 ItemName1.Name = "资产编码"; 48 ItemName1.Value = item.F_BARCODE; 49 50 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain ItemName2 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 51 ItemName2.Name = "资产名称"; 52 ItemName2.Value = item.F_FANAME; 53 54 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain ItemName3 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 55 ItemName3.Name = "资产规格"; 56 ItemName3.Value = item.F_SPEC; 57 58 OapiProcessinstanceCreateRequest.FormComponentValueVoDomain ItemName4 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain(); 59 ItemName4.Name = "资产数量"; 60 ItemName4.Value = item.F_QTY.ToString(); 61 62 a += ",[" + ItemName1.ToJson() + "," + ItemName2.ToJson() + "," + ItemName3.ToJson() + "," + ItemName4.ToJson() + "]"; 63 64 } 65 66 a = "[" + a.Substring(1, a.Length - 1) + "]"; 67 68 69 70 vo.Name = "明细"; 71 vo.Value = a; 72 73 74 formComponentValues.Add(obj1); 75 formComponentValues.Add(obj2); 76 formComponentValues.Add(obj3); 77 formComponentValues.Add(obj4); 78 formComponentValues.Add(obj5); 79 formComponentValues.Add(vo); 80 request.FormComponentValues_ = formComponentValues; 81 request.OriginatorUserId = userEntry.F_DINGID;//发起人 82 request.DeptId = dept;//发起人部门 83 // OapiProcessinstanceCreateResponse response = client.Execute(request, accessToken); 84 85 return Success("提交成功!!"); 86 }
//获取AccessToken码 public string getAccessToken() { string result = string.Empty; IDingTalkClient clientaccess = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey =Appkey;//在创建H5微应用 应用信息 --》 查看详情 --》Appkey request.Appsecret = Appsecret;//在创建H5微应用 应用信息 --》 查看详情 --》Appsecret;
request.SetHttpMethod("GET"); OapiGettokenResponse response = clientaccess.Execute(request); result = response.AccessToken; return result; }
原文地址:https://www.cnblogs.com/lonelyxmas/p/12408957.html
时间: 2024-11-02 09:27:05