Browse Source

fixed issue #76 and merge #67

dodgepudding 11 years ago
parent
commit
c4c8186fe1
4 changed files with 64 additions and 3 deletions
  1. 12 2
      Thinkphp/Wechat.class.php
  2. 20 0
      Thinkphp/Wechatext.class.php
  3. 12 1
      wechat.class.php
  4. 20 0
      wechatext.class.php

+ 12 - 2
Thinkphp/Wechat.class.php

@@ -109,8 +109,7 @@ class Wechat
 		$token = $this->token;
 		$tmpArr = array($token, $timestamp, $nonce);
 
-    # 把值作为字符串来处理
-    sort($tmpArr, SORT_STRING);
+	    sort($tmpArr, SORT_STRING);
 
 		$tmpStr = implode( $tmpArr );
 		$tmpStr = sha1( $tmpStr );
@@ -361,6 +360,17 @@ class Wechat
 			return false;
 	}
 	
+	/**
+	* 获取二维码的场景值
+	*/
+	public function getRevSceneId (){
+		if (isset($this->_receive['EventKey'])){
+			return str_replace('qrscene_','',$this->_receive['EventKey']);
+		} else{
+			return false;
+		}
+	}
+	
 	public static function xmlSafeStr($str)
 	{   
 		return '<![CDATA['.preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/",'',$str).']]>';   

+ 20 - 0
Thinkphp/Wechatext.class.php

@@ -404,6 +404,26 @@ class Wechatext
 	}
 	
 	/**
+	 * 获得头像数据
+	 *
+	 * @param FakeId $fakeid
+	 * @return JPG二进制数据
+	 */
+	public function getHeadImg($fakeid){
+		$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;
+		$url = "https://mp.weixin.qq.com/cgi-bin/getheadimg?fakeid=$fakeid&token=".$this->_token."&lang=zh_CN";
+		$send_snoopy->fetch($url);
+		$result = $send_snoopy->results;
+		$this->log('Head image:'.$fakeid.'; length:'.strlen($result));
+		if(!$result){
+			return false;
+		}
+		return $result;
+	}
+	
+	/**
 	 * 获取消息更新数目
 	 * @param int $lastid 最近获取的消息ID,为0时获取总消息数目
 	 * @return int 数目

+ 12 - 1
wechat.class.php

@@ -107,7 +107,7 @@ class Wechat
         		
 		$token = $this->token;
 		$tmpArr = array($token, $timestamp, $nonce);
-		sort($tmpArr);
+		sort($tmpArr, SORT_STRING);
 		$tmpStr = implode( $tmpArr );
 		$tmpStr = sha1( $tmpStr );
 		
@@ -352,6 +352,17 @@ class Wechat
 		return false;
     }
 	
+    /**
+     * 获取二维码的场景值
+     */
+    public function getRevSceneId (){
+    	if (isset($this->_receive['EventKey'])){
+    		return str_replace('qrscene_','',$this->_receive['EventKey']);
+    	} else{
+    		return false;
+    	}
+    }
+    
 	public static function xmlSafeStr($str)
 	{   
 		return '<![CDATA['.preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/",'',$str).']]>';   

+ 20 - 0
wechatext.class.php

@@ -404,6 +404,26 @@ class Wechatext
 		}
 		return false;
 	}
+	
+	/**
+	 * 获得头像数据
+	 *
+	 * @param FakeId $fakeid
+	 * @return JPG二进制数据
+	 */
+	public function getHeadImg($fakeid){
+		$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;
+		$url = "https://mp.weixin.qq.com/cgi-bin/getheadimg?fakeid=$fakeid&token=".$this->_token."&lang=zh_CN";
+		$send_snoopy->fetch($url);
+		$result = $send_snoopy->results;
+		$this->log('Head image:'.$fakeid.'; length:'.strlen($result));
+		if(!$result){
+			return false;
+		}
+		return $result;
+	}
 
 	/**
 	 * 获取消息更新数目