Commit 8f6a9d34 authored by 杨培's avatar 杨培

管理员登录

parent 8a9b6ee2
...@@ -17,7 +17,7 @@ return [ ...@@ -17,7 +17,7 @@ return [
'csrfParam' => '_csrf-backend', 'csrfParam' => '_csrf-backend',
], ],
'user' => [ 'user' => [
'identityClass' => 'common\models\User', 'identityClass' => 'backend\models\User',
'enableAutoLogin' => true, 'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
], ],
......
...@@ -13,6 +13,7 @@ use common\libs\Utils; ...@@ -13,6 +13,7 @@ use common\libs\Utils;
use common\models\Classes; use common\models\Classes;
use common\models\User; use common\models\User;
use Yii; use Yii;
use yii\filters\AccessControl;
use yii\web\Controller; use yii\web\Controller;
class ClassesController extends Controller class ClassesController extends Controller
...@@ -20,6 +21,24 @@ class ClassesController extends Controller ...@@ -20,6 +21,24 @@ class ClassesController extends Controller
public $layout = 'back'; public $layout = 'back';
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
]
]
]
];
}
public function actionIndex() public function actionIndex()
{ {
$status = Yii::$app->request->get('status', Classes::STATUS_OK); $status = Yii::$app->request->get('status', Classes::STATUS_OK);
......
...@@ -17,6 +17,7 @@ use common\models\TranscodeQueue; ...@@ -17,6 +17,7 @@ use common\models\TranscodeQueue;
use common\models\User; use common\models\User;
use Yii; use Yii;
use yii\base\ExitException; use yii\base\ExitException;
use yii\filters\AccessControl;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
...@@ -25,6 +26,24 @@ class CourseController extends Controller ...@@ -25,6 +26,24 @@ class CourseController extends Controller
public $layout = 'back'; public $layout = 'back';
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
]
]
]
];
}
public function actionIndex() public function actionIndex()
{ {
$status = Yii::$app->request->get('status', Course::STATUS_OK); $status = Yii::$app->request->get('status', Course::STATUS_OK);
......
<?php <?php
namespace backend\controllers; namespace backend\controllers;
use backend\models\LoginForm;
use backend\models\User;
use common\libs\Utils;
use Yii; use Yii;
use yii\web\Controller; use yii\web\Controller;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use common\models\LoginForm;
/** /**
* Site controller * Site controller
*/ */
class SiteController extends Controller class SiteController extends Controller
{ {
public $layout = 'lte';
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -53,7 +58,7 @@ class SiteController extends Controller ...@@ -53,7 +58,7 @@ class SiteController extends Controller
*/ */
public function actionIndex() public function actionIndex()
{ {
return $this->render('index'); return $this->redirect(['course/index']);
} }
/** /**
...@@ -63,6 +68,15 @@ class SiteController extends Controller ...@@ -63,6 +68,15 @@ class SiteController extends Controller
*/ */
public function actionLogin() public function actionLogin()
{ {
//$user = new User();
//$user->username = 'admin';
//$user->password_hash = \Yii::$app->security->generatePasswordHash('111111');
//$user->ip = Utils::getRealIP();
//$user->logged_at = time();
//$user->save();
//
//print_r($user->errors);
if (!Yii::$app->user->isGuest) { if (!Yii::$app->user->isGuest) {
return $this->goHome(); return $this->goHome();
} }
...@@ -85,7 +99,6 @@ class SiteController extends Controller ...@@ -85,7 +99,6 @@ class SiteController extends Controller
public function actionLogout() public function actionLogout()
{ {
Yii::$app->user->logout(); Yii::$app->user->logout();
return $this->goHome(); return $this->goHome();
} }
} }
<?php
namespace backend\models;
use common\libs\Utils;
use Yii;
use yii\base\Model;
/**
* Login form
*/
class LoginForm extends Model
{
const MAX_LOGIN_NUM = 5;
const LOGIN_CYCLE = 900; //second
const REDIS_KEY_PREFIX = 'yy_adminlogin_ip';
public $username;
public $password;
public $rememberMe = true;
private $_user;
public function formName()
{
return '';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
// password is validated by validatePassword()
['password', 'validatePassword'],
['username', 'string']
];
}
/**
* @return array
*/
public function attributeLabels()
{
return [
'username' => '用户名',
'password' => '密码',
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
$redis = Yii::$app->redis;
$key = self::REDIS_KEY_PREFIX . '::' . Utils::getRealIP();
$value = $redis->get($key);
if ($value === NULL) {
$redis->setex($key, self::LOGIN_CYCLE, self::MAX_LOGIN_NUM);
} else {
if ($value <= 0) {
$this->addError('password', '登陆已经被限制了.');
}
}
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
if ($value !== NULL) {
$redis->decr($key);
}
$this->addError($attribute, '用户名或者密码错误');
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return boolean whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), 86400*7);
} else {
return false;
}
}
/**
* Finds user by [[username]]
*
* @return User
*/
protected function getUser()
{
if ($this->_user === NULL) {
$this->_user = User::findOne(['username'=>$this->username]);
}
return $this->_user;
}
}
<?php
namespace backend\models;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
* 后台管理用户类
*
* @property integer $id
* @property string $username
* @property string $auth_key
* @property string $password_hash
* @property integer $status
* @property string $ip
* @property string $created_at
* @property string $updated_at
* @property string $logged_at
*/
class User extends ActiveRecord implements \yii\web\IdentityInterface
{
public static function tableName()
{
return '{{%admin_users}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
]
]
];
}
public function rules()
{
return [
[['username', 'password_hash', 'ip', 'logged_at'], 'required'],
[['id', 'status'], 'integer'],
[['created_at', 'updated_at', 'logged_at'], 'safe'],
[['username', 'auth_key', 'ip'], 'string', 'max' => 32],
[['password_hash'], 'string', 'max' => 255],
['status', 'default', 'value' => 1]
];
}
public function getId()
{
return $this->id;
}
public function getAuthKey()
{
return $this->auth_key;
}
public function validateAuthKey($authKey)
{
return $this->getAuthKey() == $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
return \Yii::$app->security->validatePassword($password, $this->password_hash);
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->auth_key = \Yii::$app->security->generateRandomString();
}
return true;
}
return false;
}
public static function findIdentity($id)
{
return self::findOne(['id'=>$id]);
}
public static function findIdentityByAccessToken($token, $type = null)
{
throw new \yii\base\NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
}
\ No newline at end of file
...@@ -4,17 +4,20 @@ ...@@ -4,17 +4,20 @@
* @var $content string * @var $content string
*/ */
use backend\assets\LteAsset; use backend\assets\LteAsset;
use yii\helpers\Url;
$lte = $this->assetManager->getBundle(LteAsset::className()); $lte = $this->assetManager->getBundle(LteAsset::className());
//$bootstrap = $this->assetManager->getBundle('\yii\bootstrap\BootstrapAsset'); //$bootstrap = $this->assetManager->getBundle('\yii\bootstrap\BootstrapAsset');
//$this->registerJsFile($this->assetManager->getAssetUrl($bootstrap, 'js/bootstrap.min.js'));
$this->beginPage(); $this->beginPage();
$this->beginBody(); $this->beginBody();
//$this->registerJsFile($this->assetManager->getAssetUrl($bootstrap, 'js/bootstrap.min.js'));
$this->beginContent('@app/views/layouts/lte.php'); $this->beginContent('@app/views/layouts/lte.php');
?> ?>
<!-- Main Header --> <body class="hold-transition skin-blue sidebar-mini">
<header class="main-header"> <div class="wrapper">
<!-- Main Header -->
<header class="main-header">
<!-- Logo --> <!-- Logo -->
<a href="/" class="logo"> <a href="/" class="logo">
...@@ -33,101 +36,6 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -33,101 +36,6 @@ $this->beginContent('@app/views/layouts/lte.php');
<!-- Navbar Right Menu --> <!-- Navbar Right Menu -->
<div class="navbar-custom-menu"> <div class="navbar-custom-menu">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<!-- Messages: style can be found in dropdown.less-->
<li class="dropdown messages-menu">
<!-- Menu toggle button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-envelope-o"></i>
<span class="label label-success">4</span>
</a>
<ul class="dropdown-menu">
<li class="header">You have 4 messages</li>
<li>
<!-- inner menu: contains the messages -->
<ul class="menu">
<li><!-- start message -->
<a href="#">
<div class="pull-left">
<!-- User Image -->
<img src="<?=$this->assetManager->getAssetUrl($lte, 'img/user2-160x160.jpg')?>" class="img-circle" alt="User Image">
</div>
<!-- Message title and timestamp -->
<h4>
Support Team
<small><i class="fa fa-clock-o"></i> 5 mins</small>
</h4>
<!-- The message -->
<p>Why not buy a new awesome theme?</p>
</a>
</li>
<!-- end message -->
</ul>
<!-- /.menu -->
</li>
<li class="footer"><a href="#">See All Messages</a></li>
</ul>
</li>
<!-- /.messages-menu -->
<!-- Notifications Menu -->
<li class="dropdown notifications-menu">
<!-- Menu toggle button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<span class="label label-warning">10</span>
</a>
<ul class="dropdown-menu">
<li class="header">You have 10 notifications</li>
<li>
<!-- Inner Menu: contains the notifications -->
<ul class="menu">
<li><!-- start notification -->
<a href="#">
<i class="fa fa-users text-aqua"></i> 5 new members joined today
</a>
</li>
<!-- end notification -->
</ul>
</li>
<li class="footer"><a href="#">View all</a></li>
</ul>
</li>
<!-- Tasks Menu -->
<li class="dropdown tasks-menu">
<!-- Menu Toggle Button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-flag-o"></i>
<span class="label label-danger">9</span>
</a>
<ul class="dropdown-menu">
<li class="header">You have 9 tasks</li>
<li>
<!-- Inner menu: contains the tasks -->
<ul class="menu">
<li><!-- Task item -->
<a href="#">
<!-- Task title and progress text -->
<h3>
Design some buttons
<small class="pull-right">20%</small>
</h3>
<!-- The progress bar -->
<div class="progress xs">
<!-- Change the css width attribute to simulate progress -->
<div class="progress-bar progress-bar-aqua" style="width: 20%" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
<span class="sr-only">20% Complete</span>
</div>
</div>
</a>
</li>
<!-- end task item -->
</ul>
</li>
<li class="footer">
<a href="#">View all tasks</a>
</li>
</ul>
</li>
<!-- User Account Menu --> <!-- User Account Menu -->
<li class="dropdown user user-menu"> <li class="dropdown user user-menu">
<!-- Menu Toggle Button --> <!-- Menu Toggle Button -->
...@@ -135,7 +43,7 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -135,7 +43,7 @@ $this->beginContent('@app/views/layouts/lte.php');
<!-- The user image in the navbar--> <!-- The user image in the navbar-->
<img src="<?=$this->assetManager->getAssetUrl($lte, 'img/user2-160x160.jpg')?>" class="user-image" alt="User Image"> <img src="<?=$this->assetManager->getAssetUrl($lte, 'img/user2-160x160.jpg')?>" class="user-image" alt="User Image">
<!-- hidden-xs hides the username on small devices so only the image appears. --> <!-- hidden-xs hides the username on small devices so only the image appears. -->
<span class="hidden-xs">Alexander Pierce</span> <span class="hidden-xs"><?=\Yii::$app->user->getIdentity()->username?></span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<!-- The user image in the menu --> <!-- The user image in the menu -->
...@@ -143,7 +51,7 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -143,7 +51,7 @@ $this->beginContent('@app/views/layouts/lte.php');
<img src="<?=$this->assetManager->getAssetUrl($lte, 'img/user2-160x160.jpg')?>" class="img-circle" alt="User Image"> <img src="<?=$this->assetManager->getAssetUrl($lte, 'img/user2-160x160.jpg')?>" class="img-circle" alt="User Image">
<p> <p>
Alexander Pierce - Web Developer <?=\Yii::$app->user->getIdentity()->username?> - Web Developer
<small>Member since Nov. 2012</small> <small>Member since Nov. 2012</small>
</p> </p>
</li> </li>
...@@ -168,7 +76,7 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -168,7 +76,7 @@ $this->beginContent('@app/views/layouts/lte.php');
<a href="#" class="btn btn-default btn-flat">Profile</a> <a href="#" class="btn btn-default btn-flat">Profile</a>
</div> </div>
<div class="pull-right"> <div class="pull-right">
<a href="#" class="btn btn-default btn-flat">Sign out</a> <a href="<?=Url::to(['site/logout'])?>" class="btn btn-default btn-flat">Sign out</a>
</div> </div>
</li> </li>
</ul> </ul>
...@@ -180,9 +88,9 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -180,9 +88,9 @@ $this->beginContent('@app/views/layouts/lte.php');
</ul> </ul>
</div> </div>
</nav> </nav>
</header> </header>
<!-- Left side column. contains the logo and sidebar --> <!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar"> <aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less --> <!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar"> <section class="sidebar">
...@@ -193,7 +101,7 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -193,7 +101,7 @@ $this->beginContent('@app/views/layouts/lte.php');
<img src="<?=$this->assetManager->getAssetUrl($lte, 'img/user2-160x160.jpg')?>" class="img-circle" alt="User Image"> <img src="<?=$this->assetManager->getAssetUrl($lte, 'img/user2-160x160.jpg')?>" class="img-circle" alt="User Image">
</div> </div>
<div class="pull-left info"> <div class="pull-left info">
<p>Alexander Pierce</p> <p><?=\Yii::$app->user->getIdentity()->username?></p>
<!-- Status --> <!-- Status -->
<a href="#"><i class="fa fa-circle text-success"></i> Online</a> <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
</div> </div>
...@@ -209,41 +117,43 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -209,41 +117,43 @@ $this->beginContent('@app/views/layouts/lte.php');
</span> </span>
</div> </div>
</form> </form>
<!-- /.search form -->
<!-- Sidebar Menu --> <!-- Sidebar Menu -->
<ul class="sidebar-menu"> <ul class="sidebar-menu" id="sidebarMenu" data-route="<?=Yii::$app->controller->id?>">
<li class="header">基本</li> <li class="header">基本</li>
<!-- Optionally, you can add icons to the links --> <!-- Optionally, you can add icons to the links -->
<li><a href="#"><i class="fa fa-link"></i> <span>Link</span></a></li> <li><a href="#"><i class="fa fa-link"></i> <span>全局概揽</span></a></li>
<li><a href="#"><i class="fa fa-link"></i> <span>Another Link</span></a></li>
<li class="header">内容</li> <li class="header">内容</li>
<li><a href="/classes"><i class="fa fa-link"></i> <span>课堂管理</span></a></li> <li class="RT_classes"><a href="/classes"><i class="fa fa-link"></i> <span>课堂管理</span></a></li>
<li class="active"><a href="/course"><i class="fa fa-link"></i> <span>课程管理</span></a></li> <li class="RT_course"><a href="/course"><i class="fa fa-link"></i> <span>课程管理</span></a></li>
</ul> </ul>
<!-- /.sidebar-menu --> <script>
var sidebar = $("#sidebarMenu");
var currentRoute = sidebar.data("route");
sidebar.find("li.RT_"+currentRoute).addClass("active");
</script>
</section> </section>
<!-- /.sidebar --> <!-- /.sidebar -->
</aside> </aside>
<!-- Content Wrapper. Contains page content --> <!-- Content Wrapper. Contains page content -->
<div class="content-wrapper"> <div class="content-wrapper">
<?=$content?> <?=$content?>
</div> </div>
<!-- /.content-wrapper --> <!-- /.content-wrapper -->
<!-- Main Footer --> <!-- Main Footer -->
<footer class="main-footer"> <footer class="main-footer">
<!-- To the right --> <!-- To the right -->
<div class="pull-right hidden-xs"> <div class="pull-right hidden-xs">
Anything you want Anything you want
</div> </div>
<!-- Default to the left --> <!-- Default to the left -->
<strong>Copyright &copy; 2016 <a href="#">Company</a>.</strong> All rights reserved. <strong>Copyright &copy; 2016 <a href="#">Company</a>.</strong> All rights reserved.
</footer> </footer>
<!-- Control Sidebar --> <!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark"> <aside class="control-sidebar control-sidebar-dark">
<!-- Create the tabs --> <!-- Create the tabs -->
<ul class="nav nav-tabs nav-justified control-sidebar-tabs"> <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
<li class="active"><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li> <li class="active"><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
...@@ -313,11 +223,14 @@ $this->beginContent('@app/views/layouts/lte.php'); ...@@ -313,11 +223,14 @@ $this->beginContent('@app/views/layouts/lte.php');
</div> </div>
<!-- /.tab-pane --> <!-- /.tab-pane -->
</div> </div>
</aside> </aside>
<!-- /.control-sidebar --> <!-- /.control-sidebar -->
<!-- Add the sidebar's background. This div must be placed <!-- Add the sidebar's background. This div must be placed
immediately after the control sidebar --> immediately after the control sidebar -->
<div class="control-sidebar-bg"></div> <div class="control-sidebar-bg"></div>
</div>
</body>
<?php <?php
$this->endContent(); $this->endContent();
$this->endBody(); $this->endBody();
......
...@@ -24,12 +24,8 @@ AppAsset::register($this); ...@@ -24,12 +24,8 @@ AppAsset::register($this);
<script src="http://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> <script src="http://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]--> <![endif]-->
</head> </head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<?php $this->beginBody() ?> <?php $this->beginBody() ?>
<?=$content?> <?=$content?>
<?php $this->endBody() ?> <?php $this->endBody() ?>
</div>
</body>
</html> </html>
<?php $this->endPage() ?> <?php $this->endPage() ?>
\ No newline at end of file
<?php <?php
/**
/* @var $this yii\web\View */ * @var $this yii\web\View
/* @var $form yii\bootstrap\ActiveForm */ * @var $form yii\bootstrap\ActiveForm
/* @var $model \common\models\LoginForm */ * @var $model \backend\models\LoginForm
*/
use yii\helpers\Html; use yii\helpers\Html;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
$this->title = 'Login'; $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title; //$this->params['breadcrumbs'][] = $this->title;
$usernameError = $model->getFirstError('username');
$passwordError = $model->getFirstError('password');
?> ?>
<div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p> <body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo"><b>Admin</b>YunYa</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?> <?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<div class="form-group<?php if ($usernameError) { ?> has-error<?php } ?>">
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> <?php if ($usernameError) { ?>
<label class="control-label" for="inputError">
<?= $form->field($model, 'password')->passwordInput() ?> <i class="fa fa-times-circle-o"></i> <?=$usernameError?>
</label>
<?= $form->field($model, 'rememberMe')->checkbox() ?> <?php } ?>
<input type="text" name="username" class="form-control" placeholder="Username" value="<?=$model->username?>">
<div class="form-group"> <span class="glyphicon glyphicon-user form-control-feedback"></span>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div>
<div class="form-group<?php if ($passwordError) { ?> has-error<?php } ?>">
<?php if ($passwordError) { ?>
<label class="control-label" for="inputError">
<i class="fa fa-times-circle-o"></i> <?=$passwordError?>
</label>
<?php } ?>
<input type="password" name="password" class="form-control" placeholder="Password" value="<?=$model->password?>">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8"></div>
<div class="col-xs-4">
<?= Html::submitButton('Sign In', ['class' => 'btn btn-primary btn-block btn-flat', 'name' => 'login-button']) ?>
</div> </div>
<?php ActiveForm::end(); ?>
</div> </div>
<?php ActiveForm::end(); ?>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -53,20 +53,14 @@ class QiniuTranscode ...@@ -53,20 +53,14 @@ class QiniuTranscode
$fops = self::transcodeFops($avInfo); $fops = self::transcodeFops($avInfo);
$bucket = $qiniu->getStorageConfig('video', 'bucket'); $bucket = $qiniu->getStorageConfig('video', 'bucket');
$target = $bucket.':'.$targetKey; //存储位置
//存储位置
$target = $bucket.':'.$targetKey;
$notifyUrl = YII_ENV == 'dev'
? 'http://t.pp.cc/tmp/qiniu_callback.php'
: Url::to(['qiniu-callback/transcode'], true);;
/* @var $err null|\Qiniu\Http\Error */ /* @var $err null|\Qiniu\Http\Error */
if ($fops) { if ($fops) {
$fops .= '|saveas/'.\Qiniu\base64_urlSafeEncode($target); $fops .= '|saveas/'.\Qiniu\base64_urlSafeEncode($target);
//发送处理请求 //发送处理请求
$persistent = new PersistentFop($auth, $bucket, null, $notifyUrl); $persistent = new PersistentFop($auth, $bucket, null, self::getNotifyUrl());
list($presistendId, $err) = $persistent->execute($sourceKey, $fops); list($presistendId, $err) = $persistent->execute($sourceKey, $fops);
if ($err) { if ($err) {
...@@ -124,17 +118,11 @@ class QiniuTranscode ...@@ -124,17 +118,11 @@ class QiniuTranscode
//存储位置 //存储位置
$target = $bucket.':'.$targetKey; $target = $bucket.':'.$targetKey;
$fops = $fops.'/ss/0/t/'.($freeTime*60).'|saveas/'.\Qiniu\base64_urlSafeEncode($target); $fops = $fops.'/ss/0/t/'.($freeTime*60).'|saveas/'.\Qiniu\base64_urlSafeEncode($target);
$notifyUrl = YII_ENV == 'dev'
? 'http://t.pp.cc/tmp/qiniu_callback.php'
: Url::to(['qiniu-callback/transcode'], true);;
//发送处理请求 //发送处理请求
/* @var $err null|\Qiniu\Http\Error */ /* @var $err null|\Qiniu\Http\Error */
$persistent = new PersistentFop($auth, $bucket, null, $notifyUrl); $persistent = new PersistentFop($auth, $bucket, null, self::getNotifyUrl());
list($presistendId, $err) = $persistent->execute($standKey, $fops); list($presistendId, $err) = $persistent->execute($standKey, $fops);
if ($err) { if ($err) {
...@@ -212,4 +200,11 @@ class QiniuTranscode ...@@ -212,4 +200,11 @@ class QiniuTranscode
return $fops; return $fops;
} }
protected static function getNotifyUrl()
{
return YII_ENV == 'dev'
? 'http://t.pp.cc/tmp/qiniu_callback.php'
: Url::to(['qiniu-callback/transcode'], true);
}
} }
\ No newline at end of file
...@@ -36,5 +36,7 @@ return [ ...@@ -36,5 +36,7 @@ return [
'mchid' => '1399794002', 'mchid' => '1399794002',
'key' => '8934e7d15453e97507ef794cf7b0519d', 'key' => '8934e7d15453e97507ef794cf7b0519d',
'appsecret' => '7c18222c6ec31efa65d21606a629585d', 'appsecret' => '7c18222c6ec31efa65d21606a629585d',
] ],
'fronend.baseUrl' => 'http://dev.zuiketang.com/',
'backend.baseUrl' => 'http://backend.zuiketang.com/'
]; ];
...@@ -36,5 +36,7 @@ return [ ...@@ -36,5 +36,7 @@ return [
'mchid' => '1399794002', 'mchid' => '1399794002',
'key' => '8934e7d15453e97507ef794cf7b0519d', 'key' => '8934e7d15453e97507ef794cf7b0519d',
'appsecret' => '7c18222c6ec31efa65d21606a629585d', 'appsecret' => '7c18222c6ec31efa65d21606a629585d',
] ],
'fronend.baseUrl' => 'http://c.pp.cc/',
'backend.baseUrl' => 'http://admin.c.pp.cc/'
]; ];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment