コード例 #1
0
        /// <summary>
        /// 发送工作通知
        /// </summary>
        public static async Task <DDWorkNoticeSentResult> SendWorkNoticeAsync(DDMessage msg, string userids)
        {
            var access_token = GetAccessToken(DingTalkConfig.CorpId, DingTalkConfig.CorpSecret);
            // var t = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds;
            var httpClient = HttpClientFactory.Create();

            var list = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("agent_id", "203886196"));
            list.Add(new KeyValuePair <string, string>("userid_list", userids));
            list.Add(new KeyValuePair <string, string>("msg", JsonConvert.SerializeObject(msg)));
            var requestContent = new FormUrlEncodedContent(list);
            var response       = await httpClient.PostAsync($"https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token={access_token}", requestContent);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <DDWorkNoticeSentResult>(json));
            }
            return(null);
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: hehua0733/DingTalk.SDK
        /// <summary>
        /// 发送企业会话消息
        /// 企业可以主动发消息给员工,消息量不受限制。
        /// 发送企业会话消息和发送普通会话消息的不同之处在于发送消息的主体不同 - 普通会话消息发送主体是普通员工,体现在接收方手机上的联系人是消息发送员工
        /// </summary>
        /// <param name="touser"></param>
        /// <param name="toparty"></param>
        /// <param name="agentid"></param>
        /// <returns></returns>
        public static SendMessageResult send(string touser, string toparty, string agentid, DDMessage msg)
        {
            var token = Auth.GetToken();

            msg.touser  = touser;
            msg.toparty = toparty;
            msg.agentid = agentid;
            var rst = Post.PostJson <SendMessageResult>(string.Format(URL_send, token), msg);

            return(rst);
        }
コード例 #3
0
ファイル: Message.cs プロジェクト: hehua0733/DingTalk.SDK
        /// <summary>
        /// 发送普通会话消息
        /// 员工可以在微应用中把消息发送到同企业的人或群。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="cid"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static SendMessageResult send_to_conversation(string sender,
                                                             string cid, string agentid, DDMessage msg)
        {
            var token = Auth.GetToken();

            msg.sender = sender; msg.cid = cid; msg.agentid = agentid;
            var rst = Post.PostJson <SendMessageResult>(string.Format(URL_send_to_conversation, token), msg);

            return(rst);
        }