PHPackages                             easydowork/yii2-rotate-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. easydowork/yii2-rotate-captcha

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

easydowork/yii2-rotate-captcha
==============================

基于isszz/rotate-captcha组件开发yii2图片旋转验证码

v1.0(4y ago)610MITPHPPHP &gt;=7.0

Since Feb 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/easydowork/yii2-rotate-captcha)[ Packagist](https://packagist.org/packages/easydowork/yii2-rotate-captcha)[ RSS](/packages/easydowork-yii2-rotate-captcha/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

yii2图片旋转验证码
-----------

[](#yii2图片旋转验证码)

- 简介
    基于 修改的图片旋转验证码.
- 流程说明
    1. 表单提交时js添加`beforeSubmit`事件,判断是有验证码校验值
    2. 弹窗旋转图片验证码,进行检验,若不成功重新旋转图片.
    3. 校验成功后台返回value,赋值给表单的captcha隐藏输入框,js自动提交表单.
- 使用说明

```
//与yii\captcha\Captcha类似,配置不同
//例:SiteController中behaviors与actions方法配置
public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'actions' => ['captcha'],//允许访问
                    'allow' => true,
                ],
            ],
        ],

    ];
}
public function actions()
{
    return [
        'captcha' => [
            'class' => 'easydowork\rotateCaptcha\CaptchaAction',
            'captchaOption' => [
                'imagePath' => '',//验证码图片库目录
                'cacheImagePath' => '',//旋转后验证码缓存目录
                'cacheHandel' => '',//缓存类继承yii\caching\Cache
                'cacheExpire' => 60,//验证码token过期时间
                'salt' => '',//加密字符串参数 默认为当前文件地址
                'size' => 350,//生成图片大小 px
                'earea' => 10,//验证图片时允许旋转角度的误差值
                'imageHandle'=>'gd',//推荐使用gd库,个人测试imagick时在windows和linux上生成的图片不一致,有能力的欢迎pr.
                'imageHandleConfig' => [ //生成验证码的参数
                    'quality' => 80,//图片质量
                    'bgcolor' => '#fff', // 底色
                ],
                'callbackFunc' => [ //一些回调函数 参数可看代码 非必填
                    'cacheKey' => function(){},//token缓存key
                    'cacheValue' => function(){},//token缓存value
                    'check' => function(){},//验证token
                    'generateValue' => function(){},//图片验证码通过后返回的value
                    'validateValue' => function(){},//校验value
                ],
            ]
        ],
    ];
}
//例:LoginForm中rules方法配置
public function rules()
{
    return [
        ['captcha', 'easydowork\rotateCaptcha\CaptchaValidator','captchaAction'=>'site/captcha','message'=>'验证码不正确！'],
    ];
}
//view 视图中使用
