|
@@ -30,93 +30,19 @@ class Index extends Controller
|
|
|
{
|
|
{
|
|
|
public function index()
|
|
public function index()
|
|
|
{
|
|
{
|
|
|
- FacadeLog::info("cookies:" . json_encode(Request::post()));
|
|
|
|
|
- $sub = "";
|
|
|
|
|
- $uid = 0;
|
|
|
|
|
- FacadeLog::info($_COOKIE);
|
|
|
|
|
- if (!empty($_COOKIE['SUB'])) {
|
|
|
|
|
|
|
+ FacadeLog::info("index cookies: ". json_encode($_COOKIE));
|
|
|
|
|
+ if (!empty($_COOKIE['SUB']) && strpos($_SERVER["HTTP_USER_AGENT"],"Weibo")) {
|
|
|
$sub = $_COOKIE['SUB'];
|
|
$sub = $_COOKIE['SUB'];
|
|
|
|
|
+ $isWebo = 1;
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ $isWebo = 0;
|
|
|
// 只在调试模式下开启从POST参数中获取UID,方便测试联调
|
|
// 只在调试模式下开启从POST参数中获取UID,方便测试联调
|
|
|
if (env('app_debug')) {
|
|
if (env('app_debug')) {
|
|
|
$sub = Request::post('cookie');
|
|
$sub = Request::post('cookie');
|
|
|
- $uid = $sub;
|
|
|
|
|
- } else {
|
|
|
|
|
- return $this->response(403, 'not login.');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- FacadeLog::info($sub);
|
|
|
|
|
- $userInfoRes = (new WeiboService($uid))->userinfo($sub);
|
|
|
|
|
- if (empty($userInfoRes) || $userInfoRes['ok'] != 1) {
|
|
|
|
|
- return $this->response(403, $userInfoRes['msg'] ?? '没有登录');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 使用客户端信息生成token
|
|
|
|
|
- $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'];
|
|
|
|
|
-
|
|
|
|
|
- $userInfo = Db::table('awards_user_info')->where('uid', $user['uid'])->find();
|
|
|
|
|
- $count = 0;
|
|
|
|
|
- $isShare = 0;
|
|
|
|
|
- if (empty($userInfo)) {
|
|
|
|
|
- $userAttr = [
|
|
|
|
|
- 'uid' => $user['uid'],
|
|
|
|
|
- 'portrait' => $user['profile_image_url'],
|
|
|
|
|
- 'nickname' => $user['name'],
|
|
|
|
|
- 'is_share' => 0,
|
|
|
|
|
- 'count' => 1,
|
|
|
|
|
- 'create_at' => time()
|
|
|
|
|
- ];
|
|
|
|
|
- if (0 == Db::table('awards_user_info')->insert($userAttr)) {
|
|
|
|
|
- return $this->response(5001, '系统错误,请稍后再试~');
|
|
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- $count = Db::table('awards_user_task_log')->where('uid', $user['uid'])->count('id');
|
|
|
|
|
- $isShare = $userInfo['is_share'];
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 生成加密用的密钥和向量
|
|
|
|
|
- $cipher = "aes-256-gcm";
|
|
|
|
|
- $ivlen = openssl_cipher_iv_length($cipher);
|
|
|
|
|
- $iv = bin2hex(openssl_random_pseudo_bytes($ivlen));
|
|
|
|
|
- $aesKey = bin2hex(openssl_random_pseudo_bytes(32));
|
|
|
|
|
- $user = array_merge($user, [
|
|
|
|
|
- 'aes_key' => $aesKey,
|
|
|
|
|
- 'ase_iv' => $iv,
|
|
|
|
|
- ]);
|
|
|
|
|
- $cacheUser = [
|
|
|
|
|
- 'aes_key' => $aesKey,
|
|
|
|
|
- 'ase_iv' => $iv,
|
|
|
|
|
- 'uid' => $user['uid'],
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
|
|
|
|
|
- ->where('end_at', '>=', time())->find();
|
|
|
|
|
-
|
|
|
|
|
- $isBeginActivity = 1;
|
|
|
|
|
- if (empty($activity)) {
|
|
|
|
|
- $isBeginActivity = 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $userInfo = [];
|
|
|
|
|
- if ($count > 0) {
|
|
|
|
|
- $userInfo = Db::table('awards_user_task_log')->alias('l')
|
|
|
|
|
- ->leftJoin('awards_user_info u', 'l.uid = u.uid')
|
|
|
|
|
- ->field(['u.nickname', 'u.portrait', 'u.uid', 'l.duration', 'l.number'])
|
|
|
|
|
- ->order('l.number', 'desc')
|
|
|
|
|
- ->order('l.duration', 'asc')
|
|
|
|
|
- ->find();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 缓存用户信息1天
|
|
|
|
|
- Cache::set('u:' . $token, json_encode($cacheUser), 86400);
|
|
|
|
|
-
|
|
|
|
|
- $this->assign('user', $user);
|
|
|
|
|
- $this->assign('token', $token);
|
|
|
|
|
- $this->assign('isShare', $isShare);
|
|
|
|
|
- $this->assign('count', $count);
|
|
|
|
|
- $this->assign('isBeginActivity', $isBeginActivity);
|
|
|
|
|
- $this->assign('task', $userInfo);
|
|
|
|
|
|
|
+ $this->assign('sub', $sub);
|
|
|
|
|
+ $this->assign('isWeibo', $isWebo);
|
|
|
|
|
|
|
|
$this->fetch();
|
|
$this->fetch();
|
|
|
}
|
|
}
|
|
@@ -149,22 +75,9 @@ class Index extends Controller
|
|
|
*/
|
|
*/
|
|
|
public function checkLogin()
|
|
public function checkLogin()
|
|
|
{
|
|
{
|
|
|
- FacadeLog::info("cookies:" . json_encode(Request::post()));
|
|
|
|
|
- $sub = "";
|
|
|
|
|
|
|
+ FacadeLog::info("checkLogin cookies:" . json_encode(Request::post()));
|
|
|
|
|
+ $sub = Request::post('cookie');
|
|
|
$uid = 0;
|
|
$uid = 0;
|
|
|
- FacadeLog::info($_COOKIE);
|
|
|
|
|
- if (!empty($_COOKIE['SUB'])) {
|
|
|
|
|
- $sub = $_COOKIE['SUB'];
|
|
|
|
|
- } else {
|
|
|
|
|
- // 只在调试模式下开启从POST参数中获取UID,方便测试联调
|
|
|
|
|
- if (env('app_debug')) {
|
|
|
|
|
- $sub = Request::post('cookie');
|
|
|
|
|
- $uid = $sub;
|
|
|
|
|
- } else {
|
|
|
|
|
- return $this->response(403, 'not login.');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- FacadeLog::info($sub);
|
|
|
|
|
$userInfoRes = (new WeiboService($uid))->userinfo($sub);
|
|
$userInfoRes = (new WeiboService($uid))->userinfo($sub);
|
|
|
if (empty($userInfoRes) || $userInfoRes['ok'] != 1) {
|
|
if (empty($userInfoRes) || $userInfoRes['ok'] != 1) {
|
|
|
return $this->response(403, $userInfoRes['msg'] ?? '没有登录');
|
|
return $this->response(403, $userInfoRes['msg'] ?? '没有登录');
|