Beispiel #1
0
        /// <summary>
        /// 发送OA型消息
        /// </summary>
        /// <param name="dingMsg"></param>
        /// <returns></returns>
        public static Ding_Post_ReturnVal Msg_OAText_Send(Ding_Msg_OA dingMsg)
        {
            string url = "https://oapi.dingtalk.com/message/send?access_token=" + dingMsg.Access_Token;

            try
            {
                StringBuilder append_Json = new StringBuilder();
                append_Json.Append("{");
                append_Json.Append("\"touser\":\"" + dingMsg.touser + "\"");
                append_Json.Append(",\"msgtype\":\"oa\"");
                append_Json.Append(",\"agentid\":\"" + dingMsg.agentid + "\"");
                append_Json.Append(",\"oa\":{");
                append_Json.Append("\"message_url\":\"" + dingMsg.messageUrl + "\"");

                append_Json.Append(",\"head\":{");
                append_Json.Append("\"bgcolor\":\"" + dingMsg.head_bgcolor + "\"");
                append_Json.Append(",\"text\":\"" + dingMsg.head_text + "\"");
                append_Json.Append("}");

                append_Json.Append(",\"body\":{");
                append_Json.Append("\"title\":\"" + dingMsg.body_title + "\"");
                if (dingMsg.body_form.Count > 0)
                {
                    append_Json.Append(",\"form\":[");
                    foreach (string itemKey in dingMsg.body_form.Keys)
                    {
                        append_Json.Append("{");
                        append_Json.Append("\"key\":\"" + itemKey + "\"");
                        append_Json.Append(",\"value\":\"" + dingMsg.body_form[itemKey] + "\"");
                        append_Json.Append("},");
                    }
                    append_Json.Remove(append_Json.Length - 1, 1);
                    append_Json.Append("]");
                }

                append_Json.Append(",\"author\":\"" + dingMsg.body_author + "\"");
                append_Json.Append("}");
                append_Json.Append("}");
                append_Json.Append("}");
                string str = new HttpWebResponseUtility().HttpResponsePost_Json(url, append_Json.ToString());
                Ding_Post_ReturnVal postVal = FormatToJson.ParseFromJson <Ding_Post_ReturnVal>(str);
                return(postVal);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Beispiel #2
0
        public Ding_Post_ReturnVal Ding_SendWorkMessage(DingMsgType msgType, long WorkID, string sender)
        {
            DataTable dt = BP.DA.DBAccess.RunSQLReturnTable("SELECT * FROM WF_GenerWorkFlow WHERE WorkID=" + WorkID);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            int    wfState     = int.Parse(dt.Rows[0]["WFState"].ToString());
            string title       = dt.Rows[0]["Title"].ToString();
            string flowNo      = dt.Rows[0]["FK_Flow"].ToString();
            string nodeID      = dt.Rows[0]["FK_Node"].ToString();
            string fid         = dt.Rows[0]["FID"].ToString();
            string flowName    = dt.Rows[0]["FlowName"].ToString();
            string nodeName    = dt.Rows[0]["NodeName"].ToString();
            string starterName = dt.Rows[0]["StarterName"].ToString();
            string rdt         = dt.Rows[0]["RDT"].ToString();


            //结束不发送消息
            if (wfState == 3)
            {
                return(null);
            }



            //判断节点类型,分合流等.
            dt = BP.DA.DBAccess.RunSQLReturnTable("SELECT * FROM WF_EmpWorks WHERE WorkID=" + WorkID + " OR FID=" + WorkID);
            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            string toUsers = "";

            foreach (DataRow dr in dt.Rows)
            {
                if (toUsers.Length > 0)
                {
                    toUsers += "|";
                }
                toUsers += dr["FK_Emp"].ToString();
            }
            if (toUsers.Length == 0)
            {
                return(null);
            }

            switch (msgType)
            {
            case DingMsgType.text:
                Ding_Msg_Text msgText = new Ding_Msg_Text();
                msgText.Access_Token = DingDing.getAccessToken();
                msgText.agentid      = SystemConfig.Ding_AgentID;
                msgText.touser       = toUsers;
                msgText.content      = title + "\n发送人:" + sender + "\n时间:" + BP.DA.DataType.CurrentDataTimeCNOfShort;
                return(DingTalk_Message.Msg_AgentText_Send(msgText));

            case DingMsgType.link:
                Ding_Msg_Link msgLink = new Ding_Msg_Link();
                msgLink.Access_Token = DingDing.getAccessToken();
                msgLink.touser       = toUsers;
                msgLink.agentid      = SystemConfig.Ding_AgentID;
                msgLink.messageUrl   = SystemConfig.Ding_MessageUrl + "/CCMobile/login.aspx";
                msgLink.picUrl       = "@lALOACZwe2Rk";
                msgLink.title        = title;
                msgLink.text         = "发送人:" + sender + "\n时间:" + BP.DA.DataType.CurrentDataTimeCNOfShort;
                return(DingTalk_Message.Msg_AgentLink_Send(msgLink));

            case DingMsgType.OA:
                string[]            users     = toUsers.Split('|');
                string              faildSend = "";
                Ding_Post_ReturnVal postVal   = null;
                foreach (string user in users)
                {
                    Ding_Msg_OA msgOA = new Ding_Msg_OA();
                    msgOA.Access_Token = DingDing.getAccessToken();
                    msgOA.agentid      = SystemConfig.Ding_AgentID;
                    msgOA.touser       = user;
                    msgOA.messageUrl   = SystemConfig.Ding_MessageUrl + "/CCMobile/DingAction.aspx?ActionFrom=message&UserID=" + user
                                         + "&ActionType=ToDo&FK_Flow=" + flowNo + "&FK_Node=" + nodeID
                                         + "&WorkID=" + WorkID + "&FID=" + fid;
                    //00是完全透明,ff是完全不透明,比较适中的透明度值是 1e
                    msgOA.head_bgcolor = "FFBBBBBB";
                    msgOA.head_text    = "审批";
                    msgOA.body_title   = title;
                    Hashtable hs = new Hashtable();
                    hs.Add("流程名", flowName);
                    hs.Add("当前节点", nodeName);
                    hs.Add("申请人", starterName);
                    hs.Add("申请时间", rdt);
                    msgOA.body_form   = hs;
                    msgOA.body_author = sender;
                    postVal           = DingTalk_Message.Msg_OAText_Send(msgOA);
                    if (postVal.errcode != "0")
                    {
                        if (faildSend.Length > 0)
                        {
                            faildSend += ",";
                        }
                        faildSend += user;
                    }
                }
                //有失败消息
                if (faildSend.Length > 0)
                {
                    postVal.errcode = "500";
                    postVal.errmsg  = faildSend + "消息发送失败";
                }
                return(postVal);
            }
            return(null);
        }