Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }