Commit 87385a10 authored by Alex Ne's avatar Alex Ne

VKAPI

parent 64b3e548
<?php
namespace X\Social\VK;
class CredentialsClientIdError extends \X\ETrace\System {}
class CredentialsClientSecretError extends \X\ETrace\System {}
class Credentials {
/**
......@@ -10,17 +12,17 @@ class Credentials {
* @param $client_id
* @param $client_secret
*/
public function __construct($client_id, $client_secret, $api_version = "5.28") {
public function __construct($client_id, $client_secret, $api_version = "5.52") {
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]);
throw new CredentialsClientIdError("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]);
throw new CredentialsClientSecretError("VK Client Secret not string or len =< 0", 0, ["client_secret" => $client_secret]);
}
$this->api_version = $api_version;
}
......
......@@ -2,11 +2,17 @@
namespace X\Social\VK;
class Secure {
/**
* @var mixed
*/
private $ServerToken;
/**
* @param \X\Social\VK\Credentials $Credentials
* @param string $ServerToken
*/
public function __construct($Credentials = null) {}
public function __construct($ServerToken) {
$this->server_token = $server_token;
}
# secure.getAppBalance
# Возвращает платежный баланс (счет) приложения в сотых долях голоса.
......@@ -22,50 +28,94 @@ class Secure {
# secure.getSMSHistory
# Выводит список SMS-уведомлений, отосланных приложением с помощью метода secure.sendSMSNotification.
public function getSMSHistory() {
/**
* @param int $user_id
* @param unixtime $date_from
* @param unixtime $date_to
* @param int $limit
*/
public function getSMSHistory($user_id, $date_from, $date_to, $limit = 1000) {
# code...
}
# secure.sendSMSNotification
# Отправляет SMS-уведомление на мобильный телефон пользователя.
public function sendSMSNotification() {
/**
* @param int $user_id
* @param string $message
*/
public function sendSMSNotification($user_id, $message) {
# code...
}
# secure.sendNotification
# Отправляет уведомление пользователю.
public function sendNotification() {
/**
* @param string $user_ids - идентификаторы через зяпятую: "13б,4563465,2345245". Max 100 users
* @param int $user_id
* @param string $message
*/
public function sendNotification($user_ids, $user_id, $message) {
# code...
}
# secure.setCounter
# Устанавливает счетчик, который выводится пользователю жирным шрифтом в левом меню.
public function setCounter() {
/**
* @param string $counters - user_id1:counter1,user_id2:counter2. Max 200 items
* @param int $user_id
* @param int $counter
*/
public function setCounter($counters, $user_id, $counter) {
# code...
}
# secure.setUserLevel
# Устанавливает игровой уровень пользователя в приложении, который смогут увидеть его друзья.
public function setUserLevel() {
/**
* @param $levels - user_id1:level1,user_id2:level2, пример: 66748:6,6492:2. Max 200 items
* @param $user_id
* @param $level
*/
public function setUserLevel($levels, $user_id, $level) {
# code...
}
# secure.getUserLevel
# Возвращает ранее выставленный игровой уровень одного или нескольких пользователей в приложении.
public function getUserLevel() {
/**
* @param string $user_ids - userid1,userid2,userid3,
*/
public function getUserLevel($user_ids) {
# code...
}
# secure.addAppEvent
# Добавляет информацию о достижениях пользователя в приложении.
public function addAppEvent() {
/**
* @param $user_id
* @param $activity_id
* @param $value
*/
public function addAppEvent($user_id, $activity_id, $value) {
# code...
}
# secure.checkToken
# Позволяет проверять валидность пользователя в IFrame, Flash и Standalone-приложениях с помощью передаваемого в приложения параметра access_token.
public function checkToken() {
/**
* @param $token
* @param $ip
*/
public function checkToken($token, $ip = null) {
# code...
# В случае успеха будет возвращен объект, содержащий следующие поля:
# success = 1
# user_id = идентификатор пользователя
# date = unixtime дата, когда access_token был сгенерирован
# expire = unixtime дата, когда access_token станет не валиден
}
}
?>
\ No newline at end of file
<?php
namespace X\Social\VK;
class getServerTokenError extends \X\ETrace\System {}
class ServerToken extends VKAPI {
/**
* @var string
*/
private $oauth_url = "https://oauth.vk.com/";
/**
* @var mixed
*/
private $server_token;
/**
* @param \X\Social\VK\Credentials $Credentials
*/
public function __construct($Credentials = null) {
# code...
parent::__construct($Credentials);
$this->request();
}
private function request() {
$params["client_id"] = $this->Credentials->get_client_id();
$params["client_secret"] = $this->Credentials->get_client_secret();
$params["grant_type"] = "client_credentials";
$params["v"] = $this->Credentials->get_api_version();
$data = $this->query($oauth_url . "access_token?" . $params);
if (isset($data["access_token"])) {
$this->server_token = $data["access_token"];
} else {
throw new getServerTokenError("VK: get server access_token fail", 0, ["params" => $params, "data" => $data]);
}
}
/**
* @return mixed
*/
public function get_token() {
return $this->server_token;
}
}
......
<?php
namespace X\Social\VK;
class VKAPICredentialsIsNull extends \X\ETrace\System {}
class VKAPI {
......@@ -11,7 +12,7 @@ class VKAPI {
/**
* @var \X\Social\VK\Credentials
*/
private $Credentials;
protected $Credentials;
/**
* @var string
......@@ -29,7 +30,7 @@ class VKAPI {
}
if (is_null($this->Credentials)) {
throw new \X\ETrace\System("VK Credentials is NULL", 0);
throw new VKAPICredentialsIsNull("VK Credentials is NULL", 0);
}
}
......@@ -38,9 +39,15 @@ class VKAPI {
* @param array $params
* @return array
*/
public function api($method, $params = []) {
public function api($method, $params = []) {}
$Client = new \X\Network\Http\Client($this->api_url . "/" . $method);
/**
* @param $url
* @param $params
* @return array
*/
protected function query($url, $params) {
$Client = new \X\Network\Http\Client($url);
$Client->set_model_data(["post" => $params]);
if ($data = $Client->exec()->json_decode()) {
return $data;
......
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