doimg(); Yii::app()->session['lewaimai_captcha'] = $captchaModel->getCode(); exit; } /** * gt滑动验证初始化 */ public function actionStartcaptcha() { /** * 使用Get的方式返回:challenge和capthca_id 此方式以实现前后端完全分离的开发模式 专门实现failback * @author Tanxu */ //error_reporting(0); require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/lib/class.geetestlib.php'; require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/config/config.php'; $GtSdk = new GeetestLib(CAPTCHA_ID, PRIVATE_KEY); $user_id = "test"; $status = $GtSdk->pre_process($user_id); $_SESSION['gtserver'] = $status; $_SESSION['user_id'] = $user_id; echo $GtSdk->get_response_str(); exit(); } /** * gt滑动验证 */ public function actionVerifycaptcha() { require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/lib/class.geetestlib.php'; require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/config/config.php'; $GtSdk = new GeetestLib(CAPTCHA_ID, PRIVATE_KEY); $user_id = $_SESSION['user_id']; if ($_SESSION['gtserver'] == 1) { //服务器正常 $result = $GtSdk->success_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'], $user_id); if ($result) { echo '{"status":"success"}'; } else{ echo '{"status":"fail"}'; } }else{ //服务器宕机,走failback模式 if ($GtSdk->fail_validate($_POST['geetest_challenge'],$_POST['geetest_validate'],$_POST['geetest_seccode'])) { echo '{"status":"success"}'; }else{ echo '{"status":"fail"}'; } } } /** * ajax提交图片temp临时存放 */ public function actionUploadtemp(){ $type = strtolower($_FILES['surface']['type']); $size = $_FILES['surface']['size']; $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000'; $imagetype = isset($_POST['type'])?$_POST['type']:'all'; if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) { if($size > $maxsize){ echo 'size';//图片容量超过200K }else{ if(stristr($type, 'png')) { $extention = '.png'; }else{ $extention = '.jpg'; } $temp_words = LewaimaiString::create_noncestr(32);//随机图片名 $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/'; if(!is_dir($temp_url)){ mkdir($temp_url,0755,true); } $temp_name = $temp_url.$temp_words.$extention; $time = LewaimaiString:: GetOutTradeNo(); if(copy($_FILES['surface']['tmp_name'], $temp_name)){ chmod($temp_name,0755); $cdn_url = getUpyunUploadPath(); $fileName = $temp_words . $extention; $surfaceimg = $cdn_url.$fileName; LewaimaiImageUpload('./'.$temp_name,$surfaceimg); echo $surfaceimg; //清除本地文件 LewaimaiUtility::clearTempimages(); }else{ echo 'error';//出错 } } }else{ echo 'suffix';//格式不对 } exit; } public function actionCropImg() { $type = strtolower($_FILES['surface']['type']); $size = $_FILES['surface']['size']; $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000'; $imagetype = isset($_POST['type'])?$_POST['type']:'all'; if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) { if($size > $maxsize){ echo 'size';//图片容量超过200K }else{ if(stristr($type, 'png')) { $extention = '.png'; }else{ $extention = '.jpg'; } $temp_words = LewaimaiString::create_noncestr(32);//随机图片名 $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/'; if(!is_dir($temp_url)){ mkdir($temp_url,0755,true); } $temp_name = $temp_url.$temp_words.$extention; $time = LewaimaiString:: GetOutTradeNo(); $file = $_FILES['surface']['tmp_name']; if(isset($_POST['avatar_src']) && isset($_POST['avatar_data'])) { require_once 'CropImage.php'; $crop = new CropImage($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['surface']); $file = $crop->getResult(); } if(copy($file, $temp_name)){ chmod($temp_name,0755); $cdn_url = getUpyunUploadPath(); $fileName = $temp_words . $extention; $surfaceimg = $cdn_url.$fileName; LewaimaiImageUpload('./'.$temp_name,$surfaceimg); echo $surfaceimg; //清除本地文件 LewaimaiUtility::clearTempimages(); }else{ echo 'error';//出错 } } }else{ echo 'suffix';//格式不对 } exit; } }