Call to a member function valid() on boolean这是出了什么错误?
我把一段代码从thinkphp 3.1 移植到 thinkphp 3.2 ,然后调整的时候出现了这么一个错误,找了好多都没找到。
<code>public function init() { $config = M ( "Wxconfig" )->where ( array ( "id" => "1" ) )->find (); $options = array ( 'token' => $config ["token"], // 填写你设定的key 'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey 'appid' => $config ["appid"], // 填写高级调用功能的app id 'appsecret' => $config ["appsecret"], // 填写高级调用功能的密钥 ); $weObj = A('Api/Wechat ( $options )'); return $weObj; } public function index() { $weObj = $this->init(); $weObj -> valid (); </code>
下面是Api/Wechat中的那个 valid方法:
<code>/** * For weixin server validation * @param bool $return 是否返回 */ public function valid($return=false) { $encryptStr=""; if ($_SERVER['REQUEST_METHOD'] == "POST") { $postStr = file_get_contents("php://input"); $array = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"]: ''; if ($this->encrypt_type == 'aes') { //aes加密 $this->log($postStr); $encryptStr = $array['Encrypt']; $pc = new Prpcrypt($this->encodingAesKey); $array = $pc->decrypt($encryptStr,$this->appid); if (!isset($array[0]) || ($array[0] != 0)) { if (!$return) { die('decrypt error!'); } else { return false; } } $this->postxml = $array[1]; if (!$this->appid) $this->appid = $array[2];//为了没有appid的订阅号。 } else { $this->postxml = $postStr; } } elseif (isset($_GET["echostr"])) { $echoStr = $_GET["echostr"]; if ($return) { if ($this->checkSignature()) return $echoStr; else return false; } else { if ($this->checkSignature()) die($echoStr); else die('no access'); } } if (!$this->checkSignature($encryptStr)) { if ($return) return false; else die('no access'); } return true; } </code>
这是什么问题TAT
回复内容:
我把一段代码从thinkphp 3.1 移植到 thinkphp 3.2 ,然后调整的时候出现了这么一个错误,找了好多都没找到。
<code>public function init() { $config = M ( "Wxconfig" )->where ( array ( "id" => "1" ) )->find (); $options = array ( 'token' => $config ["token"], // 填写你设定的key 'encodingaeskey' => $config ["encodingaeskey"], // 填写加密用的EncodingAESKey 'appid' => $config ["appid"], // 填写高级调用功能的app id 'appsecret' => $config ["appsecret"], // 填写高级调用功能的密钥 ); $weObj = A('Api/Wechat ( $options )'); return $weObj; } public function index() { $weObj = $this->init(); $weObj -> valid (); </code>
下面是Api/Wechat中的那个 valid方法:
<code>/** * For weixin server validation * @param bool $return 是否返回 */ public function valid($return=false) { $encryptStr=""; if ($_SERVER['REQUEST_METHOD'] == "POST") { $postStr = file_get_contents("php://input"); $array = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"]: ''; if ($this->encrypt_type == 'aes') { //aes加密 $this->log($postStr); $encryptStr = $array['Encrypt']; $pc = new Prpcrypt($this->encodingAesKey); $array = $pc->decrypt($encryptStr,$this->appid); if (!isset($array[0]) || ($array[0] != 0)) { if (!$return) { die('decrypt error!'); } else { return false; } } $this->postxml = $array[1]; if (!$this->appid) $this->appid = $array[2];//为了没有appid的订阅号。 } else { $this->postxml = $postStr; } } elseif (isset($_GET["echostr"])) { $echoStr = $_GET["echostr"]; if ($return) { if ($this->checkSignature()) return $echoStr; else return false; } else { if ($this->checkSignature()) die($echoStr); else die('no access'); } } if (!$this->checkSignature($encryptStr)) { if ($return) return false; else die('no access'); } return true; } </code>
这是什么问题TAT
$weObj = A('Api/Wechat ( $options )');
Thinkphp A 函数不是这样调用吧
意思是说现在版本的TP的init方法在你这里的代码中没有返回对象,而是返回了布尔值,很可能是false;
跟踪一下3.2版本的A方法:

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写
