-1

我是 OOP 的新手,所以我可能会遗漏一些东西。我看了一会儿代码,不知道为什么它没有返回任何结果。该类如下(我的 API 密钥是正确的 - 我只是更改了它,因此人们无法访问我的帐户):

<?php

class Inputs {
    private $URL;
    private $Key;
    private $Action;

    public function __construct() {
        $this->URL = 'https://inputs.io/api?key=' . $this->Key;
        $this->Key = '123';
    }

    public function Methods($Action) {
        if($this->Action == 'getbalance') {
            return file_get_contents($this->URL . '&action=getbalance');
        }
    }
}

$Inputs = new Inputs;
print_r($Inputs->Methods('getbalance'));

API 的文档在这里:https ://inputs.io/api

如果不想访问网址,这里有一张图片:http: //puu.sh/4C5uW.png

谢谢。

4

2 回答 2

1

一方面,您在设置需要的 URL 之后设置它们的键!反转构造函数中的这两行。

于 2013-09-28T06:19:24.663 回答
0

如果条件检查似乎是错误的。

Here $this->Action != 'getbalance' & $Action= 'getbalance'. 

使用 $this 来引用当前对象。使用 self 来引用当前类。对非静态成员使用 $this->member,对静态成员使用 self::$member。

于 2013-09-28T06:20:24.277 回答