素材牛VIP会员
Call to a member function valid() on boolean这是出了什么错误?
 旧****  分类:ThinkPHP  人气:1296  回帖:2  发布于6年前 收藏

我把一段代码从thinkphp 3.1 移植到 thinkphp 3.2 ,然后调整的时候出现了这么一个错误,找了好多都没找到。

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 ();

下面是Api/Wechat中的那个 valid方法:

/**
     * 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;
    }

这是什么问题TAT

 标签:thinkphpphp

讨论这个帖子(2)垃圾回帖将一律封号处理……

Lv1 新人
陈***1 学生 6年前#1

$weObj = A('Api/Wechat ( $options )');

Thinkphp A 函数不是这样调用吧

Lv2 入门
青***f 页面重构设计 6年前#2

意思是说现在版本的TP的init方法在你这里的代码中没有返回对象,而是返回了布尔值,很可能是false;

跟踪一下3.2版本的A方法:

 文明上网,理性发言!   😉 阿里云幸运券,戳我领取