黑客防线上的一篇文章,应该算是最简单的验证码了,学习了下。以下代码修改自源文章,稍微优化了下。
代码:
Option Explicit
Private P(3 To 11, 5 To 34) As BooleanPrivate Sub Command1_Click()
On Error Resume NextIf Inet1.StillExecuting Then
Inet1.Cancel
End IfDim picByte() As Byte
picByte = Inet1.OpenURL("http://3g.renren.com/randimg?post=_REQUESTFRIEND_88193bf7488cd4d0169d399541bdb4a7&rnd=1300194185024", icByteArray)Dim ntime, stime
stime = Now
While Inet1.StillExecuting
DoEvents
ntime = Now
If DateDiff("s", stime, ntime) > 3 Then MsgBox "验证码获取超时": Exit Sub
WendOpen App.Path & "\test.gif" For Binary As #1
Put #1, , picByte
Close #1Picture1.AutoSize = True
Picture1.ScaleMode = vbPixels
Picture1.Picture = LoadPicture(App.Path & "\test.gif")
End SubPrivate Sub Command2_Click()
On Error Resume NextDim i As Integer, j As Integer, s As String
Text1 = ""
For i = 3 To 11
For j = 5 To 34
P(i, j) = IIf(Picture1.Point(j, i) <> 0, True, False)
s = s & IIf(Picture1.Point(j, i) <> 0, "□", "■")
Next j
s = s & vbCrLf
Next i
Text1 = s
Me.Caption = "识别结果" & Very(5, 11) & Very(13, 19) & Very(21, 27) & Very(29, 34)
End SubPrivate Function Very(ByVal col1 As Integer, ByVal col2 As Integer) As Integer
Dim i As Integer, j As Integer
Dim yesCount As Integer, yesCount2 As Integer
For i = col1 To col2
If P(3, i) Then yesCount = yesCount + 1
NextSelect Case yesCount
Case 6
Very = 7
Case 1
Very = 4
Case 5
Very = 5
Case 2
For i = col1 To col2
If P(11, i) Then yesCount2 = yesCount2 + 1
Next
Select Case yesCount2
Case 2
Very = 0
Case 4
Very = 9
Case 5
Very = 1
End Select
Case 4
For i = col1 To col2
If P(7, i) Then yesCount2 = yesCount2 + 1
Next
Select Case yesCount2
Case 1
Very = 2
Case 2
Very = 3
Case 3
Very = 6
Case 4
Very = 8
End Select
End Select
End Function
已经有(4)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/program/745.html 欢迎订阅Eddy Blog。
简单吗?我怎么感觉也蛮复杂的啊 。。。看来我的能力有限啊
好多代码啊。。呵呵、、、
能写上几行注释么?看得有点不明白
是vb代码?