net编写的微信聊天机器人,实现了根据聊天内容自动回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace wxBot.NET
{
class TulingWXBot:wxbot
{
private string tuling_key = "";
private bool robot_switch = true;
public TulingWXBot()
{
try
{
IniHelper _IniHelper = new IniHelper(Environment.CurrentDirectory "\\conf.ini");
tuling_key = _IniHelper.ReadValue("main", "key");
if (tuling_key == "")
{
Console.WriteLine("[ERROR] Please set tuling key . ");
}
else
{
Console.WriteLine("[INFO] tuling_key:" tuling_key);
}
}
catch
{
}
}
public string tuling_auto_reply(string uid, wxMsg msg)
{
if (tuling_key != "")
{
string url = "http://www.tuling123.com/openapi/api";
string user_id = uid.Replace("@", "").Substring(0, 30);
string data = "key=" tuling_key "&info=" msg.Content "&userid=" user_id;
string r = Http.WebPost(url, data);
JObject result = JsonConvert.DeserializeObject(r) as JObject;
string rr = "";
if (result["code"].ToString() == "100000")
{
rr = result["text"].ToString().Replace("<br>", " ");
rr = rr.Replace("\xa0", " ");
}
else if (result["code"].ToString() == "200000")
{
rr = result["url"].ToString();
}
else if (result["code"].ToString() == "302000")
{
foreach (JObject k in result["list"])
{
rr = rr "【" k["source"].ToString() "】 "
k["article"].ToString() "\t" k["detailurl"] "\n";
}
}
else
{
rr = result["text"].ToString().Replace("<br>", " ");
rr = rr.Replace("\xa0", " ");
}
return rr " @Auto Reply by Turing Robot@";
}
else
{
return ("知道啦");
}
}
public override void handle_msg_all(wxMsg msg)
{
if (!robot_switch && msg.Type != 1)
{
return;
}
if (msg.Type == 1 && msg.ContentType == 0)
{
auto_switch(msg);
}
if (msg.Type == 4 && msg.ContentType == 0)
{
send_msg_by_uid(tuling_auto_reply(msg.From, msg), msg.From);
}
}
public void auto_switch(wxMsg msg)
{
string[] stop_cmd = { "退下", "走开", "关闭", "关掉", "休息", "滚开" };
string[] start_cmd = { "出来", "启动", "工作" };
string msg_data = msg.Content;
if (robot_switch)
{
if (stop_cmd.Contains(msg_data))
{
robot_switch = false;
send_msg_by_uid("robot off", msg.From);
}
}
else
{
if (start_cmd.Contains(msg_data))
{
robot_switch = true;
send_msg_by_uid("robot on", msg.From);
}
}
}
}
}
资源文件列表
wxBot.NET-master/.gitattributes , 378
wxBot.NET-master/.gitignore , 649
wxBot.NET-master/README.md , 519
wxBot.NET-master/wxBot.NET.sln , 917
wxBot.NET-master/wxBot.NET/App.config , 187
wxBot.NET-master/wxBot.NET/Config/conf.ini , 16
wxBot.NET-master/wxBot.NET/Gma.QrCodeNet.Encoding.Net35.dll , 108032
wxBot.NET-master/wxBot.NET/Libs/Gma.QrCodeNet.Encoding.Net35.dll , 108032
wxBot.NET-master/wxBot.NET/Libs/Newtonsoft.Json.dll , 510976
wxBot.NET-master/wxBot.NET/Newtonsoft.Json.dll , 510976
wxBot.NET-master/wxBot.NET/Objects/wxMsg.cs , 1482
wxBot.NET-master/wxBot.NET/Objects/wxUser.cs , 4718
wxBot.NET-master/wxBot.NET/Program.cs , 382
wxBot.NET-master/wxBot.NET/Properties/AssemblyInfo.cs , 1356
wxBot.NET-master/wxBot.NET/SimpleWXbot.cs , 477
wxBot.NET-master/wxBot.NET/TulingWXBot.cs , 3824
wxBot.NET-master/wxBot.NET/Utility/Common.cs , 2607
wxBot.NET-master/wxBot.NET/Utility/CommonRule.cs , 2606
wxBot.NET-master/wxBot.NET/Utility/Http.cs , 5276
wxBot.NET-master/wxBot.NET/Utility/IniHelper.cs , 1534
wxBot.NET-master/wxBot.NET/Utility/Log.cs , 182
wxBot.NET-master/wxBot.NET/Utility/WebRule.cs , 6667
wxBot.NET-master/wxBot.NET/bin/Debug/Config/conf.ini , 48
wxBot.NET-master/wxBot.NET/bin/Debug/Gma.QrCodeNet.Encoding.Net35.dll , 108032
wxBot.NET-master/wxBot.NET/bin/Debug/Newtonsoft.Json.dll , 510976
wxBot.NET-master/wxBot.NET/bin/Debug/conf.ini , 48
wxBot.NET-master/wxBot.NET/bin/Debug/img/QRcode.png , 554
wxBot.NET-master/wxBot.NET/bin/Debug/wxBot.NET.exe , 31232
wxBot.NET-master/wxBot.NET/bin/Debug/wxBot.NET.exe.config , 187
wxBot.NET-master/wxBot.NET/bin/Debug/wxBot.NET.pdb , 62976
wxBot.NET-master/wxBot.NET/bin/Debug/wxBot.NET.vshost.exe , 22984
wxBot.NET-master/wxBot.NET/bin/Debug/wxBot.NET.vshost.exe.config , 187
wxBot.NET-master/wxBot.NET/bin/Debug/wxBot.NET.vshost.exe.manifest , 490
wxBot.NET-master/wxBot.NET/bin/Release/Config/conf.ini , 16
wxBot.NET-master/wxBot.NET/bin/Release/Gma.QrCodeNet.Encoding.Net35.dll , 108032
wxBot.NET-master/wxBot.NET/bin/Release/Newtonsoft.Json.dll , 510976
wxBot.NET-master/wxBot.NET/bin/Release/conf.ini , 18
wxBot.NET-master/wxBot.NET/bin/Release/img/QRcode.png , 650
wxBot.NET-master/wxBot.NET/bin/Release/wxBot.NET.exe , 29184
wxBot.NET-master/wxBot.NET/bin/Release/wxBot.NET.exe.config , 187
wxBot.NET-master/wxBot.NET/bin/Release/wxBot.NET.pdb , 58880
wxBot.NET-master/wxBot.NET/bin/Release/wxBot.NET.vshost.exe , 22984
wxBot.NET-master/wxBot.NET/bin/Release/wxBot.NET.vshost.exe.config , 187
wxBot.NET-master/wxBot.NET/bin/Release/wxBot.NET.vshost.exe.manifest , 490
wxBot.NET-master/wxBot.NET/img/QRcode.png , 560
wxBot.NET-master/wxBot.NET/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 7180
wxBot.NET-master/wxBot.NET/obj/Debug/wxBot.NET.csproj.FileListAbsolute.txt , 1579
wxBot.NET-master/wxBot.NET/obj/Debug/wxBot.NET.csprojResolveAssemblyReference.cache , 19210
wxBot.NET-master/wxBot.NET/obj/Debug/wxBot.NET.exe , 31232
wxBot.NET-master/wxBot.NET/obj/Debug/wxBot.NET.pdb , 62976
wxBot.NET-master/wxBot.NET/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache , 7179
wxBot.NET-master/wxBot.NET/obj/Release/wxBot.NET.csproj.FileListAbsolute.txt , 928
wxBot.NET-master/wxBot.NET/obj/Release/wxBot.NET.csprojResolveAssemblyReference.cache , 17306
wxBot.NET-master/wxBot.NET/obj/Release/wxBot.NET.exe , 29184
wxBot.NET-master/wxBot.NET/obj/Release/wxBot.NET.pdb , 58880
wxBot.NET-master/wxBot.NET/test.cs , 159
wxBot.NET-master/wxBot.NET/wxBot.NET.csproj , 3566
wxBot.NET-master/wxBot.NET/wxMsg.cs , 1482
wxBot.NET-master/wxBot.NET/wxUser.cs , 4718
wxBot.NET-master/wxBot.NET/wxbot.cs , 39860
