public function handle() { echo "msgid:{$this->msgid} 处理*****\r\n"; $msg = Msglist::where('MsgId', $this->msgid)->first()->toArray(); if (!count($msg)) { $this->death('消息已经失效'); } if ($msg['MsgType'] == 3) { //消息为图片 $info = $this->pub_img($msg); //反馈消息 $this->webwxsendmsg($msg['FromUserName'], $info); } else { if ($msg['ToUserName'] == 'filehelper') { //消息为发送给自己的文件助手 //$info = $this->cmd($msg['Content']); } else { if (strstr($msg['FromUserName'], "@@")) { //群消息 if ($msg['MsgType'] == 1) { //群普通消息 //$info = $this->room($msg); } } else { if ($msg['MsgType'] == 1) { //普通文本消息 // $info = $this->tuling($msg['Content'], $msg['FromUserName']); } else { if ($msg['MsgType'] == 10000 && $msg['Content'] == '收到红包,请在手机上查看') { //红包 } else { if ($msg['MsgType'] == 10002) { //撤回消息 } else { //其他特殊情况 $info = ""; } } } } } } }
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']); } }