瀏覽代碼

Merge branch 'test' of https://git.oschina.net/yiguanjia/php into test

Charlie 8 年之前
父節點
當前提交
4b75f244fb

+ 17 - 0
www/protected/controllers/UeditorUploaderController.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: PHP
+ * Date: 2016/10/10
+ * Time: 13:47
+ */
+class UeditorUploaderController extends AdminController {
+
+    /**
+     * Ueditor上传接口
+     */
+    public function actionUeditorUploader() {
+        $uploader = new UeditorUploader();
+        $uploader->handleAction()->printResult();
+    }
+}

+ 1 - 11
www/protected/modules/common/controllers/ActivityController.php

@@ -24,20 +24,16 @@ class ActivityController extends O2oBaseController  {
         if($code && $state){
         if($code && $state){
             $accessInfo = CommonWeixin::getAccessInfo($code);
             $accessInfo = CommonWeixin::getAccessInfo($code);
             $userId = '';
             $userId = '';
-            echo "1";exit;
             if (!isset($accessInfo['errcode']) && $state == 'yiguanjia') {
             if (!isset($accessInfo['errcode']) && $state == 'yiguanjia') {
-                echo "2";
                 $appToken = md5(substr($accessInfo['openid'],2));
                 $appToken = md5(substr($accessInfo['openid'],2));
                 //微信校验通过,登录(注册),分发token
                 //微信校验通过,登录(注册),分发token
                 $userInfo = CommonWeixin::getUserInfo($accessInfo['access_token'], $accessInfo['openid']);
                 $userInfo = CommonWeixin::getUserInfo($accessInfo['access_token'], $accessInfo['openid']);
                 if (!isset($accessInfo['errcode'])) {
                 if (!isset($accessInfo['errcode'])) {
-                    echo "3";
                     //检查是否有注册,没有就注册
                     //检查是否有注册,没有就注册
                     $criteria = new EMongoCriteria();
                     $criteria = new EMongoCriteria();
                     $criteria->unionid('==', $accessInfo['unionid']);
                     $criteria->unionid('==', $accessInfo['unionid']);
                     $user = RUser::model()->find($criteria);
                     $user = RUser::model()->find($criteria);
                     if ($user) {
                     if ($user) {
-                        echo "4";
                         $userId = $user->_id;
                         $userId = $user->_id;
                         if(!isset($user->wx_pub_openid) || empty($user->wx_pub_openid)){
                         if(!isset($user->wx_pub_openid) || empty($user->wx_pub_openid)){
                             $user->wx_pub_openid = $accessInfo['openid'];
                             $user->wx_pub_openid = $accessInfo['openid'];
@@ -45,7 +41,6 @@ class ActivityController extends O2oBaseController  {
                             $user->update(array('wx_pub_openid','wx_have_follow'),true);
                             $user->update(array('wx_pub_openid','wx_have_follow'),true);
                         }
                         }
                     }else{
                     }else{
-                        echo "5";
                         $userAr  = new RUser();
                         $userAr  = new RUser();
                         $userAr->user_name = $userInfo['nickname'];
                         $userAr->user_name = $userInfo['nickname'];
                         $userAr->avatar = $userInfo['headimgurl'];
                         $userAr->avatar = $userInfo['headimgurl'];
@@ -65,7 +60,6 @@ class ActivityController extends O2oBaseController  {
 
 
                         $result = $userAr->save();
                         $result = $userAr->save();
                         if($result){
                         if($result){
-                            echo "6";
                             //异步同步微信头像到七牛
                             //异步同步微信头像到七牛
                             if (!empty($userAr->unionid) && (strpos($userAr->avatar, 'qiniu') === false)) {
                             if (!empty($userAr->unionid) && (strpos($userAr->avatar, 'qiniu') === false)) {
                                 $list = new ARedisList('after_user_reg');
                                 $list = new ARedisList('after_user_reg');
@@ -78,13 +72,12 @@ class ActivityController extends O2oBaseController  {
                         }
                         }
                     }
                     }
                     //用户注册后,发放代金券
                     //用户注册后,发放代金券
-                    echo "7";
+
                     $coupon_id =new MongoId($coupon_id);
                     $coupon_id =new MongoId($coupon_id);
                     $start_time = time();                 //发放优惠券可用开始时间
                     $start_time = time();                 //发放优惠券可用开始时间
                     $end_time = $start_time + 86400*30;   //发放优惠券过期时间
                     $end_time = $start_time + 86400*30;   //发放优惠券过期时间
                     if (CommonFn::isMongoId($coupon_id)) {
                     if (CommonFn::isMongoId($coupon_id)) {
                         if (CommonFn::isMongoId($user->_id)) {
                         if (CommonFn::isMongoId($user->_id)) {
-                            echo "8";
                             Service::factory('CouponService')->giveCoupon($user->_id, $coupon_id, $start_time, $end_time);//发放代金券
                             Service::factory('CouponService')->giveCoupon($user->_id, $coupon_id, $start_time, $end_time);//发放代金券
                         }
                         }
                     }
                     }
@@ -96,7 +89,6 @@ class ActivityController extends O2oBaseController  {
         }
         }
 
 
         if($home_page){
         if($home_page){
-            echo "9";exit;
             $this->renderpartial('//o2o/web/index', array(
             $this->renderpartial('//o2o/web/index', array(
                 'version' => '2015111601',
                 'version' => '2015111601',
                 'debug' => 'false',
                 'debug' => 'false',
@@ -138,8 +130,6 @@ class ActivityController extends O2oBaseController  {
         }
         }
         $scope = 'snsapi_userinfo';
         $scope = 'snsapi_userinfo';
         $state = 'yiguanjia';
         $state = 'yiguanjia';
-        echo "1";
-        var_dump($redirectURI);exit;
         $codeURI = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $wxConfig['appId'] . '&redirect_uri=' . urlencode($redirectURI) . '&response_type=code&scope=' . $scope . '&state=' . $state . '#wechat_redirect';
         $codeURI = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $wxConfig['appId'] . '&redirect_uri=' . urlencode($redirectURI) . '&response_type=code&scope=' . $scope . '&state=' . $state . '#wechat_redirect';
 
 
         $this->renderpartial('wxIndex', array(
         $this->renderpartial('wxIndex', array(

+ 1 - 1
www/protected/modules/common/views/activity/getCoupon.php

@@ -73,7 +73,7 @@
         }
         }
         var debug = true;
         var debug = true;
 
 
-        alert(location.href);
+
         var main = '<?php echo Yii::app()->request->baseUrl;?>/webapp/o2o/dist/js/main.js?v=20160960804';
         var main = '<?php echo Yii::app()->request->baseUrl;?>/webapp/o2o/dist/js/main.js?v=20160960804';
         if (debug) {
         if (debug) {
             main = '<?php echo Yii::app()->request->baseUrl;?>/webapp/o2o/js/main.js?v=' + (new Date()).getTime();
             main = '<?php echo Yii::app()->request->baseUrl;?>/webapp/o2o/js/main.js?v=' + (new Date()).getTime();

+ 154 - 0
www/protected/vendors/ueditor/UeditorUploader.php

@@ -0,0 +1,154 @@
+<?php
+/**
+ * UEditor上传
+ */
+$path = Yii::getPathOfAlias('application')."/vendors/qiniu";
+require_once($path."/rs.php");
+require_once($path."/io.php");
+require_once($path."/http.php");
+require_once($path."/auth_digest.php");
+
+class UeditorUploader {
+
+    public  $action;
+    private $config;
+    private $result;
+
+    /**
+     * 构造方法
+     * 从ueditor/config.json获取ueditor上传配置
+     */
+    public function __construct() {
+        // ueditor配置
+        $this->config = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(dirname(__FILE__)."/ueditor_config.json")), true);
+        $this->action = isset($_GET['action']) ? htmlspecialchars($_GET['action']) : 'config';
+    }
+
+    /**
+     * 处理控制器请求
+     */
+    public function handleAction() {
+        switch ($this->action) {
+            /* 获取配置 */
+            case 'config':
+                $this->result = json_encode($this->config);
+                break;
+            /* 上传图片 */
+            case 'uploadimage':
+                /* 上传涂鸦 */
+            case 'uploadscrawl':
+                /* 上传视频 */
+            case 'uploadvideo':
+                /* 上传文件 */
+            case 'uploadfile':
+                $this->result = $this->actionUpload();
+                break;
+
+            // /* 列出图片 */
+            // case 'listimage':
+            //     $this->result = $this->actionList();
+            //     break;
+            // /* 列出文件 */
+            // case 'listfile':
+            //     $this->result = $this->actionList();
+            //     break;
+            // /* 抓取远程文件 */
+            // case 'catchimage':
+            //     $this->result = $this->actionCrawler();
+            //     break;
+            default:
+                $this->result = json_encode([
+                    'state' => '请求地址出错'
+                ]);
+                break;
+        }
+        return $this;
+    }
+
+    /**
+     * 向前端打印结果
+     */
+    public function printResult() {
+        if (isset($_GET['callback'])) {
+            $callback = $_GET['callback'];
+            if (preg_match("/^[\w_]+$/", $callback)) {
+                echo htmlspecialchars($callback) . '(' . $this->result . ')';
+            } else {
+                echo json_encode([
+                    'state'=> 'callback参数不合法'
+                ]);
+            }
+        } else {
+            echo $this->result;
+        }
+    }
+
+    public function actionUpload() {
+        switch ($this->action) {
+            case 'uploadimage':
+                $fieldName = $this->config['imageFieldName'];
+                $bucket = Yii::app()->params['qiniuConfig']['pics'];
+                break;
+            case 'uploadvideo':
+                $fieldName = $this->config['videoFieldName'];
+                $bucket = Yii::app()->params['qiniuConfig']['video'];
+                break;
+            default:
+                $fieldName = $this->config['fileFieldName'];
+                $bucket = 'null';
+                break;
+        }
+
+        if ($bucket == 'null') {
+            return json_encode(['state' => '上传文件出错']);
+        }
+
+        $file = $_FILES[$fieldName];
+        // 命名
+        $saveName = md5(time() + rand());
+        $saveKey = $saveName.'.'.pathinfo($file['name'], PATHINFO_EXTENSION);
+        // 临时存储路径
+        $savePath = dirname($file['tmp_name']).'/'.$saveKey;
+        if (!file_exists($savePath)) {
+            move_uploaded_file($file['tmp_name'], $savePath);
+        }
+
+        $status = $this->uploadToQiniu($savePath, $saveKey, $bucket);
+        if (!$status) {
+            unlink($savePath);
+            return json_encode(['state' => '上传文件到七牛失败']);
+        } else {
+            unlink($savePath);
+            $url = 'http://'.$bucket.'.qiniudn.com/'.$saveKey;
+            $fileInfo = [
+                'state'    => 'SUCCESS',
+                'url'      => $url,
+                'title'    => $saveName,
+                'original' => $file['name'],
+                'type'     => $file['type'],
+                'size'     => $file['size'],
+            ];
+
+            return json_encode($fileInfo);
+        }
+    }
+
+    public function uploadToQiniu($file, $upname, $bucket) {
+        $qiniu_config = Yii::app()->params['qiniuConfig'];
+        $accessKey = $qiniu_config['ak'];
+        $secretKey = $qiniu_config['sk'];
+        Qiniu_SetKeys($accessKey, $secretKey);
+        $putPolicy = new Qiniu_RS_PutPolicy($bucket);
+        $upToken = $putPolicy->Token(null);
+        $putExtra = new Qiniu_PutExtra();
+        $putExtra->Crc32 = 1;
+        list($ret,$err) = Qiniu_PutFile($upToken,$upname,$file,$putExtra);
+        if ($err !== null) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+}
+?>

+ 1 - 1
www/protected/views/staticSource/index.php

@@ -42,7 +42,7 @@ $(function(){
 
 
     // 初始化UEditor
     // 初始化UEditor
     UE.getEditor('ueditor_container', {
     UE.getEditor('ueditor_container', {
-        serverUrl: '/index.php?r=deal/kennel/ueditorUploader',
+        serverUrl: '/index.php?r=ueditorUploader/UeditorUploader',
         toolbars: [
         toolbars: [
             [
             [
                 'anchor', //锚点
                 'anchor', //锚点