|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
namespace app\index\controller;
|
|
|
|
|
|
-use app\admin\model\SinaNotice;
|
|
|
+use app\admin\model\SystemNotice;
|
|
|
use app\middleware\Log;
|
|
|
use app\middleware\Safe;
|
|
|
use app\service\WeiboService;
|
|
|
@@ -45,8 +45,13 @@ class Index extends Controller
|
|
|
if (!empty($_COOKIE['SUB'])) {
|
|
|
$sub = $_COOKIE['SUB'];
|
|
|
} else {
|
|
|
- $sub = Request::post('cookie');
|
|
|
- $uid = $sub;
|
|
|
+ // 只在调试模式下开启从POST参数中获取UID,方便测试联调
|
|
|
+ if (env('app_debug') === true || env('app_debug') === 'true') {
|
|
|
+ $sub = Request::post('cookie');
|
|
|
+ $uid = $sub;
|
|
|
+ } else {
|
|
|
+ return $this->response(403, 'not login.');
|
|
|
+ }
|
|
|
}
|
|
|
FacadeLog::info($sub);
|
|
|
$userInfoRes = (new WeiboService($uid))->userinfo($sub);
|
|
|
@@ -54,7 +59,7 @@ class Index extends Controller
|
|
|
return $this->response(403, $userInfoRes['msg'] ?? '没有登录');
|
|
|
}
|
|
|
// 使用客户端信息生成token
|
|
|
- $token = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . get_client_ip(0)) . $userInfoRes['data']['uid'];
|
|
|
+ $token = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . $_SERVER['HTTP_REFERER'] . get_client_ip(0)) . $userInfoRes['data']['uid'];
|
|
|
$user = $userInfoRes['data'];
|
|
|
// 生成加密用的密钥和向量
|
|
|
$cipher = "aes-256-gcm";
|
|
|
@@ -65,8 +70,13 @@ class Index extends Controller
|
|
|
'aes_key' => $aesKey,
|
|
|
'ase_iv' => $iv,
|
|
|
]);
|
|
|
+ $cacheUser = [
|
|
|
+ 'aes_key' => $aesKey,
|
|
|
+ 'ase_iv' => $iv,
|
|
|
+ 'uid' => $user['uid'],
|
|
|
+ ];
|
|
|
// 缓存用户信息1天
|
|
|
- Cache::set('u:' . $token, json_encode($user), 86400);
|
|
|
+ Cache::set('u:' . $token, json_encode($cacheUser), 86400);
|
|
|
return $this->successResponse([
|
|
|
'user' => $user,
|
|
|
'token' => $token,
|
|
|
@@ -95,7 +105,7 @@ class Index extends Controller
|
|
|
*/
|
|
|
public function notices()
|
|
|
{
|
|
|
- $rows = SinaNotice::limit(20)->order('id', 'desc')->select();
|
|
|
+ $rows = SystemNotice::limit(20)->order('id', 'desc')->select();
|
|
|
return $this->successResponse([
|
|
|
"lists" => $rows,
|
|
|
]);
|
|
|
@@ -112,7 +122,7 @@ class Index extends Controller
|
|
|
if (empty($sendRes) || $sendRes['code'] != 10000) {
|
|
|
return $this->response(403, $sendRes['msg'] ?? '发布失败');
|
|
|
}
|
|
|
- Cache::set('u:f:' . Safe::$user['uid'], 1, 0);
|
|
|
+ Cache::set('u:f:' . Safe::$user['uid'], 1, 180 * 86400);
|
|
|
return $this->successResponse(null, '发布成功!');
|
|
|
}
|
|
|
/**
|
|
|
@@ -122,7 +132,7 @@ class Index extends Controller
|
|
|
*/
|
|
|
public function setFirst()
|
|
|
{
|
|
|
- Cache::set('u:f:' . Safe::$user['uid'], 1, 0);
|
|
|
+ Cache::set('u:f:' . Safe::$user['uid'], 1, 180 * 86400);
|
|
|
return $this->successResponse(null, '操作成功!');
|
|
|
}
|
|
|
|