1、申 请 I D:T584596
2、个人邮箱:584596597@qq.com
3、原创技术文章:实现自动签到获取论坛积分工具
需求背景:为了提高论坛活跃度,很多论坛下载附件需要支付论坛虚拟币。如果论坛开启了签到送虚拟币的功能,下载附件虚拟币不够时,我们可以通过设置计划任务每天签到获取论坛虚拟币。
支持范围:所有开启“每日签到”功能的 Discuz (2.x,3.x)论坛,可通过访问 http://论坛地址/plugin.php?id=dsu_paulsign:sign 检查论坛是否开启该插件
实现语言:C#
实现流程与代码:
1、通过账号密码模拟登录论坛
[C#] 纯文本查看 复制代码 RequestHandler handler = new RequestHandler(); //RequestHandler为请求数据包
handler.Url = txtUrl.Text + "member.php?mod=logging&action=login&loginsubmit=yes&loginhash=Lp6F5&inajax=1";
handler.CharsetSource = "Page";
handler.Charset = Encoding.GetEncoding(Request.GetPageCharset(txtUrl.Text));
handler.Method = "Post";
handler.Data = string.Format("username={0}&password={1}",txtUser.Text,txtPwd.Text);
2、保存登录信息
[C#] 纯文本查看 复制代码
CookieContainer cookies = new CookieContainer(); //登录信息保存容器
HttpWebResponse resp = Request.Execute(handler);
try {
cookies.Add(resp.Cookies);
}
catch { }
if (Regex.IsMatch(handler.GetHtml(resp), "登录失败", RegexOptions.IgnoreCase)) //检查论坛是否返回登录失败信息
{
MessageBox.Show("帐号或密码错误");
return;
}
3、发起签到请求
3.1、先取得签到数据需要的formhash
[C#] 纯文本查看 复制代码 handler.Url = txtUrl.Text + "plugin.php?id=dsu_paulsign:sign";
handler.Method = "Get";
handler.Cookies = cookies; //带上已登录的cookie信息
resp = Request.Execute(handler);
Match match = Regex.Match(handler.GetHtml(resp), @"formhash=(\w{8})", RegexOptions.IgnoreCase);
if (match.Groups.Count != 2)
{
MessageBox.Show("没有正确获取到formHash!");
return;
}
string formhash = match.Groups[1].Value;
3.2、如果取得成功,则开始签到
[C#] 纯文本查看 复制代码 handler.Url = txtUrl.Text + "plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=1&sign_as=1";
handler.Method = "Post";
handler.Data = string.Format("formhash={0}&qdxq=kx&qdmode=3", formhash);
resp = Request.Execute(handler);
string html = handler.GetHtml(resp);
if (Regex.IsMatch(html, "您今日已经签到,请明天再来"))
{
labMsg.Text = "您今日已经签到,请明天再来";
}
else {
labMsg.Text ="恭喜签到成功!";
}
4、获取积分情况
[C#] 纯文本查看 复制代码 handler.Url = txtUrl.Text + "home.php?mod=spacecp&ac=credit&showcredit=1&inajax=1&ajaxtarget=extcreditmenu_menu";
handler.Method = "Get";
handler.Cookies = cookies; //带上已登录的cookie信息
resp = Request.Execute(handler);
match = Regex.Match(handler.GetHtml(resp), @"(\d+)币", RegexOptions.IgnoreCase); //抓取用户信息内的虚拟币值
if (match.Groups.Count == 2)
{
string ygb = match.Groups[1].Value;
string msg = string.Format("您有 (论坛币{0})!",ygb);
//记录日志
if (File.Exists(Application.StartupPath + "/log.txt") == false) {
using (File.Create(Application.StartupPath + "/log.txt")) { }
}
using (StreamWriter sw = File.AppendText(Application.StartupPath + "/log.txt")) {
sw.WriteLine(string.Format("#{0}# {1}", DateTime.Now, msg));
}
labMsg.Text = msg;
}
5、软件截图
画面
日志
|