Пример #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $weixin = $request->session()->get('wechat.oauth_user');
     // 不接受无信用的凭证
     if (empty($weixin['id']) || strlen($weixin['id']) !== 28) {
         return abort(405);
     }
     // 生成一个随机的userKEY用于会话验证
     // 将该session的过期时间设置为比access_token
     // 的refresh时长多10s,一旦access_token刷新,
     // userKEY的值会重新计算并存储
     $token = $weixin['token'];
     $refresh = $token['refresh_token'];
     $expires = $token['expires_in'];
     // 假设用户数据已经存在于数据库中
     $user = Weixin_User::getFullyUserInfoWithOpenID($token['openid']);
     if (empty($user)) {
         $user = Weixin_User::storeNewUserInfo(new Weixin_User(), $weixin->toArray());
     }
     $user_id = $user->user_id;
     $key = 'jk_session:' . $user_id . ':userKEY';
     // 存储当前会话消息
     $request->session()->put('jukebox_user', $user_id);
     // 计算并存储userKEY
     if (!\PRedis::command('get', [$key])) {
         \PRedis::command('setex', [$key, intval($expires) + 10, str_limit($refresh, 5) . str_random(1)]);
     }
     return $next($request);
 }
Пример #2
0
 echo "--------begin get user info--------\n";
 $total = $redis->llen('request_queue');
 if ($total == 0) {
     echo "--------done--------\n";
     break;
 }
 $current_count = $total <= $max_connect ? $total : $max_connect;
 for ($i = 1; $i <= $current_count; ++$i) {
     $pid = pcntl_fork();
     if ($pid == -1) {
         echo "--------fork child process failed--------\n";
         exit(0);
     }
     if (!$pid) {
         $startTime = microtime();
         $tmp_redis = PRedis::getInstance();
         $tmp_u_id = $tmp_redis->lpop('request_queue');
         if (empty($tmp_redis->zscore('already_get_queue', $tmp_u_id))) {
             saveUserInfo($tmp_u_id);
             $user_info = User::info($tmp_u_id);
             $user_followees_count = $tmp_redis->hget($tmp_u_id, 'followees_count');
             $user_followers_count = $tmp_redis->hget($tmp_u_id, 'followers_count');
             if ($user_info['followees_count'] != $user_followees_count) {
                 updateUserInfo($tmp_u_id);
                 echo "--------start getting {$tmp_u_id}'s " . $user_info['followees_count'] . " followees user list--------\n";
                 $followee_users = getUserList($tmp_u_id, 'followees', $user_info['followees_count'], 1);
                 $tmp_redis->set($tmp_u_id, 'followees_count', count($followee_users));
                 if (!empty($followee_users)) {
                     foreach ($followee_users as $user) {
                         $tmp_redis->lpush('request_queue', $user[3]);
                     }
Пример #3
0
 /**
  *
  */
 public static function getUserVotesWithUserID($song_id, $user_id)
 {
     return \PRedis::command('hget', ['jk_upvote:' . $song_id . ':userLIST', $user_id]);
 }