Beispiel #1
0
        /// <summary>
        /// 发送群消息
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static ResponseParameters SendGroupMessages(RequestParameters parameters)
        {
            try
            {
                DefaultDingTalkClient client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/send");
                OapiChatSendRequest   request = new OapiChatSendRequest();
                request.Chatid = parameters.Chatid;

                OapiChatSendRequest.MsgDomain msg = new OapiChatSendRequest.MsgDomain();
                msg.Msgtype = "text";
                OapiChatSendRequest.TextDomain text = new OapiChatSendRequest.TextDomain();
                text.Content = parameters.Message;
                msg.Text     = text;

                request.Msg_ = msg;
                OapiChatSendResponse response = client.Execute(request, Get_Access_Token());
                return(new ResponseParameters()
                {
                    ErroCode = response.Errcode,
                    ErroMsg = response.Errmsg,
                    MessageId = response.MessageId
                });
            }
            catch (Exception ex)
            {
                return(new ResponseParameters()
                {
                    ErroCode = -1,
                    ErroMsg = ex.Message
                });
            }
        }
Beispiel #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            JObject obj = null;
            string  msg = string.Empty;

            if (rad_SDK.Checked)
            {
                IDingTalkClient     client = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/send");
                OapiChatSendRequest req    = new OapiChatSendRequest();
                req.Chatid = txt_cid.Text;
                OapiChatSendRequest.TextDomain obj1 = new OapiChatSendRequest.TextDomain();
                obj1.Content = txt_Msg.Text;
                req.Text_    = obj1;
                req.Msgtype  = "text";
                OapiChatSendResponse rsp = client.Execute(req, txt_access_token.Text);
                if (rsp != null)
                {
                    obj = JsonConvert.DeserializeObject <JObject>(rsp.Body);
                    msg = obj["errmsg"].ToString();
                }
            }
            else
            {
                string url = string.Format("https://oapi.dingtalk.com/chat/send?access_token={0}", txt_access_token.Text);
                Dictionary <string, string> list = new Dictionary <string, string>();
                list.Add("chatid", txt_cid.Text);
                list.Add("msgtype", "text");
                Dictionary <string, string> list_message = new Dictionary <string, string>();
                list_message.Add("content", txt_Msg.Text);
                list.Add("text", JsonConvert.SerializeObject(list_message).ToString());

                var result = HttpHelper.Post(url, JsonConvert.SerializeObject(list).ToString());
                obj = JsonConvert.DeserializeObject <JObject>(result);
                msg = obj["errmsg"].ToString();
            }
            lbl_state.Text = msg;
        }