初次提交
This commit is contained in:
commit
39c0465ee3
5
.htaccess
Normal file
5
.htaccess
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<IfModule mod_rewrite.c>
|
||||||
|
RewriteEngine on
|
||||||
|
RewriteRule ^$ public/ [L]
|
||||||
|
RewriteRule (.*) public/$1 [L]
|
||||||
|
</IfModule>
|
||||||
20
.htrouter.php
Normal file
20
.htrouter.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the Phalcon Developer Tools.
|
||||||
|
*
|
||||||
|
* (c) Phalcon Team <team@phalcon.io>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||||
|
|
||||||
|
if ($uri !== '/' && file_exists(__DIR__ . '/public' . $uri)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_GET['_url'] = $_SERVER['REQUEST_URI'];
|
||||||
|
|
||||||
|
require_once __DIR__ . '/public/index.php';
|
||||||
10
app/config/config.ini
Normal file
10
app/config/config.ini
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[application]
|
||||||
|
controllersDir = app/controllers/
|
||||||
|
modelsDir = app/models/
|
||||||
|
viewsDir = app/views/
|
||||||
|
pluginsDir = app/plugins/
|
||||||
|
formsDir = app/forms/
|
||||||
|
libraryDir = app/library/
|
||||||
|
baseUri = /
|
||||||
|
[setting]
|
||||||
|
debug=0
|
||||||
30
app/config/config.php
Normal file
30
app/config/config.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modified: prepend directory path of current file, because of this file own different ENV under between Apache and command line.
|
||||||
|
* NOTE: please remove this comment.
|
||||||
|
*/
|
||||||
|
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
|
||||||
|
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
|
||||||
|
|
||||||
|
return new \Phalcon\Config([
|
||||||
|
'database' => [
|
||||||
|
'adapter' => 'Mysql',
|
||||||
|
'host' => MYSQL_CONNECT_HOST,
|
||||||
|
'username' => MYSQL_CONNECT_USERNAME,
|
||||||
|
'password' => MYSQL_CONNECT_PASSWORD,
|
||||||
|
'dbname' => MYSQL_CONNECT_DBNAME,
|
||||||
|
'charset' => 'utf8',
|
||||||
|
],
|
||||||
|
'application' => [
|
||||||
|
'appDir' => APP_PATH . '/',
|
||||||
|
'controllersDir' => APP_PATH . '/controllers/',
|
||||||
|
'modelsDir' => APP_PATH . '/models/',
|
||||||
|
'migrationsDir' => APP_PATH . '/migrations/',
|
||||||
|
'viewsDir' => APP_PATH . '/views/',
|
||||||
|
'pluginsDir' => APP_PATH . '/plugins/',
|
||||||
|
'libraryDir' => APP_PATH . '/library/',
|
||||||
|
'cacheDir' => BASE_PATH . '/cache/',
|
||||||
|
'baseUri' => '/',
|
||||||
|
]
|
||||||
|
]);
|
||||||
117
app/config/consts.php
Normal file
117
app/config/consts.php
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tiffany SMS API重构
|
||||||
|
* @author QZQ
|
||||||
|
*/
|
||||||
|
defined("BASE_PATH") || define("BASE_PATH", getenv("BASE_PATH")?:realpath(dirname(__FILE__)."/../.."));
|
||||||
|
defined("APP_PATH") || define("APP_PATH", BASE_PATH."/app");
|
||||||
|
|
||||||
|
//================客户调用接口地址、文件路径、日志前缀、数据库及redis连接相关常量开始==================
|
||||||
|
//如果HTTP_HOST表明是本地环境
|
||||||
|
if($_SERVER['HTTP_HOST']=="127.0.0.1"){
|
||||||
|
//日志前缀
|
||||||
|
define("TIFFANY_SMS_REDIS_LOG_PREFIX", "tiffany/api/");
|
||||||
|
|
||||||
|
//业务域名
|
||||||
|
define("BASE_URL", "http://127.0.0.1/tiffany/api/");
|
||||||
|
|
||||||
|
//数据库连接
|
||||||
|
define("MYSQL_CONNECT_HOST", "mysql.weu.me");
|
||||||
|
define("MYSQL_CONNECT_USERNAME", "root");
|
||||||
|
define("MYSQL_CONNECT_PASSWORD", "root_123");
|
||||||
|
define("MYSQL_CONNECT_DBNAME", "sms");
|
||||||
|
|
||||||
|
//REDIS DB
|
||||||
|
//注:本地redis就15个库,所以先放在15里 by QZQ
|
||||||
|
define("REDIS_DB_NUMBER", 15);
|
||||||
|
}
|
||||||
|
//如果是开发环境或测试环境
|
||||||
|
//注:为了让CLI脚本也能区分正式、测试、开发环境,
|
||||||
|
//以下使用SCRIPT_FILENAME来判断正式、测试、开发环境常量
|
||||||
|
elseif($_SERVER['HTTP_HOST']=="dev-shorturl.wemediacn.com" || !empty($_SERVER['SCRIPT_FILENAME']) && (preg_match("@\/d\/@", strtolower($_SERVER['SCRIPT_FILENAME'])) || preg_match("@\/t\/@", strtolower($_SERVER['SCRIPT_FILENAME'])))){
|
||||||
|
//日志前缀
|
||||||
|
define("TIFFANY_SMS_REDIS_LOG_PREFIX", "tiffany/apitest/");
|
||||||
|
|
||||||
|
//业务域名
|
||||||
|
define("BASE_URL", "https://dev-shorturl.wemediacn.com/");
|
||||||
|
|
||||||
|
//数据库连接
|
||||||
|
define("MYSQL_CONNECT_HOST", "we-devsql.mysql.rds.aliyuncs.com");
|
||||||
|
define("MYSQL_CONNECT_USERNAME", "we_dev");
|
||||||
|
define("MYSQL_CONNECT_PASSWORD", "xtcpmw0OrX2vMMPj");
|
||||||
|
define("MYSQL_CONNECT_DBNAME", "sms");
|
||||||
|
|
||||||
|
//REDIS DB
|
||||||
|
define("REDIS_DB_NUMBER", 130);
|
||||||
|
}
|
||||||
|
//如果是正式环境
|
||||||
|
else{
|
||||||
|
//日志前缀
|
||||||
|
define("TIFFANY_SMS_REDIS_LOG_PREFIX", "tiffany/api/");
|
||||||
|
|
||||||
|
//业务域名
|
||||||
|
define("BASE_URL", "https://we-shorturl.wemediacn.com/"); //新增常量 by lianghui
|
||||||
|
|
||||||
|
//数据库连接
|
||||||
|
define("MYSQL_CONNECT_HOST", "rds0yslqyg1iuze8txux545.mysql.rds.aliyuncs.com");
|
||||||
|
define("MYSQL_CONNECT_USERNAME", "tiffany");
|
||||||
|
define("MYSQL_CONNECT_PASSWORD", "50iRVc5EZURndwf5");
|
||||||
|
define("MYSQL_CONNECT_DBNAME", "sms");
|
||||||
|
|
||||||
|
//REDIS DB
|
||||||
|
define("REDIS_DB_NUMBER", 30);
|
||||||
|
}
|
||||||
|
//REDIS类
|
||||||
|
define("REDIS_FILE_PATH", "/data/www/common/create_redis.php");
|
||||||
|
|
||||||
|
//REDIS连接
|
||||||
|
define("REDIS_CONNECT_HOST", "r-bp11564d96842414128.redis.rds.aliyuncs.com");
|
||||||
|
define("REDIS_CONNECT_PORT", 6379);
|
||||||
|
define("REDIS_CONNECT_AUTH", "3Nsb4Pmsl9bcLs24mL12l");
|
||||||
|
//================客户调用接口地址、文件路径、日志前缀、数据库及redis连接相关常量结束==================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================线上日志名相关常量开始==================
|
||||||
|
//线上业务接口日志
|
||||||
|
define("TIFFANY_SMS_API_LOG", TIFFANY_SMS_REDIS_LOG_PREFIX."api");
|
||||||
|
|
||||||
|
//线上业务报错日志
|
||||||
|
define("TIFFANY_SMS_ERROR_LOG", TIFFANY_SMS_REDIS_LOG_PREFIX."error");
|
||||||
|
//================线上日志名相关常量开始==================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================其他工具类引用路径及公共类目录相关常量开始==================
|
||||||
|
//公共类所在目录
|
||||||
|
define("FILE_COMMON_PATH", "/data/www/common/");
|
||||||
|
|
||||||
|
//企业号消息警报类
|
||||||
|
define("QY_SEND_PATH", FILE_COMMON_PATH."Qy_send.php");
|
||||||
|
//================其他工具类引用路径及公共类目录相关常量开始==================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================状态、类别等数值相关基本常量开始==================
|
||||||
|
//是否删除:已删除
|
||||||
|
define("IS_DEL", 1);
|
||||||
|
|
||||||
|
//是否删除:未删除
|
||||||
|
define("NOT_DEL", 2);
|
||||||
|
|
||||||
|
//是否过期:已过期
|
||||||
|
define("IS_DUE", 1);
|
||||||
|
|
||||||
|
//是否过期:未过期
|
||||||
|
define("NOT_DUE", 2);
|
||||||
|
|
||||||
|
//通用的常量数组
|
||||||
|
class constans{
|
||||||
|
//是否删除描述
|
||||||
|
public static $IS_DEL_NAMES = array(
|
||||||
|
IS_DEL=>"是",
|
||||||
|
NOT_DEL=>"否"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//================状态、类别等数值相关常量结束==================
|
||||||
|
?>
|
||||||
21
app/config/loader.php
Normal file
21
app/config/loader.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$loader = new \Phalcon\Loader();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We're a registering a set of directories taken from the configuration file
|
||||||
|
*/
|
||||||
|
|
||||||
|
$loader->registerDirs(
|
||||||
|
[
|
||||||
|
$config->application->appDir,
|
||||||
|
$config->application->controllersDir,
|
||||||
|
$config->application->modelsDir,
|
||||||
|
$config->application->migrationsDir,
|
||||||
|
$config->application->viewsDir,
|
||||||
|
$config->application->libraryDir,
|
||||||
|
$config->application->pluginsDir,
|
||||||
|
$config->application->cacheDir,
|
||||||
|
$config->application->baseUri
|
||||||
|
]
|
||||||
|
)->register();
|
||||||
42
app/config/router.php
Normal file
42
app/config/router.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$router = $di->getRouter();
|
||||||
|
|
||||||
|
if(!empty($_SERVER['HTTP_HOST']) && (preg_match("@weapp\.wemediacn@", strtolower($_SERVER['HTTP_HOST'])))){
|
||||||
|
if(!empty($_SERVER['REQUEST_URI']) && preg_match("@\/([a-z0-9]{1,20})\/stretch@", strtolower($_SERVER['REQUEST_URI']), $matches)){
|
||||||
|
$custom_dir = $matches[1];
|
||||||
|
$router->add(
|
||||||
|
"/{$custom_dir}/tiffany/api/:controller/:action/:params",
|
||||||
|
array(
|
||||||
|
"controller"=>1,
|
||||||
|
"action"=>2,
|
||||||
|
"params"=>3
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
$router->add(
|
||||||
|
"/d/tiffany/api/:controller/:action/:params",
|
||||||
|
array(
|
||||||
|
"controller"=>1,
|
||||||
|
"action"=>2,
|
||||||
|
"params"=>3
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$router->add(
|
||||||
|
"/tiffany/api/:controller/:action/:params",
|
||||||
|
array(
|
||||||
|
"controller"=>1,
|
||||||
|
"action"=>2,
|
||||||
|
"params"=>3
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$router->handle(
|
||||||
|
$_SERVER["REQUEST_URI"]
|
||||||
|
);
|
||||||
|
?>
|
||||||
187
app/config/services.php
Normal file
187
app/config/services.php
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
use Phalcon\Escaper;
|
||||||
|
use Phalcon\Flash\Direct as Flash;
|
||||||
|
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
|
||||||
|
use Phalcon\Mvc\View;
|
||||||
|
use Phalcon\Mvc\View\Engine\Php as PhpEngine;
|
||||||
|
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
|
||||||
|
use Phalcon\Session\Adapter\Stream as SessionAdapter;
|
||||||
|
use Phalcon\Storage\SerializerFactory;
|
||||||
|
use Phalcon\Session\Manager as SessionManager;
|
||||||
|
use Phalcon\Url as UrlResolver;
|
||||||
|
|
||||||
|
if(isset($_REQUEST['qaz'])){
|
||||||
|
if($_REQUEST['qaz']=='wsx'){
|
||||||
|
ini_set("display_errors", "On");
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
}
|
||||||
|
if($_REQUEST['qaz']=='wyb'){
|
||||||
|
ini_set("display_errors", "On");
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$di->set('NoticeCenter', function ()
|
||||||
|
{
|
||||||
|
$noticeCenter = new NoticeCenter();
|
||||||
|
return $noticeCenter;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared configuration service
|
||||||
|
*/
|
||||||
|
$di->setShared('config', function () {
|
||||||
|
return include APP_PATH . "/config/config.php";
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL component is used to generate all kind of urls in the application
|
||||||
|
*/
|
||||||
|
$di->setShared('url', function () {
|
||||||
|
$config = $this->getConfig();
|
||||||
|
$url = new UrlResolver();
|
||||||
|
$url->setBaseUri($config->application->baseUri);
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting up the view component
|
||||||
|
*/
|
||||||
|
$di->setShared('view', function () {
|
||||||
|
$config = $this->getConfig();
|
||||||
|
$view = new View();
|
||||||
|
$view->setDI($this);
|
||||||
|
$view->setViewsDir($config->application->viewsDir);
|
||||||
|
|
||||||
|
$view->registerEngines([
|
||||||
|
'.volt' => function ($view) {
|
||||||
|
$config = $this->getConfig();
|
||||||
|
|
||||||
|
$volt = new VoltEngine($view, $this);
|
||||||
|
|
||||||
|
$volt->setOptions([
|
||||||
|
'path' => $config->application->cacheDir,
|
||||||
|
'separator' => '_'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $volt;
|
||||||
|
},
|
||||||
|
'.phtml' => PhpEngine::class
|
||||||
|
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database connection is created based in the parameters defined in the configuration file
|
||||||
|
*/
|
||||||
|
$di->setShared('db', function () {
|
||||||
|
$config = $this->getConfig();
|
||||||
|
|
||||||
|
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
|
||||||
|
$params = [
|
||||||
|
'host' => MYSQL_CONNECT_HOST,
|
||||||
|
'username' => MYSQL_CONNECT_USERNAME,
|
||||||
|
'password' => MYSQL_CONNECT_PASSWORD,
|
||||||
|
'dbname' => MYSQL_CONNECT_DBNAME,
|
||||||
|
'charset' => "utf8"
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($config->database->adapter == 'Postgresql') {
|
||||||
|
unset($params['charset']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new $class($params);
|
||||||
|
});
|
||||||
|
$di->setShared('read_db', function () {
|
||||||
|
$config = $this->getConfig();
|
||||||
|
|
||||||
|
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
|
||||||
|
$params = [
|
||||||
|
'host' => 'rr-bp1z8643dc476j0yw.mysql.rds.aliyuncs.com',
|
||||||
|
'username' => MYSQL_CONNECT_USERNAME,
|
||||||
|
'password' => MYSQL_CONNECT_PASSWORD,
|
||||||
|
'dbname' => MYSQL_CONNECT_DBNAME,
|
||||||
|
'charset' => "utf8"
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($config->database->adapter == 'Postgresql') {
|
||||||
|
unset($params['charset']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new $class($params);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the configuration specify the use of metadata adapter use it or use memory otherwise
|
||||||
|
*/
|
||||||
|
$di->setShared('modelsMetadata', function () {
|
||||||
|
return new MetaDataAdapter();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the session flash service with the Twitter Bootstrap classes
|
||||||
|
*/
|
||||||
|
$di->set('flash', function () {
|
||||||
|
$escaper = new Escaper();
|
||||||
|
$flash = new Flash($escaper);
|
||||||
|
$flash->setImplicitFlush(false);
|
||||||
|
$flash->setCssClasses([
|
||||||
|
'error' => 'alert alert-danger',
|
||||||
|
'success' => 'alert alert-success',
|
||||||
|
'notice' => 'alert alert-info',
|
||||||
|
'warning' => 'alert alert-warning'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $flash;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the session the first time some component request the session service
|
||||||
|
*/
|
||||||
|
$di->setShared('session', function () {
|
||||||
|
$session = new SessionManager();
|
||||||
|
$files = new SessionAdapter([
|
||||||
|
'savePath' => sys_get_temp_dir(),
|
||||||
|
]);
|
||||||
|
$session->setAdapter($files);
|
||||||
|
$session->start();
|
||||||
|
|
||||||
|
return $session;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 载入redis
|
||||||
|
*/
|
||||||
|
$di->set('redis', function ()
|
||||||
|
{
|
||||||
|
$redisObj = new Redis ();
|
||||||
|
if(
|
||||||
|
preg_match("@weapp\.wemediacn@", strtolower($_SERVER['HTTP_HOST']))
|
||||||
|
||
|
||||||
|
preg_match("@dev-shorturl\.wemediacn@", strtolower($_SERVER['HTTP_HOST']))
|
||||||
|
||
|
||||||
|
preg_match("@we-shorturl\.wemediacn@", strtolower($_SERVER['HTTP_HOST']))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$redisObj->connect('r-bp11564d96842414128.redis.rds.aliyuncs.com', 6379);
|
||||||
|
$redisObj->auth('3Nsb4Pmsl9bcLs24mL12l');
|
||||||
|
} elseif ($_SERVER['HTTP_HOST'] == '127.0.0.1'){ //本地环境
|
||||||
|
$redisObj->connect('mysql5.weu.me', 6379);
|
||||||
|
} else{
|
||||||
|
$redisObj->connect('r-bp1i8kwmlrnp6hhrkf.redis.rds.aliyuncs.com', 6379);
|
||||||
|
$redisObj->auth('r-bp1i8kwmlrnp6hhrkf');
|
||||||
|
}
|
||||||
|
|
||||||
|
$redisObj->select(REDIS_DB_NUMBER);
|
||||||
|
return $redisObj;
|
||||||
|
});
|
||||||
|
|
||||||
|
$di->set('qy_send', function () use($di)
|
||||||
|
{
|
||||||
|
$qy_send = new QySend($di);
|
||||||
|
return $qy_send;
|
||||||
|
});
|
||||||
137
app/controllers/ControllerBase.php
Normal file
137
app/controllers/ControllerBase.php
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tiffany SMS API重构-公共类
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
class ControllerBase extends Phalcon\Mvc\Controller{
|
||||||
|
|
||||||
|
//公共助手
|
||||||
|
//public $_PublicHelper;
|
||||||
|
//日志助手
|
||||||
|
public $_LogObj;
|
||||||
|
|
||||||
|
function initialize(){
|
||||||
|
//$this->_PublicHelper = new PublicHelper();
|
||||||
|
//$this->_LogObj = new LogClient();
|
||||||
|
//选择redis库(测试及开发为130,正式为30)
|
||||||
|
$this->redis->select(REDIS_DB_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* curl get
|
||||||
|
*/
|
||||||
|
function __https_request($url){
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||||
|
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$data = curl_exec($curl);
|
||||||
|
if (curl_errno($curl)) {
|
||||||
|
return 'ERROR ' . curl_error($curl);
|
||||||
|
}
|
||||||
|
curl_close($curl);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* curl post
|
||||||
|
*/
|
||||||
|
function __http_post_request($url, $postArr){
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
//curl_setopt ( $curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
|
||||||
|
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
|
||||||
|
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
|
||||||
|
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
|
||||||
|
curl_setopt($curl, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArr);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$data = curl_exec($curl);
|
||||||
|
curl_close($curl);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转页面方法封装,针对后台跳转使用
|
||||||
|
*/
|
||||||
|
function __response_redirect($url=""){
|
||||||
|
header("Location: $url"); exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客户ip
|
||||||
|
*/
|
||||||
|
function __get_client_ip(){
|
||||||
|
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
|
||||||
|
$cip = $_SERVER["HTTP_CLIENT_IP"];
|
||||||
|
}
|
||||||
|
elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
|
||||||
|
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
|
||||||
|
}
|
||||||
|
elseif(!empty($_SERVER["REMOTE_ADDR"])){
|
||||||
|
$cip = $_SERVER["REMOTE_ADDR"];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$cip = "UNKNOWN";
|
||||||
|
}
|
||||||
|
return $cip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除html标签
|
||||||
|
*/
|
||||||
|
function __delhtml($str){
|
||||||
|
$str = trim($str);
|
||||||
|
$str = str_replace(array('"', "'"), array("", ""), $str);
|
||||||
|
//开始
|
||||||
|
$st = -1;
|
||||||
|
//结束
|
||||||
|
$et = -1;
|
||||||
|
$stmp = array();
|
||||||
|
$stmp[] = " ";
|
||||||
|
$len = strlen($str);
|
||||||
|
for($i=0; $i<$len; $i++){
|
||||||
|
$ss = substr($str, $i, 1);
|
||||||
|
//ord("<")==60
|
||||||
|
if(ord($ss)==60){
|
||||||
|
$st = $i;
|
||||||
|
}
|
||||||
|
//ord(">")==62
|
||||||
|
if(ord($ss)==62){
|
||||||
|
$et = $i;
|
||||||
|
if($st!=-1){
|
||||||
|
$stmp [] = substr($str, $st, $et-$st+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$str = str_replace($stmp, "", $str);
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换xml为数组
|
||||||
|
*/
|
||||||
|
function __change_xml_to_array($xmlfile){
|
||||||
|
$ob = simplexml_load_string($xmlfile, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||||
|
$json = json_encode($ob);
|
||||||
|
$configData = json_decode($json, true);
|
||||||
|
return $configData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机生成8位字符
|
||||||
|
*/
|
||||||
|
function _get_act_code(){
|
||||||
|
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
$code = substr(str_shuffle($str), 0, 8);
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
22
app/controllers/ErrorsController.php
Normal file
22
app/controllers/ErrorsController.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
class ErrorsController extends ControllerBase {
|
||||||
|
|
||||||
|
public function initialize() {
|
||||||
|
parent::initialize ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show404Action() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show401Action() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show500Action() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
31
app/controllers/Oauth2Controller.php
Normal file
31
app/controllers/Oauth2Controller.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tiffany SMS API重构-接口类
|
||||||
|
* @author QZQ
|
||||||
|
*/
|
||||||
|
header("Content-Type:text/html; Charset=utf-8");
|
||||||
|
|
||||||
|
class Oauth2Controller extends ControllerBase{
|
||||||
|
|
||||||
|
function initialize(){
|
||||||
|
parent::initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取code(Get code)
|
||||||
|
* http://127.0.0.1/tiffany/api/oauth2/code?qaz=wsx
|
||||||
|
*/
|
||||||
|
function codeAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据code获取access_token(Get access token by code)
|
||||||
|
* http://127.0.0.1/tiffany/api/oauth2/accesstoken?qaz=wsx
|
||||||
|
*/
|
||||||
|
function accesstokenAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
63
app/controllers/SmsController.php
Normal file
63
app/controllers/SmsController.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tiffany SMS API重构-接口类
|
||||||
|
* @author QZQ
|
||||||
|
*/
|
||||||
|
header("Content-Type:text/html; Charset=utf-8");
|
||||||
|
|
||||||
|
class SmsController extends ControllerBase{
|
||||||
|
|
||||||
|
function initialize(){
|
||||||
|
parent::initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取code(Get code)
|
||||||
|
* http://127.0.0.1/tiffany/api/sms/code?qaz=wsx
|
||||||
|
*/
|
||||||
|
function codeAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据code获取access_token(Get access token by code)
|
||||||
|
* http://127.0.0.1/tiffany/api/sms/accesstoken?qaz=wsx
|
||||||
|
*/
|
||||||
|
function accesstokenAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送短信(Send SMS)
|
||||||
|
* http://127.0.0.1/tiffany/api/sms/send?qaz=wsx
|
||||||
|
*/
|
||||||
|
function sendAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取手机验证码(Get mobile verification)
|
||||||
|
* http://127.0.0.1/tiffany/api/sms/authcode?qaz=wsx
|
||||||
|
*/
|
||||||
|
function authcodeAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量查询最新短信发送结果(Batch query for the latest SMS sending result)
|
||||||
|
* http://127.0.0.1/tiffany/api/sms/query_reports?qaz=wsx
|
||||||
|
*/
|
||||||
|
function queryReportsAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长链转短链(Long URL shortening)
|
||||||
|
* http://127.0.0.1/tiffany/api/sms/query_reports?qaz=wsx
|
||||||
|
*/
|
||||||
|
function shorturlAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
23
app/controllers/UrlsController.php
Normal file
23
app/controllers/UrlsController.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Tiffany SMS API重构-接口类
|
||||||
|
* @author QZQ
|
||||||
|
*/
|
||||||
|
header("Content-Type:text/html; Charset=utf-8");
|
||||||
|
|
||||||
|
class UrlsController extends ControllerBase{
|
||||||
|
|
||||||
|
function initialize(){
|
||||||
|
parent::initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长链转短链(Long URL shortening)
|
||||||
|
* http://127.0.0.1/tiffany/api/urls/shorturl?qaz=wsx
|
||||||
|
*/
|
||||||
|
function shorturlAction(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
124
app/library/CryptAES.php
Normal file
124
app/library/CryptAES.php
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
class CryptAES
|
||||||
|
{
|
||||||
|
protected $cipher = MCRYPT_RIJNDAEL_128;
|
||||||
|
protected $mode = MCRYPT_MODE_CBC;
|
||||||
|
protected $pad_method = NULL;
|
||||||
|
protected $secret_key = '';
|
||||||
|
protected $iv = '';
|
||||||
|
|
||||||
|
public function set_cipher($cipher)
|
||||||
|
{
|
||||||
|
$this->cipher = $cipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_mode($mode)
|
||||||
|
{
|
||||||
|
$this->mode = $mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_iv($iv)
|
||||||
|
{
|
||||||
|
$this->iv = $iv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_key($key)
|
||||||
|
{
|
||||||
|
$this->secret_key = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function require_pkcs5()
|
||||||
|
{
|
||||||
|
$this->pad_method = 'pkcs5';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function pad_or_unpad($str, $ext)
|
||||||
|
{
|
||||||
|
if ( is_null($this->pad_method) )
|
||||||
|
{
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$func_name = __CLASS__ . '::' . $this->pad_method . '_' . $ext . 'pad';
|
||||||
|
if ( is_callable($func_name) )
|
||||||
|
{
|
||||||
|
$size = mcrypt_get_block_size($this->cipher, $this->mode);
|
||||||
|
return call_user_func($func_name, $str, $size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function pad($str)
|
||||||
|
{
|
||||||
|
return $this->pad_or_unpad($str, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function unpad($str)
|
||||||
|
{
|
||||||
|
return $this->pad_or_unpad($str, 'un');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function encrypt($str)
|
||||||
|
{
|
||||||
|
$str = $this->pad($str);
|
||||||
|
$td = mcrypt_module_open($this->cipher, '', $this->mode, '');
|
||||||
|
|
||||||
|
if ( empty($this->iv) )
|
||||||
|
{
|
||||||
|
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$iv = $this->iv;
|
||||||
|
}
|
||||||
|
mcrypt_generic_init($td, $this->secret_key, $iv);
|
||||||
|
$cyper_text = mcrypt_generic($td, $str);
|
||||||
|
$rt = base64_encode($cyper_text);
|
||||||
|
mcrypt_generic_deinit($td);
|
||||||
|
mcrypt_module_close($td);
|
||||||
|
|
||||||
|
return $rt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function decrypt($str){
|
||||||
|
$td = mcrypt_module_open($this->cipher, '', $this->mode, '');
|
||||||
|
|
||||||
|
if ( empty($this->iv) )
|
||||||
|
{
|
||||||
|
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$iv = $this->iv;
|
||||||
|
}
|
||||||
|
|
||||||
|
mcrypt_generic_init($td, $this->secret_key, $iv);
|
||||||
|
$decrypted_text = mdecrypt_generic($td, base64_decode($str));
|
||||||
|
$rt = $decrypted_text;
|
||||||
|
mcrypt_generic_deinit($td);
|
||||||
|
mcrypt_module_close($td);
|
||||||
|
|
||||||
|
return $this->unpad($rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function pkcs5_pad($text, $blocksize)
|
||||||
|
{
|
||||||
|
$pad = $blocksize - (strlen($text) % $blocksize);
|
||||||
|
return $text . str_repeat(chr($pad), $pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function pkcs5_unpad($text)
|
||||||
|
{
|
||||||
|
$pad = ord($text{strlen($text) - 1});
|
||||||
|
if ($pad > strlen($text)) return false;
|
||||||
|
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
|
||||||
|
return substr($text, 0, -1 * $pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
112
app/library/NoticeCenter.php
Normal file
112
app/library/NoticeCenter.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 通过企业号消息提示报警
|
||||||
|
*/
|
||||||
|
class QySend
|
||||||
|
{
|
||||||
|
public $access_token = "";
|
||||||
|
public $redis = null;
|
||||||
|
public function __construct($di)
|
||||||
|
{
|
||||||
|
$this->redis = $di->get("redis");
|
||||||
|
$this->access_token = $this->__qy_access_token(QY_CORPID, QY_SECRET);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST方式执行页面
|
||||||
|
*/
|
||||||
|
function __http_post_request($url, $postArr){
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
|
||||||
|
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
|
||||||
|
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
|
||||||
|
curl_setopt($curl, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArr);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$data = curl_exec($curl);
|
||||||
|
curl_close($curl);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业号acces_token
|
||||||
|
* $corpid,$corpsecret为权限组的id和密钥
|
||||||
|
*/
|
||||||
|
function __qy_access_token($corpid,$corpsecret)
|
||||||
|
{
|
||||||
|
$this->redis->select(REDIS_DB_NUMBER);
|
||||||
|
$rediskey = 'qy_' . $corpid . '_' . $corpsecret;
|
||||||
|
$qy_acces_token = $this->redis->get($rediskey);
|
||||||
|
if(!empty($qy_acces_token)){
|
||||||
|
return $qy_acces_token;
|
||||||
|
}else{
|
||||||
|
$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$corpsecret";
|
||||||
|
$info = $this->__https_request($url);
|
||||||
|
$tokenArr = json_decode($info,true);
|
||||||
|
$qy_acces_token = $tokenArr['access_token'];
|
||||||
|
$this->redis->setex($rediskey,7000, $qy_acces_token);
|
||||||
|
return $qy_acces_token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET方式执行页面
|
||||||
|
*/
|
||||||
|
function __https_request($url)
|
||||||
|
{
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||||
|
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$data = curl_exec($curl);
|
||||||
|
if(curl_errno($curl)){
|
||||||
|
return 'ERROR '.curl_error($curl);
|
||||||
|
}
|
||||||
|
curl_close($curl);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* we企业号消息提醒(自定义发送人群)
|
||||||
|
*/
|
||||||
|
function send_user_remind($userArr, $content)
|
||||||
|
{
|
||||||
|
if(strstr($_SERVER['HTTP_HOST'], 'weapp'))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}elseif(strstr($_SERVER['HTTP_HOST'], '127.0.0.1'))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(is_array($userArr)){
|
||||||
|
$user_str = implode("|", $userArr);
|
||||||
|
}else{
|
||||||
|
$user_str = $userArr;
|
||||||
|
}
|
||||||
|
$str = '{
|
||||||
|
"touser": "'.$user_str.'",
|
||||||
|
"toparty": "",
|
||||||
|
"totag": "",
|
||||||
|
"msgtype": "text",
|
||||||
|
"agentid": '.QY_AGENTID.',
|
||||||
|
"text": {
|
||||||
|
"content": "'.$content.'"
|
||||||
|
},
|
||||||
|
"safe":0
|
||||||
|
}';
|
||||||
|
$url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='.$this->access_token;
|
||||||
|
return $this->__http_post_request($url, $str);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/models/ModelBase.php
Normal file
12
app/models/ModelBase.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
use Phalcon\Mvc\Model;
|
||||||
|
|
||||||
|
class ModelBase extends Model{
|
||||||
|
|
||||||
|
public function sqlquery($sql){
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
45
app/plugins/NotFoundPlugin.php
Normal file
45
app/plugins/NotFoundPlugin.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
use Phalcon\Events\Event;
|
||||||
|
use Phalcon\Mvc\User\Plugin;
|
||||||
|
use Phalcon\Dispatcher;
|
||||||
|
use Phalcon\Mvc\Dispatcher\Exception as DispatcherException;
|
||||||
|
use Phalcon\Mvc\Dispatcher as MvcDispatcher;
|
||||||
|
/**
|
||||||
|
* NotFoundPlugin
|
||||||
|
*
|
||||||
|
* Handles not-found controller/actions
|
||||||
|
*/
|
||||||
|
class NotFoundPlugin extends Plugin {
|
||||||
|
public $config = array ();
|
||||||
|
/**
|
||||||
|
* This action is executed before execute any action in the application
|
||||||
|
*
|
||||||
|
* @param Event $event
|
||||||
|
* @param MvcDispatcher $dispatcher
|
||||||
|
* @param Exception $exception
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception) {
|
||||||
|
error_log ( $exception->getMessage () . PHP_EOL . $exception->getTraceAsString () );
|
||||||
|
if ($exception instanceof DispatcherException) {
|
||||||
|
switch ($exception->getCode ()) {
|
||||||
|
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND :
|
||||||
|
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND :
|
||||||
|
$dispatcher->forward ( array (
|
||||||
|
'controller' => 'errors',
|
||||||
|
'action' => 'show404'
|
||||||
|
) );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->config->setting->debug > 1) {
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
$dispatcher->forward ( array (
|
||||||
|
'controller' => 'errors',
|
||||||
|
'action' => 'show500'
|
||||||
|
) );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
108
app/plugins/SecurityPlugin.php
Normal file
108
app/plugins/SecurityPlugin.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
use Phalcon\Acl;
|
||||||
|
use Phalcon\Acl\Role;
|
||||||
|
use Phalcon\Acl\Resource;
|
||||||
|
use Phalcon\Events\Event;
|
||||||
|
use Phalcon\Mvc\User\Plugin;
|
||||||
|
use Phalcon\Mvc\Dispatcher;
|
||||||
|
use Phalcon\Acl\Adapter\Memory as AclList;
|
||||||
|
/**
|
||||||
|
* SecurityPlugin
|
||||||
|
*
|
||||||
|
* This is the security plugin which controls that users only have access to the modules they're assigned to
|
||||||
|
*/
|
||||||
|
class SecurityPlugin extends Plugin {
|
||||||
|
/**
|
||||||
|
* Returns an existing or new access control list
|
||||||
|
*
|
||||||
|
* @return s AclList
|
||||||
|
*/
|
||||||
|
public function getAcl() {
|
||||||
|
if (! isset ( $this->persistent->acl )) {
|
||||||
|
$acl = new AclList ();
|
||||||
|
// Register roles
|
||||||
|
$roles = array (
|
||||||
|
'users' => new Role ( 'Users' ),
|
||||||
|
'guests' => new Role ( 'Guests' )
|
||||||
|
);
|
||||||
|
foreach ( $roles as $role ) {
|
||||||
|
$acl->addRole ( $role );
|
||||||
|
}
|
||||||
|
// Private area resources
|
||||||
|
$privateResources = array ();
|
||||||
|
foreach ( $privateResources as $resource => $actions ) {
|
||||||
|
$acl->addResource ( new Resource ( $resource ), $actions );
|
||||||
|
}
|
||||||
|
// Public area resources
|
||||||
|
$publicResources = array (
|
||||||
|
'index' => array (
|
||||||
|
'index'
|
||||||
|
),
|
||||||
|
'logs' => array (
|
||||||
|
'index'
|
||||||
|
),
|
||||||
|
'errors' => array (
|
||||||
|
'show401',
|
||||||
|
'show404',
|
||||||
|
'show500'
|
||||||
|
),
|
||||||
|
'session' => array (
|
||||||
|
'index',
|
||||||
|
'register',
|
||||||
|
'start',
|
||||||
|
'end'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
foreach ( $publicResources as $resource => $actions ) {
|
||||||
|
$acl->addResource ( new Resource ( $resource ), $actions );
|
||||||
|
}
|
||||||
|
// Grant access to public areas to both users and guests
|
||||||
|
foreach ( $roles as $role ) {
|
||||||
|
foreach ( $publicResources as $resource => $actions ) {
|
||||||
|
foreach ( $actions as $action ) {
|
||||||
|
$acl->allow ( $role->getName (), $resource, $action );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Grant access to private area to role Users
|
||||||
|
foreach ( $privateResources as $resource => $actions ) {
|
||||||
|
foreach ( $actions as $action ) {
|
||||||
|
$acl->allow ( 'Guests', $resource, $action );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The acl is stored in session, APC would be useful here too
|
||||||
|
$this->persistent->acl = $acl;
|
||||||
|
}
|
||||||
|
return $this->persistent->acl;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* This action is executed before execute any action in the application
|
||||||
|
*
|
||||||
|
* @param Event $event
|
||||||
|
* @param Dispatcher $dispatcher
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function beforeDispatch(Event $event, Dispatcher $dispatcher) {
|
||||||
|
$auth = $this->session->get ( 'auth' );
|
||||||
|
if (! $auth) {
|
||||||
|
$role = 'Guests';
|
||||||
|
} else {
|
||||||
|
$role = 'Users';
|
||||||
|
}
|
||||||
|
$controller = $dispatcher->getControllerName ();
|
||||||
|
$controller = strtolower ( $controller );
|
||||||
|
$action = $dispatcher->getActionName ();
|
||||||
|
$controller = strtolower ( $action );
|
||||||
|
$acl = $this->getAcl ();
|
||||||
|
$allowed = $acl->isAllowed ( $role, $controller, $action );
|
||||||
|
if ($allowed != Acl::ALLOW) {
|
||||||
|
$dispatcher->forward(array(
|
||||||
|
'controller' => 'errors',
|
||||||
|
'action' => 'show401'
|
||||||
|
));
|
||||||
|
$this->session->destroy();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
1
app/views/errors/show401.volt
Normal file
1
app/views/errors/show401.volt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{ content() }}
|
||||||
1
app/views/errors/show404.volt
Normal file
1
app/views/errors/show404.volt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{ content() }}
|
||||||
1
app/views/errors/show500.volt
Normal file
1
app/views/errors/show500.volt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{ content() }}
|
||||||
21
app/views/index.phtml
Normal file
21
app/views/index.phtml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||||
|
<title>Phalcon PHP Framework</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||||
|
<link rel="shortcut icon" type="image/x-icon" href="<?php echo $this->url->get('img/favicon.ico')?>"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<?php echo $this->getContent(); ?>
|
||||||
|
</div>
|
||||||
|
<!-- jQuery first, then Popper.js, and then Bootstrap's JavaScript -->
|
||||||
|
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
app/views/index.volt
Normal file
1
app/views/index.volt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{ content() }}
|
||||||
7
app/views/index/index.phtml
Normal file
7
app/views/index/index.phtml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<div class="page-header">
|
||||||
|
<h1>Congratulations!</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>You're now flying with Phalcon. Great things are about to happen!</p>
|
||||||
|
|
||||||
|
<p>This page is located at <code>views/index/index.phtml</code></p>
|
||||||
1
app/views/layouts/index.volt
Normal file
1
app/views/layouts/index.volt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{ content() }}
|
||||||
86
app/views/layouts/main.volt
Normal file
86
app/views/layouts/main.volt
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<title>{{get_title()}}</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo IMGURL_PREFIX_NEW;?>css/bs.min.css" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo IMGURL_PREFIX_NEW;?>css/page.css" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo IMGURL_PREFIX_NEW;?>css/dialog/dialog.css" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="<?php echo IMGURL_PREFIX_NEW;?>css/dialog/dialog-min.css" />
|
||||||
|
<script type="text/javascript" src="<?php echo IMGURL_PREFIX_NEW;?>js/jquery.min.js"></script>
|
||||||
|
<script type="text/javascript" src="<?php echo IMGURL_PREFIX_NEW;?>js/dialog/jQuery.ui.Dialog.js"></script>
|
||||||
|
<script type="text/javascript" src="<?php echo IMGURL_PREFIX_NEW;?>js/dialog/jQuery.ui.Dialog-min.js"></script>
|
||||||
|
<script type="text/javascript" src="<?php echo IMGURL_PREFIX_NEW;?>js/msg-pc.js"></script>
|
||||||
|
</head>
|
||||||
|
<script>
|
||||||
|
$(function(){
|
||||||
|
<?php if(!empty($_COOKIE['prompt'])){?>
|
||||||
|
ui.Dialog.tips("<?php echo strip_tags($_COOKIE['prompt'], '<br>');?>");
|
||||||
|
<?php setcookie('prompt', '', time()-1);}?>
|
||||||
|
$(".dropdown").hover(function(){
|
||||||
|
$(".dropdown-menu").show();
|
||||||
|
}, function(){
|
||||||
|
$(".dropdown-menu").hide();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
function loginout(){
|
||||||
|
window.location.href = "<?php echo IMGURL_PREFIX_NEW;?>backstage/loginout";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-1"></div>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<nav role="navigation" class="navbar-default">
|
||||||
|
<div class="navbar-header"><a href="javascript:;" class="navbar-brand">Dr.stretch拉伸馆</a></div>
|
||||||
|
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||||
|
<?php if(!empty($stretch_lottery_admin_chname)){?>
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li <?php if($menu_id=="events"){?> class="curr" <?php }?>><a href="<?php echo IMGURL_PREFIX_NEW;?>backstage/events">抽奖活动管理</a></li>
|
||||||
|
</ul>
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li <?php if($menu_id=="users"){?> class="curr" <?php }?>><a href="<?php echo IMGURL_PREFIX_NEW;?>backstage/users">参与用户管理</a></li>
|
||||||
|
</ul>
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li <?php if($menu_id=="error_settings"){?> class="curr" <?php }?>><a href="<?php echo IMGURL_PREFIX_NEW;?>backstage/error_settings">默认报错配置管理</a></li>
|
||||||
|
</ul>
|
||||||
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
<li class="dropdown">
|
||||||
|
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"><?php echo $stretch_lottery_admin_chname;?> <b class="caret"></b></a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li><a href="<?php echo IMGURL_PREFIX_NEW;?>backstage/edit_pwd">修改密码</a></li>
|
||||||
|
<li><a onclick="loginout();">退出</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<?php }?>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-1"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container-fluid body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-1"></div>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<div id="crumbs" class="crumbs">
|
||||||
|
<?php if(!empty($crumbsStr)){?>
|
||||||
|
<span class="loca">您的位置:</span>
|
||||||
|
<?php echo $crumbsStr;?>
|
||||||
|
<?php }?>
|
||||||
|
{{content()}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-1"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="footer">
|
||||||
|
<div class="container">
|
||||||
|
北京众览传媒上海分公司
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
11
app/views/layouts/page_limit.volt
Normal file
11
app/views/layouts/page_limit.volt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<div class="pagenum">
|
||||||
|
<ul class="pagination">
|
||||||
|
<li><a href="{{jumpurl}}{{namedStr}}&page=<?php echo $page->first;?>" class="btn"><i class="icon-fast-forward"></i>首页</a></li>
|
||||||
|
<li><a href="{{jumpurl}}{{namedStr}}&page=<?php echo $page->before;?>" class="btn"><i class="icon-fast-forward"></i>上一页</a></li>
|
||||||
|
<li><span class="num">第<?php echo $page->current;?>页</span></li>
|
||||||
|
<li><a href="{{jumpurl}}{{namedStr}}&page=<?php echo $page->next;?>" class="btn"><i class="icon-fast-forward"></i>下一页</a></li>
|
||||||
|
<li><a href="{{jumpurl}}{{namedStr}}&page=<?php echo $page->last;?>" class="btn"><i class="icon-fast-forward"></i>末页</a></li>
|
||||||
|
<li><span class="num">共<?php echo $page->last;?>页</span></li>
|
||||||
|
<li><span class="num">共<?php echo $page->total_items;?>条</span></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
1
cache/_www_tiffany_sms_app_views_index.volt.php
vendored
Normal file
1
cache/_www_tiffany_sms_app_views_index.volt.php
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?= $this->getContent() ?>
|
||||||
2
cache/volt/.gitignore
vendored
Normal file
2
cache/volt/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
1
index.html
Normal file
1
index.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<html><body><h1>Mod-Rewrite is not enabled</h1><p>Please enable rewrite module on your web server to continue</body></html>
|
||||||
8
public/.htaccess
Normal file
8
public/.htaccess
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
AddDefaultCharset UTF-8
|
||||||
|
|
||||||
|
<IfModule mod_rewrite.c>
|
||||||
|
RewriteEngine On
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
|
||||||
|
</IfModule>
|
||||||
72
public/index.php
Normal file
72
public/index.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
use Phalcon\Di\FactoryDefault;
|
||||||
|
error_reporting(0);
|
||||||
|
if(!empty($_REQUEST['qaz']))
|
||||||
|
{
|
||||||
|
if($_REQUEST['qaz']=="wsx"){
|
||||||
|
ini_set('display_errors','On');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
define("BASE_PATH", dirname(__DIR__));
|
||||||
|
define("APP_PATH", BASE_PATH."/app");
|
||||||
|
|
||||||
|
//include_once "/data/www/common/socket/log_client.php";
|
||||||
|
//include_once "/data/www/common/PublicHelper.php";
|
||||||
|
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* 引用常量文件
|
||||||
|
*/
|
||||||
|
require APP_PATH."/config/consts.php";
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 引用redis类
|
||||||
|
// */
|
||||||
|
// require REDIS_FILE_PATH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The FactoryDefault Dependency Injector automatically registers
|
||||||
|
* the services that provide a full stack framework.
|
||||||
|
*/
|
||||||
|
$di = new FactoryDefault();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read services
|
||||||
|
*/
|
||||||
|
include APP_PATH."/config/services.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle routes
|
||||||
|
*/
|
||||||
|
include APP_PATH."/config/router.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get config service for use in inline setup below
|
||||||
|
*/
|
||||||
|
$config = $di->getConfig();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include Autoloader
|
||||||
|
*/
|
||||||
|
include APP_PATH."/config/loader.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the request
|
||||||
|
*/
|
||||||
|
$application = new \Phalcon\Mvc\Application($di);
|
||||||
|
|
||||||
|
echo $application->handle($_SERVER['REQUEST_URI'])->getContent();
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
$message = array();
|
||||||
|
$message[] = $e->getMessage();
|
||||||
|
$message[] = $e->getTraceAsString();
|
||||||
|
$message[] = "request_uri:{$_SERVER['REQUEST_URI']} ";
|
||||||
|
var_dump($message);
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
2
robots.txt
Normal file
2
robots.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow: /
|
||||||
Loading…
Reference in New Issue
Block a user