机器人聊天软件c#_C#制作简易QQ聊天机器人
最近對QQ聊天機器人比較感興趣,奈何一直沒找到C#的源碼,就自己摸索,好了廢話不多說了,開始正題。
首先我們要準備的是C# 的SDK下載地址:http://pan.baidu.com/s/1geW0X3P,Newtonsoft.Json.dll插件
打開C#SDK源碼后找到MyApp.cs(QQ發送消模塊) 在里面找到QQ私聊消息
HttpWebResponse Response = null;
string result = null;
String _strMessage = msg(收到的QQ消息);
String INFO = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(_strMessage));
String getURL = "http://api.qingyunke.com/api.php?key=free&appid=0&msg=" + INFO;
HttpWebRequest MyRequest = (HttpWebRequest)HttpWebRequest.Create(getURL);
HttpWebResponse MyResponse = (HttpWebResponse)MyRequest.GetResponse();
Response = MyResponse;
using (Stream MyStream = MyResponse.GetResponseStream())
{
long ProgMaximum = MyResponse.ContentLength;
long totalDownloadedByte = 0;
byte[] by = new byte[1024];
int osize = MyStream.Read(by, 0, by.Length);
Encoding encoding = Encoding.UTF8;
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte;
result += encoding.GetString(by, 0, osize);
long ProgValue = totalDownloadedByte;
osize = MyStream.Read(by, 0, by.Length);
}
}
//解析json
JsonReader reader = new JsonTextReader(new StringReader(result));
while (reader.Read())
{
if (reader.Path == "content")//content是青云客傳過來的字符串里面的一個字段不用修改
{
//結果賦值
result = reader.Value.ToString();//result最終機器人回答的話
}
}
把這些代碼寫進去之后打包成DLL文件放入酷Q的CSharpDemoTP文件夾,別忘記把Newtonsoft.Json.dll插件放入根目錄,主要原理就是引入青云客的API ?將QQ收到的消息
交給這個API處理。
我是新手菜鳥一枚,不喜勿噴,謝謝
詳細教程
這里加上上文代碼就OK了 ?自己想加什么就加什么
總結
以上是生活随笔為你收集整理的机器人聊天软件c#_C#制作简易QQ聊天机器人的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: h5活动是什么意思_分析什么是h5页面
- 下一篇: easyui js解析字符串_easyu