Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * MyUCP
- * File Version 4.0
- * Date: 30.03.2015
- * Developed by Maksa988
- */
- class vkAuth {
- private $client_id;
- private $client_secret;
- private $redirect_uri;
- private $authurl;
- private $getFields;
- private $OAuthURL = 'http://oauth.vk.com/';
- function __set($name,$value) {
- if($name == 'data')
- {
- $this->init($value['client_id'],$value['client_secret'],$value['redirect_uri'],$value['authurl'],$value['getFields'])
- }
- }
- protected function init($client_id,$client_secret,$redirect_uri,$authurl = "/", $getFields = "uid,first_name,last_name,screen_name,sex,bdate,photo_big")
- {
- $this->client_id = $client_id;
- $this->client_secret = $client_secret;
- $this->redirect_uri = $redirect_uri;
- if(is_array($getFields))
- $this->getFields = implode(",", $getFields);
- else
- $this->getFields = $getFields;
- $this->authurl = $authurl;
- }
- public function getAuthUrl()
- {
- $params = array(
- 'client_id' => $this->client_id,
- 'redirect_uri' => $this->redirect_uri,
- 'response_type' => 'code'
- );
- return $this->OAuthURL . '/authorize/?' . urldecode(http_build_query($params));
- }
- public function getUser($code)
- {
- if (isset($_GET['code'])) {
- $params = array(
- 'client_id' => $this->client_id,
- 'client_secret' => $this->client_secret,
- 'code' => $code,
- 'redirect_uri' => $this->redirect_uri
- );
- $token = json_decode(file_get_contents($this->OAuthURL.'/access_token' . '?' . urldecode(http_build_query($params))), true);
- if (isset($token['access_token'])) {
- $params = array(
- 'uids' => $token['user_id'],
- 'fields' => $this->getFields,
- 'access_token' => $token['access_token']
- );
- $userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true);
- if (isset($userInfo['response'][0]['uid'])) {
- return $userInfo['response'][0];
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement