Код: Выделить всё
//Подключаем класс ВКinclude_once 'vkapi.class.php';$api_id = ID приложения;$secret_key = 'Секретный ключ';//Конструируем класс vk.API$VK = new vkapi($api_id, $secret_key);//Собстевнно сам классclass f { public static function withdrawVotes ($how,$user='NO') { global $_REQUEST,$VK; $vID = $_REQUEST['viewer_id']; if ($user=='NO') $user=$vID; $resp = $VK->api('secure.getBalance', array('timestamp'=>time(), 'random'=>mt_rand(1000000,9999999), 'uid'=>$user)); $balance = $resp['response']; if($resp['response'] >= $how): $resp = $VK->api('secure.withdrawVotes', array( 'timestamp'=>time(), 'random'=>mt_rand(1000000,9999999), 'uid'=>$user, 'votes'=>$how)); if ($resp['response']['350']): return true; else: return false; endif; else: return false; endif; } public static function getBalance ($user='NO') { global $_REQUEST,$VK; $vID = $_REQUEST['viewer_id']; if ($user=='NO') $user=$vID; $resp = $VK->api('secure.getBalance', array('timestamp'=>time(), 'random'=>mt_rand(1000000,9999999), 'uid'=>$user)); if ($user=='APP') $resp = $VK->api('secure.getAppBalance', array('timestamp'=>time(), 'random'=>mt_rand(1000000,9999999))); return $resp['response']; } public static function setCounter ($counter,$user='NO') { global $_REQUEST,$VK; $vID = $_REQUEST['viewer_id']; if ($user=='NO') $user=$vID; $resp = $VK->api('secure.setCounter', array('timestamp'=>time(), 'random'=>mt_rand(1000000,9999999), 'uid'=>$user, 'counter'=>$counter)); } public static function addRating ($rate,$msg='NO',$user='NO') { global $_REQUEST,$VK; $vID = $_REQUEST['viewer_id']; if ($user=='NO') $user=$vID; if ($msg=='NO') $msg='+'.$rate.' рейтинга'; $resp = $VK->api('secure.addRating', array('timestamp'=>time(), 'random'=>mt_rand(1000000,9999999), 'uid'=>$user, 'rate'=>$rate, 'message'=>"$msg")); } public static function sendNotification ($msg='NO',$users='NO') { global $_REQUEST,$VK; $vID = $_REQUEST['viewer_id']; if ($users=='NO') $users=$vID; if ($msg=='NO') $msg='Тестовое сообщение'; $resp = $VK->api('secure.sendNotification', array('timestamp'=>time(), 'random'=>mt_rand(1000000,9999999), 'uids'=>$users, 'message'=>$msg)); } }
Код: Выделить всё
f::addRating('3','+3 рейтинга от приложения flapps');//Добавит рейтинг +3 текущему пользователю