[ 'class' => 'easydowork\rotateCaptcha\CaptchaAction', 'captchaOption' => [ 'imagePath' => BASE_PATH.'web'.DIRECTORY_SEPARATOR.'upload'.DIRECTORY_SEPARATOR.'captcha'.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR,//验证码图片库目录 'cacheImagePath' => BASE_PATH.'web'.DIRECTORY_SEPARATOR.'upload'.DIRECTORY_SEPARATOR.'captcha'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR,//旋转后验证码缓存目录 'cacheHandel' => '',//缓存类继承yii\caching\Cache 'cacheExpire' => 60,//验证码token过期时间 'salt' => Yii::$app->params['authKey'],//加密字符串参数 默认为当前文件地址 'size' => 350,//生成图片大小 px 'earea' => 10,//验证图片时允许旋转角度的误差值 'imageHandle'=>'gd',//推荐使用gd库,个人测试imagick时在windows和linux上生成的图片不一致,有能力的欢迎pr. 'imageHandleConfig' => [ //生成验证码的参数 'quality' => 80,//图片质量 'bgcolor' => '#fff', // 底色 ], ] ], ]; } public function actionIndex() { if((defined('IN_ADMIN')&&IN_ADMIN==true))//如果是后台入口文件,跳转到后台首页 { $this->redirect(APP_URL.'admin/default/index'); } } //生成图形验证码 public function actionImgcode() { if(isset($_GET['getcode'])&&$_GET['getcode']==1) { $result = array('error'=>0,'msg'=>'','data'=>['scode'=>generatePwd(Session::getInitCls()->get(Yii::$app->params['capcha']))]); echo_json($result); } else { ob_end_clean(); $_vc = new Capcha();//实例化一个对象 if(isset($_GET['width']))$_vc->width = intval($_GET['width']); if(isset($_GET['height']))$_vc->height = intval($_GET['height']); $_vc->doimg(); Session::getInitCls()->set(Yii::$app->params['capcha'],$_vc->getCode()); Session::getInitCls()->set(Yii::$app->params['capchaTime'],TIMESTAMP); exit; } } //生成缩略图 public function actionMakethumb() { $get = Yii::$app->request->get(); $cut = isset($get['cut'])?intval($get['cut']):0; if($get['width']==$get['height'])$defaultType=1;//正方形 if($get['width']>$get['height'])$defaultType=2;//宽屏 if($get['width']<$get['height'])$defaultType=3;//竖屏 $dstrootdir = THUMB_PATH.get_date(TIMESTAMP,'Ymd').DIRECTORY_SEPARATOR; if($get['hash']=='noavatar'||$get['hash']=='noimage') { $imageconfig = \app\modules\admin\models\Config::find()->where("name='imageconfig'")->one(); $imageconfig = string2array($imageconfig->value); //默认缺省图 $defaultImg = $imageconfig['noimage'.$defaultType]; //默认缺省头像 $defaultAvatar = $imageconfig['noavatar']; if(empty($defaultImg)||empty($defaultAvatar)) { exit('请设置缺省图和缺省头像(设置入口:后台 > 系统设置 > 基础设置)'); } $srcimg = $get['hash']=='noimage'?getFileUrl($defaultImg):getFileUrl($defaultAvatar); $dstimg = $dstrootdir.intval($get['width']).'_'.intval($get['height']).'_'.md5($srcimg).'.jpg'; if(!file_exists($dstimg)) { $resize = new \app\common\components\ResizeImage($srcimg, intval($get['width']), intval($get['height']), md5($srcimg),0,1,$dstrootdir); $dstimg = $resize->dstimg; } } else { $dstimg = $dstrootdir.intval($get['width']).'_'.intval($get['height']).'_'.$get['hash'].'.jpg'; if(!file_exists($dstimg)) { $img = Attachment::find()->where("hash='".$get['hash']."'")->limit(1)->one(); if (!empty($img)){ $srcimg =getFileUrl($img->file_path,Yii::$app->params['oss']['OPEN_INTERNAL']); $resize = new \app\common\components\ResizeImage($srcimg, intval($get['width']), intval($get['height']), $get['hash'], $cut,1,$dstrootdir); $dstimg = $resize->dstimg; } } } ob_end_clean(); header('Content-type: image/jpeg'); echo file_get_contents($dstimg); exit(); } //webUploader上传 public function actionUpload() { try { Yii::$app->response->format = Response::FORMAT_JSON; $model = new Upload(); $info = $model->upImage(); if ($info && is_array($info)) { return $info; } else { return ['code' => 1, 'msg' => 'error']; } } catch (\Exception $e) { return ['code' => 1, 'msg' => $e->getMessage()]; } } }