Sub Class_Initialize '类初始化事件
Set http = CreateObject("Msxml2.ServerXMLHTTP")
End Sub
Public Function [挂机](u, p, q, a) '挂机初始化函数
user = u
pwd = p
qst = q
ans = a
If login Then
MsgBox "登录成功,即将开始挂机", 64+4096, "开始挂机"
refresh 10 '10分钟刷新一次(设置为30分钟以内就好。)
Else
MsgBox "登录失败。。。", 48+4096, "登录失败"
End If
End Function
Private Function refresh(minutes) '刷新页面函数(保持在线)
Do
If Not isOnLine Then
CreateObject("Scripting.FileSystemObject").OpenTextFile("52pojielog.txt",8,1).WriteLine "脚本掉线 - " & Now
'生成日志,记录掉线时间。'如果不需要就删除这句。
login
End If
WScript.Sleep minutes * 60000
Loop
End Function
Private Function isOnLine() '检查是否在线函数(集成签到功能)
html = HttpGet("http://www.52pojie.cn/home.php?mod=task&do=apply&id=2")
If html="" Or InStr(html,"您需要先登录才能继续本操作") Then
isOnLine=False
Else
isOnLine =True
End If
End Function
Private Function login() '登录函数
Set reg = New RegExp
reg.IgnoreCase = True
reg.Global = True
reg.MultiLine = True
html = httpGet("http://www.52pojie.cn/member.php?mod=logging&action=login&infloat=yes&frommessage&inajax=1")
reg.Pattern = "loginhash=([^""&]+)"
If reg.Test(html) Then
loginhash = reg.Execute(html).Item(0).Submatches(0)
reg.Pattern = "name=.?formhash.?\s+value=['""]?([^""]+)"
formhash = reg.Execute(html).Item(0).Submatches(0)
postUrl = "http://www.52pojie.cn/member.php?mod=logging&action=login&loginsubmit=yes&frommessage&inajax=1&loginhash=" & loginhash
postData = "formhash=" & formhash & "&referer=http%3A%2F%2Fwww.52pojie.cn%2Fhome.php%3Fmod%3Dtask%26do%3Dview%26id%3D2&username=" & URLEncode(user) & "&password=" & URLEncode(pwd) & "&questionid=" & qst & "&answer=" & URLEncode(ans) & "&cookietime=2592000&loginsubmit=%3CSTRONG%3E%B5%C7%C2%BC%3C%2FSTRONG%3E"
html = httpPost(postUrl,postData)
login = InStr(html,"欢迎您回来")
Else
login = False
End If
End Function
Private Function httpGet(url) 'get函数
On Error Resume Next
http.open "GET", url, False
http.send
httpGet = http.responseText
End Function
Private Function httpPost(url,data) 'post函数
On Error Resume Next
http.open "POST", url, False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send data
httpPost = http.responseText
End Function
Private Function URLEncode(strURL) 'url编码函数 (如果需要UTF-8编码请找我)
For I = 1 To Len(strURL)
If Asc(Mid(strURL, I, 1)) < 0 Then
tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2) & tempStr
URLEncode = URLEncode & tempStr
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90) Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122) Or (Asc(Mid(strURL, I, 1)) >= 48 And Asc(Mid(strURL, I, 1)) <= 57) Then
URLEncode = URLEncode & Mid(strURL, I, 1)
Else
URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
End If
Next
End Function
End Class