基本情况:中国联通官网的验证码,固定位置,固定大小,无干扰
获取地址:http://ecard.10010.com/getImage.jsp
基本思路是为每个数字建模,然后逐像素点对比,当匹配度最高的数字即为结果,如果识别错误则再次获取后识别。
程序采用WebBrowser1+自动填表+自动点击的方式完成,部分代码如下:
以上是登陆到联通自动充值页面,填写手机号码,充值金额和验证码之后,生成订单的一个过程。
之后是订单确认,然后转网银支付。
验证码识别部分:
@H_502_40@Private Sub GetCode() '识别========================= Command1.Caption = "正在识别验证码..." t1 = "" t2 = "" t3 = "" t4 = "" Dim ty(9) ty(0) = "00001111111100011111111111011100000000111000000000011000000000011100000000001110000000111101111111111100" ty(1) = "00000000000010000000000001010000000011111111111111111011111111001110000000000111000000000010000000000000" ty(2) = "00000000001110100000011101110000001100110000001110011000001100001100000110000111111110000011111110000000" ty(3) = "00000000000110100001000001110000100000111000010000011000001000001100001111111111111101111101111100000000" ty(4) = "00000001110000000001111000000001101100000000110110000000110011000001110001111111111111111111111111111000" ty(5) = "00111100000111111110000001110001000000110000100000111000011000110100000111110010000011111001000000111000" ty(6) = "00001111111100011001000001011101100000101110110000011100010000001100001000001110000110001101000001111110" ty(7) = "00000000000011000000000111100000000011110000001111101000001111000100001100000010111100000001111100000000" ty(8) = "00111001111110111110111011110001110000110000010000011000001000001100001110011110000111001111111111111110" ty(9) = "00001100000110111111000001011100110000111000001000011000000100011100000111111010000011111101111111011100" '111111111 Dim flag(10) For i = 4 To 11 For j = 8 To 20 If Picture1.Point(i,j) < &H200000 Then t1 = t1 & "1" Else t1 = t1 & "0" End If Next j Next i Text1.Tag = 0 For M = 0 To 9 For N = 0 To Len(t1) If Mid(t1,N + 1,1) = Mid(ty(M),1) Then flag(M) = flag(M) + 1 End If Next N If flag(M) > CSng(Text1.Tag) Then Text1.Tag = flag(M) ty1 = M End If Next M '2222222222222s For i = 14 To 21 For j = 8 To 20 If Picture1.Point(i,j) < &H200000 Then t2 = t2 & "1" Else t2 = t2 & "0" End If Next j Next i Text1.Tag = 0 For M = 0 To 9 flag(M) = 0 For N = 0 To Len(t2) If Mid(t2,1) Then flag(M) = flag(M) + 1 End If Next N If flag(M) > CSng(Text1.Tag) Then Text1.Tag = flag(M) ty2 = M End If Next M '33333333333 For i = 24 To 31 For j = 8 To 20 If Picture1.Point(i,j) < &H200000 Then t3 = t3 & "1" Else t3 = t3 & "0" End If Next j Next i Text1.Tag = 0 For M = 0 To 9 flag(M) = 0 For N = 0 To Len(t3) If Mid(t3,1) Then flag(M) = flag(M) + 1 End If Next N If flag(M) > CSng(Text1.Tag) Then Text1.Tag = flag(M) ty3 = M End If Next M '444444 For i = 34 To 41 For j = 8 To 20 If Picture1.Point(i,j) < &H200000 Then t4 = t4 & "1" Else t4 = t4 & "0" End If Next j Next i Text1.Tag = 0 For M = 0 To 9 flag(M) = 0 For N = 0 To Len(t4) If Mid(t4,1) Then flag(M) = flag(M) + 1 End If Next N If flag(M) > CSng(Text1.Tag) Then Text1.Tag = flag(M) ty4 = M End If Next M Text1.Text = ty1 & ty2 & ty3 & ty4 End Sub
原文链接:https://www.f2er.com/vb/261654.html