示例#1
0
 function GetMessage()
 {
     $url = 'https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=1000' . '&day=7&token=' . $this->token . '&lang=zh_CN';
     $httpClient = new HttpUtil();
     $httpClient->referer = 'https://mp.weixin.qq.com/advanced/autoreply?t=ivr/reply&action=beadded&token=' . $this->token . '&lang=zh_CN';
     $httpClient->getHeader = "0";
     $result = $httpClient->GetContent($url);
     if (preg_match('/\\{\\"msg_item\\":\\[(.*)\\]\\}/', $result, $matches)) {
         $objectres = json_decode($matches[0]);
         $mongoClient = new MongoUtil("testwechat");
         foreach ($objectres->msg_item as $object) {
             $findres = $mongoClient->finone("message", array("messageid" => $object->id));
             if (!isset($findres)) {
                 $doc = array("messageid" => $object->id, "fakeid" => $object->fakeid, "nick_name" => $object->nick_name, "content" => $object->content, "date_time" => $object->date_time);
                 $mongoClient->insert("message", $doc);
             } else {
                 break;
             }
         }
     } else {
         print_r($result);
     }
 }