瀏覽代碼

Merge pull request #28 from zhangv/master

#27 fix getTopMsg
dodge 11 年之前
父節點
當前提交
9187ec6d88
共有 1 個文件被更改,包括 11 次插入11 次删除
  1. 11 11
      wechatext.class.php

+ 11 - 11
wechatext.class.php

@@ -304,19 +304,19 @@ class Wechatext
 	 * @return array {"id":"最新一条id","type":"类型号(1为文字,2为图片,3为语音)","fileId":"0","hasReply":"0","fakeId":"用户uid","nickName":"昵称","dateTime":"时间戳","content":"文字内容","playLength":"0","length":"0","source":"","starred":"0","status":"4"}        
 	 */
 	public function getTopMsg(){
-		$send_snoopy = new Snoopy; 
+		$send_snoopy = new Snoopy;
 		$send_snoopy->rawheaders['Cookie']= $this->cookie;
-		$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&lang=zh_CN&count=50&token=".$this->_token;
-		$lastid = $lastid===0 ? '':$lastid;
-		$submit = "https://mp.weixin.qq.com/cgi-bin/getmessage?t=ajax-message&lang=zh_CN&count=1&timeline=0&day=0&star=0&cgi=getmessage&offset=0";
-		$post = array('ajax'=>1,'token'=>$this->_token);
-		$send_snoopy->submit($submit,$post);
+		$send_snoopy->referer = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=20&day=7&lang=zh_CN&token=".$this->_token;
+		$submit = "https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=20&day=7&lang=zh_CN&token=".$this->_token;
+		$send_snoopy->fetch($submit);
 		$this->log($send_snoopy->results);
-		$result = json_decode($send_snoopy->results,1);
-		if($result && count($result)>0)
-			return $result[0];
-		else 
-			return false;
+		$result = $send_snoopy->results;
+		if (preg_match("%list : (.*).msg_item%i", $result, $match)) {
+			$tmp = json_decode(substr($match[1],1,-1));
+			if($tmp && count($tmp)>0)
+				return $tmp->msg_item[0];
+		}
+		return false;
 	}
 	
 	/**