Exemplo n.º 1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     //读取好友和群消息
     $login = new LoginController();
     $login->getFriends($this->wxuin);
     do {
         //循环执行心跳
         $user = Login::where('wxuin', $this->wxuin)->where('status', 1)->first();
         if (!$user) {
             \Log::info("wxuin:{$this->wxuin} 冻结状态,结束此次循环");
             return;
         }
         $cookies = json_decode($user->cookies);
         $url = "https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=" . t() . "&skey=" . urlencode($user->skey) . "&sid=" . urlencode($cookies->wxsid) . "&uin=" . urlencode($user->Uin) . "&deviceid=" . urlencode($user->deviceid) . "&synckey=" . to_url_synckey($user->SyncKey) . "&_=" . t();
         $ret = CURL::send($url, ['Cookie' => urldecode(http_build_query($cookies, '', '; '))], ['follow_redirects' => false], ['ret' => 'all']);
         $html = $ret->body;
         $cookies2 = toCookies($ret->cookies);
         $cookies = (object) ((array) $cookies2 + (array) $cookies);
         $tmp = ['url' => $url, 'cookie' => urldecode(http_build_query($cookies, '', '; ')), 'html' => $html, 'ret_cookies' => (array) $cookies2];
         \Log::info('心跳包:', $tmp);
         $data['retcode'] = str_tiqu($html, 'retcode:\\"', '\\"');
         $data['selector'] = str_tiqu($html, 'selector:\\"', '\\"');
         //判断消息
         $this->retcode($data);
         \DB::reconnect();
         //确保获取了一个新的连接。
     } while (1);
 }
Exemplo n.º 2
0
 public function postLogin(Request $request)
 {
     $data = $request->only('url', 'uuid');
     $ret = CURL::send($data['url'], [], ['follow_redirects' => false], ['ret' => 'all']);
     //获取正真的登陆地址 //有时候需要二次跳转
     if (strstr($ret->body, "window.location.href=")) {
         $href_url = str_tiqu($ret->body, 'window.location.href=\\"', '\\"');
         $ret = CURL::send($href_url, [], ['follow_redirects' => false], ['ret' => 'all']);
     }
     $html = $ret->body;
     $cookies = toCookies($ret->cookies);
     //cookies为空返回错误
     if (!count((array) $cookies)) {
         return response()->json(['code' => 200, 'msg' => '账户可能被封,请尝试用wx.qq.com登陆']);
     }
     $file = "user/{$cookies->wxuin}.txt";
     if (\Storage::exists($file)) {
         $user = \Storage::get($file);
         $user = json_decode($user);
     } else {
         $user = (object) [];
         $user->deviceid = "e" . mt_rand(10000, 99999) . mt_rand(10000, 99999);
         //创建设备id
     }
     $user->cookies = $cookies;
     //设置cookies
     $user->skey = str_tiqu($html, '<skey>', '<\\/skey>');
     $user->pass_ticket = str_tiqu($html, '<pass_ticket>', '<\\/pass_ticket>');
     //存储
     \Storage::put($file, json_encode($user));
     return response()->json(['code' => 0, 'url' => '/login/login-ok/' . $cookies->wxuin]);
 }