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; }
public function getChatroom($wxuin) { //循环执行心跳 $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(); $post['BaseRequest']['DeviceID'] = $user->deviceid; $post['BaseRequest']['Sid'] = $cookies->wxsid; $post['BaseRequest']['Skey'] = $user->skey; $post['BaseRequest']['Uin'] = (int) $cookies->wxuin; //获取群列表 $Chatroom = Friends::where('UserName', 'like', '@@%')->where('my_uin', $wxuin)->get(); if (!count($Chatroom)) { $this->death('获取不到群信息'); } $post['Count'] = count($Chatroom); foreach (json_decode($Chatroom) as $k => $v) { $post['List'][$k]['UserName'] = $v->UserName; $post['List'][$k]['EncryChatRoomId'] = ''; } $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 = ['my_uin' => $wxuin, 'UserName' => $v['UserName'], 'NickName' => $v['NickName'], 'HeadImgUrl' => $v['HeadImgUrl'], 'OwnerUin' => $v['OwnerUin'], 'EncryChatRoomId' => $v['EncryChatRoomId'], 'MemberCount' => $v['MemberCount']]; //处理群好友信息 foreach ($v['MemberList'] as $_k => $_v) { $data_room = ['EncryChatRoomId' => $v['EncryChatRoomId'], 'UserName' => $_v['UserName'], 'AttrStatus' => $_v['AttrStatus'], 'NickName' => $_v['NickName'], 'Uin' => $_v['Uin']]; $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); unset($data_room_batch); } $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); } }