黑马程序员技术交流社区
标题:
使用opentieba自动签到
[打印本页]
作者:
aisini
时间:
2014-8-21 15:01
标题:
使用opentieba自动签到
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Opentieba;
namespace sersign
{
class SignWalker
{
public readonly BDUSS b;
public readonly kwf k;
public SignWalker(BDUSS b, baseBar bb)
{
this.b = b;
this.k = new kwf(bb.fid, bb.kw);
}
public void threadProc()
{
Program.log(b.getUsername() + " 开签" + k.kw);
try
{
// 错误最高重试次数:10
int tyacou = 10;
loope:
tyacou--;
try
{
// 签!
b.sign(k);
}
catch (TiebaField e)
{
if (e.error_code == 160002)
{
throw;
}
if (tyacou >= 0)
{
goto loope;
}
else
{
throw;
}
}
catch (System.Net.WebException)
{
if (tyacou >= 0)
{
goto loope;
}
else
{
throw;
}
}
Program.log(b.getUsername() + " 签"+k.kw+"成功。于" + DateTime.Now.ToLongTimeString());
}
catch (TiebaField e)
{
Program.log(b.getUsername() + " 签" + k.kw + "失败。" + e.error_code + ": " + e.error_msg + " 于" + DateTime.Now.ToLongTimeString());
}
catch (Exception e)
{
Program.log(b.getUsername() + " 签" + k.kw + "失败。" + e.ToString() + " 于" + DateTime.Now.ToLongTimeString());
}
Program.doneLeft--;
}
}
class Program
{
public static volatile int doneLeft = 0;
public static FileStream fslog;
static void Main(string[] args)
{
// 加载日志log文件
if (!File.Exists("sign.log"))
{
fslog = File.Create("sign.log");
}
else
{
fslog = File.Open("sign.log", FileMode.Open, FileAccess.ReadWrite);
fslog.Position = fslog.Length;
}
Program.log("==== " + DateTime.Now.ToLongDateString());
try
{
// 加载配置文件
FileStream reini = File.Open("userlist.json", FileMode.Open, FileAccess.Read);
byte[] confstrbyte = new byte[reini.Length];
reini.Read(confstrbyte, 0, (int)reini.Length);
reini.Close();
String jsonstr = Encoding.UTF8.GetString(confstrbyte);
JObject conf = JSON.parse(jsonstr);
JEnumerable<JToken> unpalist = conf["user_list"].Children();
// 登录用户
foreach (JToken t in unpalist)
{
try
{
// 登录
BDUSS bl = new BDUSS(t["name"].Value<String>(), t["passwd"].Value<String>(), "", "");
// 遍历喜欢吧
ListBarResult lbr = bl.listLike(1);
foreach (baseBar bb in lbr.likebars)
{
doneLeft++;
// 增加签到任务
new Thread(new SignWalker(bl, bb).threadProc).Start();
Thread.Sleep(120);
}
}
catch (TiebaField e)
{
Program.log(t["name"].Value<String>() + " " + e.error_code + ": " + e.error_msg + " 于" + DateTime.Now.ToLongTimeString());
}
catch (Exception e)
{
Program.log(t["name"].Value<String>() + " " + e.ToString() + " 于" + DateTime.Now.ToLongTimeString());
}
}
}
catch (Exception e)
{
Program.log(e.ToString());
}
while (doneLeft > 0)
{
Console.Write("还有" + doneLeft + "个...\n");
Thread.Sleep(500);
}
fslog.Close();
}
public static void log(String s)
{
byte[] pb = Encoding.UTF8.GetBytes(s + "\r\n");
lock (fslog)
{
fslog.Write(pb, 0, pb.Length);
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2