c# .net对接企业微信小助手 接口请求时长预警

本文介绍了如何使用C# .NET进行企业微信接口对接,特别是针对接口请求时长超过1秒的情况,实现了告警功能。详细内容包括企业微信的配置、POST请求公共方法的编写、发送企业微信消息的封装以及API接口的统一处理策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、企业微信入参   

企业微信配置 机器人助手 : https://work.weixin.qq.com/api/doc/90000/90136/91770

    /// <summary>
    /// 企业微信机器人入参
    /// </summary>
    public class WebHookInput
    {
        /// <summary>
        /// 消息类型,此时固定为text
        /// </summary>
        public string msgtype
        {
            get
            {
                return "text";
            }
        }
        /// <summary>
        /// 文本内容
        /// </summary>
        public WebHookTextInput text { get; set; }
    }
    public class WebHookTextInput
    {

        /// <summary>
        /// 文本内容,最长不超过2048个字节,必须是utf8编码
        /// </summary>
        public string content { get; set; }
    }

 

二、post请求公共方法

        public static Toutput PostRequest<Toutput, Tinput>(string url, Tinput input)
        {
            Toutput output = default;
            if (string.IsNullOrEmpty(url)) return output;
            try
            {
                string inputParam = JsonConvert.SerializeObject(input);
                string result = GetPostUrl(url, inputParam);
                if (!string.IsNullOrEmpty(result))
                {
                    output = JsonConvert.DeserializeObject<Toutput>(result);
                }
            }
            catch (Exception ex)
            {
            }
            return output;
        }

//post
private static string GetPostUrl(string url, string postData, Dictionary<string, string> heardsDic = null)
        {
            string result = string.Empty;
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值