Commit 64b3e548 authored by Alex Ne's avatar Alex Ne

Скелет функционала взаимодействия с ВКонтакте

parent 1ac9e626
<?php
namespace X\Social;
class VK {
/**
* @var string
*/
protected $api_url = "";
public function __construct() {}
/**
* @param string $method
* @param array $params
*/
public function api($method, $params = []) {
$Client = new \X\Network\Http\Client($this->api_url . "/" . $method);
$Client->set_model_data(["post" => $params]);
if ($data = $Client->exec()->json_decode()) {
return $data;
}
return;
}
}?>
\ No newline at end of file
<?php
namespace X\Social\VK;
class Credentials {
/**
* @var mixed
*/
private $client_id, $client_secret, $api_version;
/**
* @param $client_id
* @param $client_secret
*/
public function __construct($client_id, $client_secret, $api_version = "5.28") {
if (is_numeric($client_id) && $client_id > 0) {
$this->client_id = $client_id;
} else {
throw new \X\ETrace\System("VK Client ID not numeric or not > 0", 0, ["client_id" => $client_id]);
}
if (is_string($client_secret) && strlen($client_secret) > 0) {
$this->client_secret = $client_secret;
} else {
throw new \X\ETrace\System("VK Client Secret not string or len =< 0", 0, ["client_secret" => $client_secret]);
}
$this->api_version = $api_version;
}
/**
* @return int
*/
public function get_client_id() {
return $this->client_id;
}
/**
* @return string
*/
public function get_client_secret() {
return $this->client_secret;
}
/**
* @return string
*/
public function get_api_version() {
return $this->api_version;
}
}
?>
\ No newline at end of file
<?php
namespace X\Social\VK;
class Secure {
/**
* @param \X\Social\VK\Credentials $Credentials
*/
public function __construct($Credentials = null) {}
# secure.getAppBalance
# Возвращает платежный баланс (счет) приложения в сотых долях голоса.
public function getAppBalance() {
# code...
}
# secure.getTransactionsHistory
# Выводит историю транзакций по переводу голосов между пользователями и приложением.
public function getTransactionsHistory() {
# code...
}
# secure.getSMSHistory
# Выводит список SMS-уведомлений, отосланных приложением с помощью метода secure.sendSMSNotification.
public function getSMSHistory() {
# code...
}
# secure.sendSMSNotification
# Отправляет SMS-уведомление на мобильный телефон пользователя.
public function sendSMSNotification() {
# code...
}
# secure.sendNotification
# Отправляет уведомление пользователю.
public function sendNotification() {
# code...
}
# secure.setCounter
# Устанавливает счетчик, который выводится пользователю жирным шрифтом в левом меню.
public function setCounter() {
# code...
}
# secure.setUserLevel
# Устанавливает игровой уровень пользователя в приложении, который смогут увидеть его друзья.
public function setUserLevel() {
# code...
}
# secure.getUserLevel
# Возвращает ранее выставленный игровой уровень одного или нескольких пользователей в приложении.
public function getUserLevel() {
# code...
}
# secure.addAppEvent
# Добавляет информацию о достижениях пользователя в приложении.
public function addAppEvent() {
# code...
}
# secure.checkToken
# Позволяет проверять валидность пользователя в IFrame, Flash и Standalone-приложениях с помощью передаваемого в приложения параметра access_token.
public function checkToken() {
# code...
}
}
?>
\ No newline at end of file
<?php
namespace X\Social\VK;
class ServerToken extends VKAPI {
/**
* @param \X\Social\VK\Credentials $Credentials
*/
public function __construct($Credentials = null) {
# code...
}
}
?>
\ No newline at end of file
<?php
namespace X\Social\VK;
class VKAPI {
/**
* @var \X\Social\VK\Credentials
*/
static $GlobalCredentials = null;
/**
* @var \X\Social\VK\Credentials
*/
private $Credentials;
/**
* @var string
*/
private $api_url;
/**
* @param \X\Social\VK\Credentials $Credentials
*/
public function __construct($Credentials = null) {
if (is_null($Credentials)) {
$this->Credentials = self::$GlobalCredentials;
} else {
$this->Credentials = $Credentials;
}
if (is_null($this->Credentials)) {
throw new \X\ETrace\System("VK Credentials is NULL", 0);
}
}
/**
* @param string $method
* @param array $params
* @return array
*/
public function api($method, $params = []) {
$Client = new \X\Network\Http\Client($this->api_url . "/" . $method);
$Client->set_model_data(["post" => $params]);
if ($data = $Client->exec()->json_decode()) {
return $data;
}
return;
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment