Простенький PHP класс для работы с платформой продаж игр и подписок steampay.com.
Данный класс не подходит для использования в открытых запросах, так как в нём отсутствуют какие либо проверки безопасности
class SteamPay {
var $modes = [
'products' => 'products',
'top' => 'top',
'search' => 'search?query='
];
public function __construct($data) {
$this->data = $data;
$this->url = 'https://steampay.com/api/';
$this->search = false;
$this->result = array();
}
public function SteamPayInit(){
if (array_key_exists($this->data, $this->modes)) {
if ($this->data === 'search') {
$this->search = urlencode($_GET[$this->data]);
}
$this->mode = $this->modes[$this->data] . $this->search;
return $this->GetResult();
}
else return 'Ошибка №1.';
}
public function GetResult() {
return $this->GetContent();
}
public function GetContent() {
stream_context_set_default(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
));
$this->result = file_get_contents($this->BuildQuery());
return $this->DecodeResult();
}
public function BuildQuery() {
return $this->url . $this->mode;
}
public function DecodeResult() {
return json_decode($this->result, true);
}
}
В классе реализованы вывод всех имеющихся в базе steampay игр и промокодов, топ-50, поиск.
Запрос к api:
$SteamPay = new SteamPay('products'); // products, top, search
$SteamPay->SteamPayInit();
Для поиска по базе используем ?search=Xbox.
Внимание. Если решили использовать класс для работы с пользователями, нужно сделать проверку на инъекции и т.д.
На выходе получаем массив данных.