/// <summary> /// 免登数据返回接口 /// </summary> public string BeginDDAutoLogin() { string nonceStr = "helloDD";//todo:随机 ViewBag.NonceStr = nonceStr; string accessToken = DDApiService.Instance.GetAccessToken(); ViewBag.AccessToken = accessToken; string ticket = DDApiService.Instance.GetJsApiTicket(accessToken); long timeStamp = DDHelper.GetTimeStamp(); string url = dtConfig.Url; string signature = DDApiService.Instance.GetSign(ticket, nonceStr, timeStamp, url); ViewBag.Url = url; ViewBag.JsApiTicket = ticket; ViewBag.Signature = signature; ViewBag.NonceStr = nonceStr; ViewBag.TimeStamp = timeStamp; ViewBag.CorpId = DDApiService.Instance.CorpId; ViewBag.CorpSecret = dtConfig.CorpSecret; ViewBag.AgentId = DDApiService.Instance.AgentId; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Url", url); dic.Add("AgentId", DDApiService.Instance.AgentId); dic.Add("CorpId", DDApiService.Instance.CorpId); dic.Add("TimeStamp", timeStamp.ToString()); dic.Add("NonceStr", nonceStr); dic.Add("Signature", signature); dic.Add("JsApiTicket", ticket); return(JsonConvert.SerializeObject(dic)); }
public string SendToDDing(string msg, int enrolID, Sysconfig webHookObj) { if (String.IsNullOrEmpty(msg)) { return("没有消息发送."); } var resMsg = DDHelper.SendMsg(msg, webHookObj.ConfigValue.Trim()); //GetWebHookCache()); JObject jsonSearch = JObject.Parse(resMsg); string errcode = jsonSearch["errcode"].ToString(); string errmsg = jsonSearch["errmsg"].ToString(); var logObj = new EventLog(); logObj.ActionType = "钉钉消息发送 (OK) "; if (errcode != "0") { logObj.ActionType = "钉钉消息发送 (Fail) "; } logObj.LogLevel = LogLevel.System.ToString(); logObj.Comments = $"钉钉反馈:code:{errcode}; message: {errmsg} "; logObj.CreateDate = DateTime.Now; logObj.Creator = "System"; logObj.EnrollID = enrolID; _context.EventLogs.Add(logObj); _context.SaveChangesAsync(); return(errmsg); }
public ApiCommonController() { _CorpId = DDHelper.GetCorpId(); _CorpSecret = DDHelper.CorpSecret(); _AgentId = DDHelper.GetAgentId(); _accessToken = DDHelper.GetToken( ); }
public Response <bool> GetToken() { var result = new Response <bool>(); result.Code = 200; result.Message = DDHelper.GetToken(); return(result); }
public JsonResult Register() { DDHelper DDHelper = new DDHelper(); //获取钉钉token string access_token = DDHelper.GetAccessToken(); //注册时填写的token、aes_key、suitekey string token = ConfigurationManager.AppSettings["SuiteToken"]; //token = "123456";//钉钉测试文档中的token string aes_key = ConfigurationManager.AppSettings["Suiteaes_key"]; //aes_key = "4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij";//钉钉测试文档中的aes_key //准备钉钉回调事件类型 //bpms_task_change : 审批任务开始,结束,转交 //bpms_instance_change:审批实例开始,结束 string data = "{\"call_back_tag\":[\"bpms_task_change\",\"bpms_instance_change\"],\"token\":\"" + token + "\",\"aes_key\":\"" + aes_key + "\",\"url\":\"http://***/Suite/Receive\"}"; string json = new DDHelper().Request("user/create?access_token=" + access_token, data, "POST"); return(Json(json)); }
private void BeginDDAutoLogin() { string nonceStr = "helloDD";//todo:随机 ViewBag.NonceStr = nonceStr; string accessToken = DDApiService.Instance.GetAccessToken(); ViewBag.AccessToken = accessToken; string ticket = DDApiService.Instance.GetJsApiTicket(accessToken); long timeStamp = DDHelper.GetTimeStamp(); string url = Request.Url.ToString(); string signature = DDApiService.Instance.GetSign(ticket, nonceStr, timeStamp, url); ViewBag.JsApiTicket = ticket; ViewBag.Signature = signature; ViewBag.NonceStr = nonceStr; ViewBag.TimeStamp = timeStamp; ViewBag.CorpId = DDApiService.Instance.CorpId; ViewBag.CorpSecret = DDApiService.Instance.CorpSecret; ViewBag.AgentId = DDApiService.Instance.AgentId; }
// // GET: /DD/ //public ActionResult GetUserInfo(string accessToken, string code, bool setCurrentUser = true) //{ // try // { // string userId = DingDingService.Instance.GetUserId(accessToken, code); // string jsonString = DingDingService.Instance.GetUserDetailJson(accessToken, userId); // UserDetailInfo userInfo = DingDingService.Instance.GetUserDetailFromJson(jsonString); // if (setCurrentUser) // { // Session["AccessToken"] = accessToken; // Session["CurrentUser"] = userInfo; // } // return Content(jsonString); // } // catch (Exception ex) // { // return Content(string.Format("{{'errcode': -1, 'errmsg':'{0}'}}", ex.Message)); // } //} // GET: /UserManager/ public ActionResult Index() { string nonceStr = "HELLOWORK";//todo:随机 ViewBag.NonceStr = nonceStr; string accessToken = DingDingService.GetAccessToken(); ViewBag.AccessToken = accessToken; string ticket = DingDingService.GetJsApiTicket(accessToken); long timeStamp = DDHelper.GetTimeStamp(); string url = Request.Url.ToString(); string signature = DingDingService.GetSign(ticket, nonceStr, timeStamp, url); ViewBag.JsApiTicket = ticket; ViewBag.Signature = signature; ViewBag.NonceStr = nonceStr; ViewBag.TimeStamp = timeStamp; ViewBag.CorpId = DDHelper.GetCorpId(); ViewBag.CorpSecret = DDHelper.CorpSecret(); ViewBag.AgentId = DDHelper.GetAgentId(); return(View()); }
public IActionResult PostRobert([FromBody] Enroll item) { if (item == null) { return(BadRequest()); } var resMsg = DDHelper.SendMsg(item.Message, GetWebHookCache()); JObject jsonSearch = JObject.Parse(resMsg); string errcode = jsonSearch["errcode"].ToString(); string errmsg = jsonSearch["errmsg"].ToString(); var logObj = new EventLog(); logObj.ActionType = "发送消息给钉钉机器人"; logObj.LogLevel = LogLevel.Info.ToString(); if (errmsg == "token is not exist") { logObj.LogLevel = LogLevel.Error.ToString(); } logObj.CreateDate = DateTime.Now; logObj.Creator = "System"; _context.Add(logObj); _context.SaveChangesAsync(); return(Json(new { item, errmsg })); // return CreatedAtRoute("GetTodo", new { id = item.Id }, item); }
public List <DepartmentInfo> GetDepartmentList(string accessToken, int parentId = 1) { return(DDHelper.GetDepartmentList(accessToken, parentId)); }
public string GetUserDetailJson(string accessToken, string userId) { return(DDHelper.GetUserDetailJson(accessToken, userId)); }
public UserDetailInfo GetUserDetail(string accessToken, string userId) { return(DDHelper.GetUserDetail(accessToken, userId)); }
public string GetUserId(string accessToken, string code) { return(DDHelper.GetUserId(accessToken, code)); }
public string GetJsApiTicket(string accessToken) { return(DDHelper.GetJsApiTicket(accessToken)); }
/// <summary> /// 获取AccessToken /// 开发者在调用开放平台接口前需要通过CorpID和CorpSecret获取AccessToken。 /// </summary> /// <returns></returns> public string GetAccessToken() { return(DDHelper.GetAccessToken(CorpId, CorpSecret)); }
///获取审批实例列表 public Response <bool> GetProcessIntanceList2(string pid, string start_time, string userid) { var result = new Response <bool>(); string url = "https://eco.taobao.com/router/rest"; string[] userlist = { userid }; Dictionary <string, string> diclist = new Dictionary <string, string>(); diclist.Add("method", "dingtalk.smartwork.bpms.processinstance.list"); diclist.Add("session", _accessToken); diclist.Add("app_key", DDHelper.GetAgentId()); diclist.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); diclist.Add("format", "json"); diclist.Add("v", "2.0"); diclist.Add("sign_method", "md5"); diclist.Add("process_code", "pid"); diclist.Add("userlist", userlist.ToJson()); diclist.Add("start_time", start_time); diclist.Add("end_time", ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString()); //diclist.Add("access_token", _accessToken); string sign = DDHelper.SignTopRequest(diclist, DDHelper.CorpSecret(), "md5"); diclist.Add("sign", sign); diclist = diclist.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value.ToString());//对key进行升序 //遍历元素 //var data = new //{ // method = "dingtalk.smartwork.bpms.processinstance.list", // app_key = DDHelper.GetAgentId(), // timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), // format = "json", // v = "2.0", // sign_method = "md5", // process_code = pid, // start_time = start_time // //end_time = DateTime.Now.Ticks, // // userlist = userlist//080937632339701427 //}; string req = ""; int count = 0; foreach (var item in diclist) { count++; if (count == diclist.Count) { req += item.Key + "=" + item.Value; } else { req += item.Key + "=" + item.Value + "&"; } } try { string response = Infrastructure.Web.WebHelper.HttpWebRequestJson(url + "?" + req, diclist.ToJson()); result.Code = 200; result.Message = response; } catch (Exception ex) { result.Code = 500; result.Message = ex.Message; } return(result); }