100 lines
2.8 KiB
PHP
Executable File
100 lines
2.8 KiB
PHP
Executable File
<?php
|
||
|
||
namespace frontend\controllers;
|
||
|
||
use Yii;
|
||
use yii\helpers\Url;
|
||
use common\models\User;
|
||
use common\models\CAccess;
|
||
|
||
require dirname(__FILE__) . '/_public/public_demo.php';
|
||
|
||
class ApiController extends \yii\web\Controller
|
||
{
|
||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||
|
||
public function actionIndex()
|
||
{
|
||
global $_GPC;
|
||
global $_HI;
|
||
global $_FM;
|
||
$_HI['action'] = 'index';
|
||
$identity = Yii::$app->user->identity;
|
||
if (!$identity) {
|
||
return $this->goHome();
|
||
}
|
||
$_FM['user']['name'] = $identity->username;
|
||
$_FM['user']['uid'] = $identity->id;
|
||
|
||
fmFunc_cert_afterLogin();
|
||
|
||
return $this->render('index');
|
||
}
|
||
|
||
public function actionTest()
|
||
{
|
||
global $_GPC;
|
||
global $_HI;
|
||
global $_FM;
|
||
global $START_TIME;
|
||
$_HI['action'] = 'test';
|
||
|
||
$request = Yii::$app->request;
|
||
$request->enableCsrfValidation = FALSE;
|
||
|
||
// 返回所有参数
|
||
$params = $request->get();
|
||
$_FM['params'] = $params;
|
||
$accesstoken = isset($_FM['params']['accesstoken']) ? $_FM['params']['accesstoken'] : '';
|
||
//查询用户信息(根据username)
|
||
$user = CAccess::findOne(['accesstoken' => $accesstoken]);
|
||
if ($user) {
|
||
$user = $user->toArray();
|
||
} else {
|
||
$errorCode = 45300001; //未找到用户
|
||
$result = array();
|
||
$result['errorcode'] = $errorCode;
|
||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||
$result = json_encode($result);
|
||
die ($result);
|
||
}
|
||
$_FM['user'] = $user;
|
||
$_FM['user']['name'] = $_FM['user']['username'];
|
||
$cert = fmFunc_cert_exist($_FM['user']['name']);
|
||
$_FM['apiCert'] = $cert;
|
||
if ($request->isAjax) {
|
||
/* 该请求是一个 AJAX 请求 */
|
||
$result = json_encode(1);
|
||
}
|
||
if ($request->isGet) {
|
||
/* 请求方法是 GET */
|
||
|
||
}
|
||
if ($request->isPost) {
|
||
/* 请求方法是 POST */
|
||
}
|
||
if ($request->isPut) {
|
||
/* 请求方法是 PUT */
|
||
|
||
}
|
||
|
||
###定义内容类型###
|
||
//header('Content-Type: text/html; charset=utf-8'); //网页编码
|
||
//header('Content-Type: text/plain'); //纯文本格式
|
||
//header('Content-Type: image/jpeg'); //JPG、JPEG
|
||
//header('Content-Type: application/zip'); // ZIP文件
|
||
//header('Content-Type: application/pdf'); // PDF文件
|
||
//header('Content-Type: audio/mpeg'); // 音频文件
|
||
//header('Content-type: text/css'); //css文件
|
||
//header('Content-type: text/javascript'); //js文件
|
||
//header('Content-Type: application/x-shockw**e-flash'); //Flash动画
|
||
//header('Content-type: application/pdf'); //pdf
|
||
//header('Content-type: text/xml'); //xml
|
||
header('Content-type: application/json'); //json
|
||
$_FM['apiCert']['timeused'] = getMillisecond() - $START_TIME;
|
||
$_FM['apiCert']['stat'] = fmFunc_stat_get($username = $_FM['user']['username']);
|
||
$result = json_encode($_FM['apiCert']);
|
||
die($result);
|
||
}
|
||
|
||
} |