Exemplo n.º 1
0
 function webwxsync()
 {
     $user = Login::where('wxuin', $this->wxuin)->where('status', 1)->first();
     if (!$user) {
         $this->death('读取消息失败,wxuin已被冻结');
     }
     $cookies = json_decode($user->cookies);
     $url = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=" . urlencode($cookies->wxsid) . "&skey=" . urlencode($user->skey) . "&lang=zh_CN" . "&pass_ticket=" . urlencode($user->pass_ticket);
     $post = '{"BaseRequest":{"Uin":' . $user->Uin . ',"Sid":"' . $cookies->wxsid . '","Skey":"' . $user->skey . '","DeviceID":"' . $user->deviceid . '"},"SyncKey":' . $user->SyncKey . ',"rr":-' . rr() . '}';
     $ret = CURL::send($url, ['Cookie' => urldecode(http_build_query($cookies, '', '; '))], ['follow_redirects' => false], ['ret' => 'all', 'post' => $post]);
     $html = $ret->body;
     $cookies2 = toCookies($ret->cookies);
     $cookies = (object) ((array) $cookies2 + (array) $cookies);
     //更新Cookie
     Login::where('wxuin', $this->wxuin)->update(['cookies' => json_encode($cookies)]);
     $data_arr = $this->post_check($html);
     //判断数据包是否正常
     \Log::info('接收到消息:', $data_arr);
     //读取消息
     if ($data_arr['AddMsgCount'] > 0) {
         foreach ($data_arr['AddMsgList'] as $k => $v) {
             echo json_encode($v) . "\r\n";
             if ($v['MsgType'] == 51 || $v['Content'] == "") {
                 //51好像没什么用,可能是正在输入的意思
                 continue;
             }
             $msg = Msglist::where('MsgId', $v['MsgId'])->first();
             if ($msg) {
                 continue;
                 //如果存在就抛弃
             }
             $data['MsgId'] = $v['MsgId'];
             $data['FromUserName'] = $v['FromUserName'];
             $data['ToUserName'] = $v['ToUserName'];
             $data['MsgType'] = $v['MsgType'];
             $data['Content'] = $v['Content'];
             $data['Status'] = $v['Status'];
             $data['ImgStatus'] = $v['ImgStatus'];
             $data['CreateTime'] = $v['CreateTime'];
             $data['time_y'] = date('Y', $v['CreateTime']);
             $data['time_m'] = date('m', $v['CreateTime']);
             $data['time_d'] = date('d', $v['CreateTime']);
             $data['time_h'] = date('H', $v['CreateTime']);
             $data['my_uin'] = $this->wxuin;
             Msglist::insert($data);
             //加入消息处理队列    在本框架内出错,无法调用
             $msg = new LoginController();
             $msg->MsgDeal($this->wxuin, $v['MsgId']);
         }
     }
     //处理SyncKey
     if ($data_arr['SyncKey']['Count'] > 0) {
         $l['SyncKey'] = json_encode($data_arr['SyncKey']);
         Login::where('wxuin', $this->wxuin)->update($l);
     }
     //处理SKey
     if ($data_arr['SKey'] != "") {
         Login::where('wxuin', $this->wxuin)->update('skey', $data_arr['SKey']);
     }
 }
Exemplo n.º 2
0
 public function getFriends($wxuin)
 {
     //循环执行心跳
     $user = Login::where('wxuin', $wxuin)->where('status', 1)->first();
     if (!$user) {
         \Log::info("wxuin:{$wxuin} 冻结状态,结束此次循环");
         return;
     }
     $cookies = json_decode($user->cookies);
     $url = "https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?r=" . t();
     $ret = CURL::send($url, ['Cookie' => urldecode(http_build_query($cookies, '', '; '))], ['follow_redirects' => false], ['ret' => 'all']);
     $html = $ret->body;
     $html = iconv('UTF-8', 'UTF-8//IGNORE', $html);
     $cookies2 = toCookies($ret->cookies);
     $cookies = (object) ((array) $cookies2 + (array) $cookies);
     //更新Cookie
     Login::where('wxuin', $wxuin)->update(['cookies' => json_encode($cookies)]);
     $data_arr = json_decode($html, true);
     foreach ($data_arr['MemberList'] as $k => $v) {
         //获取好友信息
         $data = array('my_uin' => $wxuin, 'Uin' => $v['Uin'], 'Alias' => $v['Alias'], 'UserName' => $v['UserName'], 'NickName' => $v['NickName'], 'RemarkName' => $v['RemarkName'], 'HeadImgUrl' => $v['HeadImgUrl'], 'Sex' => $v['Sex'], 'Signature' => $v['Signature'], 'Province' => $v['Province'], 'City' => $v['City']);
         $ff = Friends::where('UserName', $v['UserName'])->first();
         //如果存在了就更新
         if ($ff) {
             Friends::where('UserName', $v['UserName'])->update($data);
         } else {
             $data_batch[] = $data;
         }
     }
     if (isset($data_batch)) {
         Friends::insert($data_batch);
     }
     return $data_arr;
 }
Exemplo n.º 3
0
 public function putChatroomFriends($wxuin, $post)
 {
     \DB::reconnect();
     //确保获取了一个新的连接。
     //循环执行心跳
     $user = Login::where('wxuin', $wxuin)->where('status', 1)->first();
     if (!$user) {
         $this->death();
     }
     $cookies = json_decode($user->cookies);
     $url = 'https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact?type=ex&r=' . t();
     $ret = CURL::send($url, ['Cookie' => urldecode(http_build_query($cookies, '', '; '))], [], ['ret' => 'all', 'post' => json_encode($post)]);
     $html = $ret->body;
     $cookies2 = toCookies($ret->cookies);
     $cookies = (object) ((array) $cookies2 + (array) $cookies);
     $html = iconv('UTF-8', 'UTF-8//IGNORE', $html);
     $data_arr = json_decode($html, true);
     foreach ($data_arr['ContactList'] as $k => $v) {
         //获取好友信息
         $data_room = ['EncryChatRoomId' => $v['EncryChatRoomId'], 'Uin' => $v['Uin'], 'UserName' => $v['UserName'], 'NickName' => $v['NickName'], 'HeadImgUrl' => $v['HeadImgUrl'], 'RemarkName' => $v['RemarkName'], 'Sex' => $v['Sex'], 'Signature' => $v['Signature'], 'AttrStatus' => $v['AttrStatus'], 'Province' => $v['Province'], 'City' => $v['City']];
         $rm = Chatroom::where('EncryChatRoomId', $v['EncryChatRoomId'])->where('UserName', $v['UserName'])->first();
         //如果存在了就更新
         if ($rm) {
             Chatroom::where('EncryChatRoomId', $v['EncryChatRoomId'])->where('UserName', $v['UserName'])->update($data_room);
         } else {
             $data_room_batch[] = $data_room;
         }
     }
     if (isset($data_room_batch)) {
         Chatroom::insert($data_room_batch);
     }
 }