|
|
@@ -2,6 +2,9 @@
|
|
|
|
|
|
namespace app\index\controller;
|
|
|
|
|
|
+use app\service\WeiboService;
|
|
|
+use think\facade\Cache;
|
|
|
+use think\facade\Db;
|
|
|
use think\facade\Request;
|
|
|
use think\admin\Controller;
|
|
|
use think\facade\Log as FacadeLog;
|
|
|
@@ -23,9 +26,82 @@ class Video extends Controller
|
|
|
$isWebo = 0;
|
|
|
// 只在调试模式下开启从POST参数中获取UID,方便测试联调
|
|
|
if (env('weibo.mock')) {
|
|
|
- $sub = Request::get('cookie', "")?:'testcookie';
|
|
|
+ $sub = Request::get('cookie', "");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ $uid = 0;
|
|
|
+ $userInfoRes = (new WeiboService($uid))->userinfo($sub);
|
|
|
+ if (empty($userInfoRes) || $userInfoRes['ok'] != 1) {
|
|
|
+ $this->fetch('404');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用客户端信息生成token
|
|
|
+ $token = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE']. 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)) {
|
|
|
+ $this->fetch('404');
|
|
|
+ }
|
|
|
+ } 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', json_encode($user));
|
|
|
+ $this->assign('token', $token);
|
|
|
+ $this->assign('isShare', $isShare);
|
|
|
+ $this->assign('count', $count);
|
|
|
+ $this->assign('isBeginActivity', $isBeginActivity);
|
|
|
+ $this->assign('task', json_encode($userInfo));
|
|
|
$this->assign('sub', $sub);
|
|
|
$this->assign('isWeibo', $isWebo);
|
|
|
$this->assign('mock', env('weibo.mock', '0'));
|