Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle($uid = false)
 {
     if ($uid == false) {
         $id = $this->argument('id');
     } else {
         $id = $uid;
     }
     $user = VKUsers::findOrFail($id);
     $this->_l('Start for user #' . $id);
     $execute = 'var u = API.users.get({"user_ids":"' . $user->user_id . '", "fields":"' . implode(',', \App\Providers\VK::getAllUserList()) . '"});' . 'var w = API.wall.get( {"owner_id":u[0].id, "count":100,"filter":"owner"} );' . 'var a = API.audio.get( { "owner_id":u[0].id,"count":1000 } );' . 'var g = API.groups.get({"user_id":u[0].id, "count":1000, "extended":1});' . 'var photos = API.photos.get({"owner_id":u[0].id, "album_id":"profile", "rev":0,"extended":1,"count":20});' . 'return {"u":u,"w":w,"a":a,"g":g,"photos":photos};';
     $response = \App\Providers\VK::api('execute', ['code' => $execute, 'access_token' => $user->access_token]);
     if ($response && isset($response['response'])) {
         $data = \App\Providers\FakeDetector::prepare($response['response']);
         $user->fill($data);
         if (!\App\Providers\FakeDetector::detect($response['response'])) {
             $user->fake = true;
         }
         $user->save();
     } else {
         if (@$response['error']['error_code'] == 14) {
             $sid = @$response['error']['captcha_sid'];
             $img = @$response['error']['captcha_img'];
             $obj = ['sid' => $sid, 'img' => $img];
             $key = 'captcha' . microtime(true);
             \Redis::command('SET', [$key, json_encode($obj)]);
         }
         $this->_e(get_class($this) . ' No response for user #' . $user->id . ' ' . print_r(array_keys($response), true));
     }
     $this->_l('ok');
 }
Exemplo n.º 2
0
 public function execute(&$count, $logger = false)
 {
     if (!empty($this->preFilter['in_friends'])) {
         $o1 = (int) floor(@$this->preFilter['offset'] / 5);
         $o2 = @$this->preFilter['offset'] % 5;
         $code = 'var xz = API.friends.get( {"count":1, "offset":' . $o1 . ',"order":"random"} );' . 'var s = API.friends.get({"user_id":xz.items[0],"count":10,"offset":' . $o2 . '});' . 'var u = 1;' . 'var w = 1;' . 'var a = 1;' . 'var g = 1;' . 'var c = 0;' . 'var store = [];' . 'while (c <= 2) {' . 'var u = API.users.get({"user_ids":s.items[c], "fields":"' . VK::getAllUserListCon() . '"});' . 'var w = API.wall.get( {"owner_id":u[0].id, "count":100,"filter":"owner"} );' . 'var a = API.audio.get( { "owner_id":u[0].id,"count":1000 } );' . 'var g = API.groups.get({"user_id":u[0].id, "count":1000, "extended":1});' . 'var photos = API.photos.get({"owner_id":u[0].id, "album_id":"profile", "rev":0,"extended":1,"count":20});' . 'store.push({"u":u,"w":w,"a":a,"g":g,"photos":photos});' . 'c = c + 1;' . '}' . 'return store;';
     } else {
         $code = 'var s = API.users.search(' . json_encode($this->buildPreFilter()) . ');' . 'var u = 1;' . 'var w = 1;' . 'var a = 1;' . 'var g = 1;' . 'var c = 0;' . 'var store = [];' . 'while (c <= 3) {' . 'var u = API.users.get({"user_ids":s.items[c].id, "fields":"' . VK::getAllUserListCon() . '"});' . 'var w = API.wall.get( {"owner_id":u[0].id, "count":100,"filter":"owner"} );' . 'var a = API.audio.get( { "owner_id":u[0].id,"count":1000 } );' . 'var g = API.groups.get({"user_id":u[0].id, "count":1000, "extended":1});' . 'var photos = API.photos.get({"owner_id":u[0].id, "album_id":"profile", "rev":0,"extended":1,"count":20});' . 'store.push({"u":u,"w":w,"a":a,"g":g,"photos":photos});' . 'c = c + 1;' . '}' . 'return store;';
     }
     $res = VK::api('execute', ['code' => $code, 'access_token' => $this->token]);
     $count = 1;
     if ($res && !empty($res['response'])) {
         $arUsers = [];
         foreach ($res['response'] as $userData) {
             if (!FakeDetector::detect($userData)) {
                 $data = FakeDetector::prepare($userData);
                 $uid = $data['user_id'];
                 $_user = VKUsers::where('user_id', $uid)->first();
                 if ($_user) {
                     $_user->fill($data);
                     $_user->save();
                 } else {
                     $_user = VKUsers::create($data);
                 }
                 if (!$_user->fake) {
                     if ($this->validForPostFilter($_user)) {
                         $arUsers[] = $_user;
                     } else {
                         if ($logger) {
                             $logger->_l(FakeDetector::$why . ' id' . @$userData['u'][0]['id'], true);
                         }
                     }
                 }
             } else {
                 if ($logger) {
                     $logger->_l(FakeDetector::$why . ' id' . @$userData['u'][0]['id'], true);
                 }
             }
         }
         $count = count($res['response']);
         return $arUsers;
     } else {
         if ($logger) {
             $logger->_l(print_r($res, true), true);
         } else {
             \Log::error(print_r($res, true));
         }
         if (empty($res['error'])) {
             if (isset($res['response'])) {
                 return false;
             }
         }
         if (@$res['error']['error_code'] == 14) {
             $sid = @$res['error']['captcha_sid'];
             $img = @$res['error']['captcha_img'];
             $obj = ['sid' => $sid, 'img' => $img];
             $key = 'captcha' . microtime(true);
             \Redis::command('SET', [$key, json_encode($obj)]);
         }
     }
     return [];
 }