• 大小: 6.89MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-04
  • 语言: 其他
  • 标签:

资源简介

DDRobot - 钉钉自定义机器人消息推送

资源截图

代码片段和文件信息

using Newtonsoft.Json;
using OapiRobotTest.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace OapiRobotTest
{
    public class OapiRobot
    {
        public static string dd_host = ConfigurationManager.AppSettings[“DDHost“];
        public static string RobotSendUrl = ConfigurationManager.AppSettings[“RobotSendUrl“];

        /// 
        /// 发起请求
        /// 

        /// 地址
        /// 数据
        /// 请求类型
        /// 
        public static String Request(string url string data string reqtype)
        {
            HttpWebRequest web = (HttpWebRequest)HttpWebRequest.Create(dd_host + url);
            web.ContentType = “application/json“;
            web.Method = reqtype;
            if (data.Length > 0 && reqtype.Trim().ToUpper() == “POST“)
            {
                byte[] postBytes = Encoding.UTF8.GetBytes(data);
                web.ContentLength = postBytes.Length;
                using (Stream reqStream = web.GetRequestStream())
                {
                    reqStream.Write(postBytes 0 postBytes.Length);
                }
            }
            string html = string.Empty;
            using (HttpWebResponse response = (HttpWebResponse)web.GetResponse())
            {
                Stream responseStream = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(responseStream Encoding.UTF8);
                html = streamReader.ReadToEnd();
            }
            return html;
        }
        /// 
        /// 发送文本消息
        /// 

        /// 文本内容
        /// @人员电话
        /// 是否@群所有成员
        public static void OapiRobotText(string content List atMobiles bool isAtAll)
        {
            TextModel tModel = new TextModel();
            tModel.at = new atText();
            tModel.text = new text();
            tModel.at.atMobiles = new List();

            tModel.text.content = content;
            tModel.at.atMobiles.AddRange(atMobiles);
            tModel.at.isAtAll = isAtAll;
            tModel.msgtype = “text“;

            string data = JsonConvert.Serializeobject(tModel);
            string json = Request(RobotSendUrl data “POST“);
        }
        /// 
        /// 发送link消息
        /// 

        /// tle“>消息标题
        /// 消息内容。如果太长只会部分展示
        /// 点击消息跳转的URL
        /// 图片URL
        public static void OapiRobotlink(string title string text string messageUrl string picUrl)
        {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-01-02 11:56  DDRobot-master\
     文件        1000  2019-01-02 11:56  DDRobot-master\OapiRobot.sln
     文件       45056  2019-01-02 11:56  DDRobot-master\OapiRobot.suo
     文件       40960  2019-01-02 11:56  DDRobot-master\OapiRobot.v12.suo
     目录           0  2019-01-02 11:56  DDRobot-master\OapiRobotTest\
     文件         419  2019-01-02 11:56  DDRobot-master\OapiRobotTest\App.config
     目录           0  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Model\
     文件        2169  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Model\ActionCardOverallModel.cs
     文件        2463  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Model\ActionCardSingleModel.cs
     文件        1847  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Model\FeedCardModel.cs
     文件        1604  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Model\linkModel.cs
     文件        1354  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Model\MarkDownModel.cs
     文件        1209  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Model\TextModel.cs
     文件        9271  2019-01-02 11:56  DDRobot-master\OapiRobotTest\OapiRobot.cs
     文件        3334  2019-01-02 11:56  DDRobot-master\OapiRobotTest\OapiRobot.csproj
     文件        4330  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Program.cs
     目录           0  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Properties\
     文件        1350  2019-01-02 11:56  DDRobot-master\OapiRobotTest\Properties\AssemblyInfo.cs
     目录           0  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\
     目录           0  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\
     文件      675240  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\Newtonsoft.Json.dll
     文件      250244  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\Newtonsoft.Json.pdb
     文件      688142  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\Newtonsoft.Json.xml
     文件       14336  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\OapiRobotTest.exe
     文件         408  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\OapiRobotTest.exe.config
     文件       19968  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\OapiRobotTest.pdb
     文件       24224  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\OapiRobotTest.vshost.exe
     文件         408  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\OapiRobotTest.vshost.exe.config
     文件         479  2019-01-02 11:56  DDRobot-master\OapiRobotTest\bin\Debug\OapiRobotTest.vshost.exe.manifest
     目录           0  2019-01-02 11:56  DDRobot-master\OapiRobotTest\obj\
     目录           0  2019-01-02 11:56  DDRobot-master\OapiRobotTest\obj\Debug\
............此处省略53个文件信息

评论

共有 条评论