优化ctms-api语法、修复已知BUG;
主要修复ctms-api、dacms对PHP新版本的支持问题
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
# @Date: 2022-04-15 20:22:03
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-07-08T16:02:30+08:00
|
||||
# @Last modified time: 2024-08-09T09:02:06+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
//前端用户入口
|
||||
|
||||
namespace backend\controllers\client\v1;
|
||||
|
||||
namespace api\controllers\client\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
@@ -26,13 +26,12 @@ class Common extends Controller
|
||||
protected $page = 1; //当前数据分页
|
||||
protected $pageSize = 10; //默认数据分页大小
|
||||
public $enableCsrfValidation = false;
|
||||
protected $timetamp = '';
|
||||
protected $timestamp = TIMESTAMP;
|
||||
//替代常规的_construct 析构函数;其他方法调用前执行
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->timetamp = time();
|
||||
//判断请求内容类型 content-type,支持 json请求
|
||||
$postdata = Yii::$app->request->post();
|
||||
$headers = Yii::$app->request->headers;
|
||||
@@ -41,7 +40,7 @@ class Common extends Controller
|
||||
$postdata = json_decode(file_get_contents('php://input'), true);
|
||||
}
|
||||
$this->postdata = $postdata;
|
||||
|
||||
|
||||
$session = Yii::$app->session;
|
||||
if (isset($postdata['pid'])) {
|
||||
if ((int)$postdata['pid']>0) {
|
||||
@@ -60,18 +59,18 @@ class Common extends Controller
|
||||
} else {
|
||||
$session->set('pid', 0);
|
||||
}
|
||||
|
||||
|
||||
$this->site_id = Yii::$app->params['siteId'];
|
||||
|
||||
|
||||
if (isset($postdata['uid']) && (int)$postdata['uid']>0) {
|
||||
$this->user_id = (int)$postdata['uid'];
|
||||
}
|
||||
if ($this->user_id) {
|
||||
$userModel = new Fans();
|
||||
$res = $userModel->findOne($this->user_id);
|
||||
if(!$res){
|
||||
if (!$res) {
|
||||
$this->user_id = 0;
|
||||
}else{
|
||||
} else {
|
||||
$this->user_info = $res;
|
||||
}
|
||||
//TBD 后期需加上更多登陆验证逻辑
|
||||
@@ -93,19 +92,20 @@ class Common extends Controller
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function fansToken($user=[], $refresh=false, $expire = null){
|
||||
|
||||
public function fansToken($user = [], $refresh = FALSE, $expire = NULL)
|
||||
{
|
||||
//生成token(用户数据,是否强制更新,过期时间 // TBD 具体方法有待优化
|
||||
$expire = $expire ? $expire : '+1 day';
|
||||
$token = Yii::$app->session->get('fansToken');
|
||||
$tokenExpired = Yii::$app->session->get('fansTokenExpired');
|
||||
if(!$token || $refresh){
|
||||
if (!$token || $refresh) {
|
||||
$tokenExpired = strtotime($expire)*1000;
|
||||
$token = md5('username='.$user['username'].'&mobile='.$user['mobile'].'&time='.$tokenExpired);
|
||||
Yii::$app->session->set('fansToken',$token);
|
||||
Yii::$app->session->set('fansTokenExpired',$tokenExpired);
|
||||
Yii::$app->session->set('fansToken', $token);
|
||||
Yii::$app->session->set('fansTokenExpired', $tokenExpired);
|
||||
}
|
||||
$user['token'] = $token;
|
||||
$user['token'] = $token;
|
||||
$user['tokenExpired'] = $tokenExpired;
|
||||
return $user;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user