调用聊天机器人 -小I机器人

本文介绍了一个简单的C#程序,该程序能够通过HTTP GET请求将字符串消息发送到小i机器人,并从返回的JSON格式数据中解析出机器人的回复内容。
 public static string sendMsg2(string msg)
       {

           try
           {    
                msg = Uri.EscapeDataString( msg);
                string sUrl = "http://i.xiaoi.com/robot/webrobot?data={%22sessionId%22:%228e52024188u65e13782%22,%22robotId%22:%22webbot%22,%22userId%22:%22b472189e640448c8927f3b982d945886%22,%22body%22:{%22content%22:%22"+msg+"%22},%22type%22:%22txt%22}";
                string s = HttpHelper.HttpGet(sUrl);
                string[] sAll =s.Split((char)1);//Trim((char)1).Trim();
                int i = sAll.Length;
                if (i > 1) {
                    i = i - 2;
                }
                if (i == 2)
                {
                    i = 0;
                }
                s= sAll[i].Trim((char)1).Trim();
                JToken  j = JToken.Parse(s);
               // //{"robotId":"webbot","userId":"b472189e640448c8927f3b982d945886","sessionId":"8e52024100404449ba67f903c5e13782","type":"txt","body":{"fontStyle":0,"fontColor":0,"content":"今天是星期三\r\n今天是戊戌年五月廿一\r\n宜:嫁娶.祭祀.沐浴.扫舍.修饰垣墙.\r\n忌:行丧.安葬.\r\n\r\n","emoticons":{}}}
               return "" + j["body"]["content"];

           }
           catch(Exception ex)
           {

               return "";
           }


       }

  

 

转载于:https://www.cnblogs.com/wgscd/p/9263908.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值