Browse Source

公众号类 增加一个验证,防止不设置回复内容直接调用reply方法导致报错

binsee 10 years ago
parent
commit
8396fd0552
2 changed files with 11 additions and 2 deletions
  1. 7 1
      Thinkphp/Wechat.class.php
  2. 4 1
      wechat.class.php

+ 7 - 1
Thinkphp/Wechat.class.php

@@ -285,6 +285,9 @@ class Wechat
     		}
     }
 
+    /**
+     * 设置消息的星标标志,官方已取消对此功能的支持
+     */
     public function setFuncFlag($flag) {
     		$this->_funcflag = $flag;
     		return $this;
@@ -971,8 +974,11 @@ class Wechat
 	 */
 	public function reply($msg=array(),$return = false)
 	{
-		if (empty($msg))
+		if (empty($msg)) {
+		    if (empty($this->_msg))   //防止不先设置回复内容,直接调用reply方法导致异常
+		        return false;
 			$msg = $this->_msg;
+		}
 		$xmldata=  $this->xml_encode($msg);
 		$this->log($xmldata);
 		if ($this->encrypt_type == 'aes') { //如果来源消息为加密方式

+ 4 - 1
wechat.class.php

@@ -969,8 +969,11 @@ class Wechat
 	 */
 	public function reply($msg=array(),$return = false)
 	{
-		if (empty($msg))
+		if (empty($msg)) {
+		    if (empty($this->_msg))   //防止不先设置回复内容,直接调用reply方法导致异常
+		        return false;
 			$msg = $this->_msg;
+		}
 		$xmldata=  $this->xml_encode($msg);
 		$this->log($xmldata);
 		if ($this->encrypt_type == 'aes') { //如果来源消息为加密方式