Ejemplo n.º 1
0
 /**
  * 控制器执行主逻辑函数
  * @param null $uri
  * @throws MException
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function invoke($uri = null)
 {
     // 解析控制器中对应操作名称
     $urlManager = new MUrlManager();
     $urlArray = $urlManager->parseActionFromUrl();
     if ($urlArray === false) {
         throw new MException(Yii::t('api', '{class} do not call an action', array('{class}' => get_class($this))));
     }
     $action = $urlArray["action"];
     $this->commonUri = $urlArray["uri"];
     self::$namespace = "api.{$action}";
     // 进行程序执行之前首先进行oauth用户身份信息验证
     // 排除指定動作可以匿名訪問
     $canAnonymous = false;
     if ($action == "info" || $action == "report") {
         $canAnonymous = true;
     }
     if ($action == "link") {
         $parts = explode("/", $this->commonUri);
         $subAction = $parts[2];
         if ($subAction == "selected") {
             $canAnonymous = true;
         }
     }
     if ($canAnonymous) {
         header('Access-Control-Allow-Origin: *');
         header('Access-Control-Allow-Methods: POST');
     }
     if (!$canAnonymous) {
         $filter = new MUserFilter();
         $filter->invoke($this->commonUri);
         // 过滤器,检查空间剩余
         $spaceFilter = new MActionFilter();
         $spaceFilter->action = $action;
         $spaceFilter->invoke($this->commonUri);
         // 修改在线用户状态
         $this->user = MUserManager::getInstance()->getCurrentUser();
         $this->device = MUserManager::getInstance()->getCurrentDevice();
         //更新设备在线状态
         MiniOnlineDevice::getInstance()->setOnlineDeviceValue($this->user["id"], $this->user["appId"], $this->device["id"]);
     }
     $this->{$action}();
 }
Ejemplo n.º 2
0
date_default_timezone_set("PRC");
defined('YII_DEBUG') or define('YII_DEBUG', false);
@ini_set('display_errors', '1');
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
// change the following paths if necessary
$config = dirname(__FILE__) . '/protected/config/main.php';
$yii = dirname(__FILE__) . '/yii/framework/yii.php';
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 8);
// 客户端请求
defined('CLIENT_REQUEST_API') or define('CLIENT_REQUEST_API', TRUE);
require_once $yii;
Yii::createWebApplication($config);
header('Access-Control-Allow-Origin: http://static.miniyun.cn');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Methods: GET');
MiniAppParam::getInstance()->load();
//初始化APP静态数据
MiniPlugin::getInstance()->load();
//加载插件
$routePath = MiniHttp::getParam("route", "");
if (empty($routePath)) {
    //老接口
    $meta = new MAPIController();
    //通过meta的控制器进行跳转处理逻辑
    $meta->invoke();
} else {
    //新接口
    $api = new APIController();
    $api->invoke();
}