CommonController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. class CommonController extends Controller
  3. {
  4. /**
  5. * 检查手机验证码
  6. */
  7. public function actionCheckverify()
  8. {
  9. $input_code = isset($_POST['code']) ? addslashes(trim($_POST['code'])) : '';
  10. $result = CheckVerifyCode($input_code);
  11. echo json_encode($result);
  12. exit;
  13. }
  14. /**
  15. * 输出验证码
  16. */
  17. public function actionGetcaptcha()
  18. {
  19. $captchaModel = new LewaimaiVerifyCode();
  20. $captchaModel->doimg();
  21. Yii::app()->session['lewaimai_captcha'] = $captchaModel->getCode();
  22. exit;
  23. }
  24. /**
  25. * gt滑动验证初始化
  26. */
  27. public function actionStartcaptcha()
  28. {
  29. /**
  30. * 使用Get的方式返回:challenge和capthca_id 此方式以实现前后端完全分离的开发模式 专门实现failback
  31. * @author Tanxu
  32. */
  33. //error_reporting(0);
  34. require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/lib/class.geetestlib.php';
  35. require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/config/config.php';
  36. $GtSdk = new GeetestLib(CAPTCHA_ID, PRIVATE_KEY);
  37. $user_id = "test";
  38. $status = $GtSdk->pre_process($user_id);
  39. $_SESSION['gtserver'] = $status;
  40. $_SESSION['user_id'] = $user_id;
  41. echo $GtSdk->get_response_str();
  42. exit();
  43. }
  44. /**
  45. * gt滑动验证
  46. */
  47. public function actionVerifycaptcha()
  48. {
  49. require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/lib/class.geetestlib.php';
  50. require_once Yii::app()->getBasePath() . '/../protected/extensions/gt-php-sdk/config/config.php';
  51. $GtSdk = new GeetestLib(CAPTCHA_ID, PRIVATE_KEY);
  52. $user_id = $_SESSION['user_id'];
  53. if ($_SESSION['gtserver'] == 1) { //服务器正常
  54. $result = $GtSdk->success_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'], $user_id);
  55. if ($result) {
  56. echo '{"status":"success"}';
  57. } else{
  58. echo '{"status":"fail"}';
  59. }
  60. }else{ //服务器宕机,走failback模式
  61. if ($GtSdk->fail_validate($_POST['geetest_challenge'],$_POST['geetest_validate'],$_POST['geetest_seccode'])) {
  62. echo '{"status":"success"}';
  63. }else{
  64. echo '{"status":"fail"}';
  65. }
  66. }
  67. }
  68. /**
  69. * ajax提交图片temp临时存放
  70. */
  71. public function actionUploadtemp(){
  72. $type = strtolower($_FILES['surface']['type']);
  73. $size = $_FILES['surface']['size'];
  74. $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000';
  75. $imagetype = isset($_POST['type'])?$_POST['type']:'all';
  76. if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) {
  77. if($size > $maxsize){
  78. echo 'size';//图片容量超过200K
  79. }else{
  80. if(stristr($type, 'png')) {
  81. $extention = '.png';
  82. }else{
  83. $extention = '.jpg';
  84. }
  85. $temp_words = LewaimaiString::create_noncestr(32);//随机图片名
  86. $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/';
  87. if(!is_dir($temp_url)){
  88. mkdir($temp_url,0755,true);
  89. }
  90. $temp_name = $temp_url.$temp_words.$extention;
  91. $time = LewaimaiString:: GetOutTradeNo();
  92. if(copy($_FILES['surface']['tmp_name'], $temp_name)){
  93. chmod($temp_name,0755);
  94. $cdn_url = getUpyunUploadPath();
  95. $fileName = $temp_words . $extention;
  96. $surfaceimg = $cdn_url.$fileName;
  97. LewaimaiImageUpload('./'.$temp_name,$surfaceimg);
  98. echo $surfaceimg;
  99. //清除本地文件
  100. LewaimaiUtility::clearTempimages();
  101. }else{
  102. echo 'error';//出错
  103. }
  104. }
  105. }else{
  106. echo 'suffix';//格式不对
  107. }
  108. exit;
  109. }
  110. public function actionCropImg()
  111. {
  112. $type = strtolower($_FILES['surface']['type']);
  113. $size = $_FILES['surface']['size'];
  114. $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000';
  115. $imagetype = isset($_POST['type'])?$_POST['type']:'all';
  116. if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) {
  117. if($size > $maxsize){
  118. echo 'size';//图片容量超过200K
  119. }else{
  120. if(stristr($type, 'png')) {
  121. $extention = '.png';
  122. }else{
  123. $extention = '.jpg';
  124. }
  125. $temp_words = LewaimaiString::create_noncestr(32);//随机图片名
  126. $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/';
  127. if(!is_dir($temp_url)){
  128. mkdir($temp_url,0755,true);
  129. }
  130. $temp_name = $temp_url.$temp_words.$extention;
  131. $time = LewaimaiString:: GetOutTradeNo();
  132. $file = $_FILES['surface']['tmp_name'];
  133. if(isset($_POST['avatar_src']) && isset($_POST['avatar_data'])) {
  134. require_once 'CropImage.php';
  135. $crop = new CropImage($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['surface']);
  136. $file = $crop->getResult();
  137. }
  138. if(copy($file, $temp_name)){
  139. chmod($temp_name,0755);
  140. $cdn_url = getUpyunUploadPath();
  141. $fileName = $temp_words . $extention;
  142. $surfaceimg = $cdn_url.$fileName;
  143. LewaimaiImageUpload('./'.$temp_name,$surfaceimg);
  144. echo $surfaceimg;
  145. //清除本地文件
  146. LewaimaiUtility::clearTempimages();
  147. }else{
  148. echo 'error';//出错
  149. }
  150. }
  151. }else{
  152. echo 'suffix';//格式不对
  153. }
  154. exit;
  155. }
  156. }