找回密码
 加入
搜索
查看: 11627|回复: 19

[原创] 发个乱七八糟验证码的生成代码

 火... [复制链接]
发表于 2010-12-16 02:49:17 | 显示全部楼层 |阅读模式
本帖最后由 netegg 于 2010-12-20 23:18 编辑

不一定有用,好玩而已
#include <GuiConstantsEx.au3>
#include <WinAPIEx.au3>
#include <GDIPlusex.au3>
#include <Array.au3>
_Main()

Func _Main()
    Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hFontCollection, $sFamilyName, $aFontFamilies, $hPointcolor, $str = ''
    Local $aFont = _arraycreate('webdings', 'Symbol', 'Marlett', 'Wingdings') ;定义几个图形字符的字形
        
    ; Create GUI
    $hGUI = GUICreate("GDI+", 640, 150)
    $hWnd = WinGetHandle("GDI+")
    GUISetState()

    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFontCollection = _GDIPlus_FontCollectionCreate()
    $aFontFamilies = _GDIPlus_FontCollectionGetFamilyList($hFontCollection)
    For $i = 1 To 10000
        $hPointcolor = _GDIPlus_BrushCreateSolid('0xFF' & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2)) ;设置干扰点颜色
        _GDIPlus_GraphicsFillEllipse($hGraphic, Random(0, 640, 1), Random(0, 150, 1), 3, 3, $hPointcolor) ;随机绘制干扰点(3x3的椭圆)
        If $i < 8 Then
            While 1
                $sFamilyName = _GDIPlus_FontFamilyGetFamilyName($aFontFamilies[Random(1, UBound($aFontFamilies) - 1, 1)]) ;随机选取字体族并获取族名(排除图形字符字形)
                If _ArraySearch($aFont, $sFamilyName) Then ExitLoop
            WEnd
            $hFamily = _GDIPlus_FontFamilyCreate($sFamilyName) ;创建基于名字的字体族
            $hBrush = _GDIPlus_BrushCreateSolid('0xFF' & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2)) ;随机设置画刷颜色
            $hFont = _GDIPlus_FontCreate($hFamily, Random(24, 50, 1), Random(0, 2, 1)) ;基于字体族以随机字形及字重创建字体
            $iX = 70 * ($i - 1) + Random(0, 70, 1) ;基于不同字符位置随机设置起始点的x坐标
            $tLayout = _GDIPlus_RectFCreate($iX, Random(0, 50, 1)) ;创建绘制字符的矩形
            $w = Random(0, 2) ;大小写开关
            Select
                Case $w > 1
                   $string = Chr(Random(65, 90, 1)) ;随机获取大写字母
                Case Else
                    $string = Chr(Random(97, 122, 1)) ;随机获取小写字母
            EndSelect
            $str &= $string
            $hImage = _GDIPlus_GraphicsDrawStringEx($hGraphic, $string, $hFont, $tLayout, $hFormat, $hBrush) ;绘制字符
            _GDIPlus_GraphicsRotateTransform($hImage, Random(0, 180, 1), Int(Random(0, 1) + 0.5)) ;随机旋转(好像有问题,转不了)
            If $i < 6 Then
                $hPen = _GDIPlus_PenCreate('0xFF' & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2) & StringRight(Hex(Random(0, 225, 1)), 2), Int(Random(2, 6, 1))) ;创建用于绘制干扰线的画笔(随机色及随机线宽)
                _GDIPlus_GraphicsDrawLine($hGraphic, Random(0, 640, 1), Random(0, 150, 1), Random(0, 640, 1), Random(0, 150, 1), $hPen) ;按随机起始坐标及随机结束坐标绘制直线
            EndIf
        EndIf
    Next
    MsgBox(0, 0, $str)
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()

EndFunc   ;==>_Main
发表于 2010-12-16 03:22:16 | 显示全部楼层
收藏了,研究研究
发表于 2010-12-16 08:42:07 | 显示全部楼层
收藏先 日后研究
发表于 2010-12-20 12:24:14 | 显示全部楼层
不错不错!收藏了
发表于 2011-1-1 12:20:54 | 显示全部楼层
很好的源码啊!支持一下!
发表于 2011-1-1 12:26:02 | 显示全部楼层
GDIPlusex.au3找不到啊
发表于 2011-1-25 15:14:55 | 显示全部楼层
看看
发表于 2011-6-29 10:37:47 | 显示全部楼层
GDIPlusex.au3找不到啊
 楼主| 发表于 2011-7-4 18:31:41 | 显示全部楼层
回复 8# qq123123

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-7-4 18:56:22 | 显示全部楼层

识别后退出有问题?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-7-4 20:03:51 | 显示全部楼层
本帖最后由 netegg 于 2011-7-4 20:04 编辑

回复 10# lpxx
那个可不是识别,只是生成,最后的那个消息框是用来看生成的东西的,不是识别出来的
另外,你图片上那个状态我这没出现过,不知道什么地方的问题
发表于 2011-7-4 22:08:51 | 显示全部楼层
回复  lpxx
那个可不是识别,只是生成,最后的那个消息框是用来看生成的东西的,不是识别出来的
另外,你图片 ...
netegg 发表于 2011-7-4 20:03


哦,是这样啊,谢谢,刚好最近学习到验证码,谢谢你的资料。
发表于 2011-7-31 01:44:58 | 显示全部楼层
看上来比较实用,当时不知道效果
发表于 2011-9-24 16:35:10 | 显示全部楼层
我怎么 运行出错
发表于 2011-9-27 16:57:24 | 显示全部楼层
#include <WinAPIEx.au3>

提示没有这个文件。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-26 08:17 , Processed in 0.082806 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表