Была поставлена задача, написать скрипт(на классах) для взаимодействия с внешними источниками данных в сети интернет, я написал вот такой код
<?php
class Wallet
{
const POST_REQUEST = 1;
const GET_REQUEST = 0;
private $params = [];
private $token;
private $uri;
private $REQUEST_METHOD;
private $phone;
public function __construct($token, $phone)
{
$this->token=$token;
$this->phone=$phone;
}
public function request()
{
$this->params = [
CURLOPT_URL => 'https://edge.qiwi.com/'.$this->uri,
CURLOPT_POST => Wallet::GET_REQUEST,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer ' . $this->token,
'Host: edge.qiwi.com']
];
if($this->REQUEST_METHOD==1){
$this->params = [
CURLOPT_URL => 'https://edge.qiwi.com/'.$this->uri,
CURLOPT_POST => $this->REQUEST_METHOD,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_HTTPHEADER => [
'Accept: text/css,*/*;q=0.1',
'Content-Type: application/json',
'Authorization: Bearer ' . $this->token,
'Host: edge.qiwi.com']
];
};
$ch = curl_init();
curl_setopt_array($ch,$this->params);
if($err = curl_errno($ch)) {
$error_message = curl_strerror($err);
die("cURL error ({$err}):\n {$error_message}");
};
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data);
}
public function uriBalance()
{
$this->uri='funding-sources/v2/persons/'.$this->phone.'/accounts';
$this->REQUEST_METHOD=Wallet::GET_REQUEST;
return Wallet::request();
}
}
class User
{
private $_token;
private $_phoneNmbr;
public function __construct($_token, int $_phoneNmbr)
{
$this->_token=$_token;
$this->_phoneNmbr=$_phoneNmbr;
}
public function getToken(){return $this->_token;}
public function getPhoneNmbr(){return $this->_phoneNmbr;}
}
/////////////////Init/////////////////////////
$uWallet = new User('33188280000000', '7950000000');
$token=$uWallet->getToken();
$phone=$uWallet->getPhoneNmbr();
/////////////////////////////////////////////
/////////////////getData/////////////////////
$objWallet = new Wallet($token,$phone);
$walletBalance = $objWallet->uriBalance();
/////////////////////////////////////////////
//////////////// debug///////////////////////
echo "<pre>";
var_dump($walletBalance->accounts[0]->balance->amount);
На вопрос почему переделать, учитель говорит, что код не работает, но у меня все работает. Подскажите где ошибка?