Advertisement
oleghalin

Untitled

Mar 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2. /*
  3. * MyUCP
  4. * File Version 4.0
  5. * Date: 30.03.2015
  6. * Developed by Maksa988
  7. */
  8.  
  9. class vkAuth {
  10. private $client_id;
  11. private $client_secret;
  12. private $redirect_uri;
  13. private $authurl;
  14. private $getFields;
  15.  
  16. private $OAuthURL = 'http://oauth.vk.com/';
  17.  
  18.  
  19. function __set($name,$value) {
  20. if($name == 'data')
  21. {
  22. $this->init($value['client_id'],$value['client_secret'],$value['redirect_uri'],$value['authurl'],$value['getFields'])
  23. }
  24. }
  25. protected function init($client_id,$client_secret,$redirect_uri,$authurl = "/", $getFields = "uid,first_name,last_name,screen_name,sex,bdate,photo_big")
  26. {
  27. $this->client_id = $client_id;
  28. $this->client_secret = $client_secret;
  29. $this->redirect_uri = $redirect_uri;
  30.  
  31. if(is_array($getFields))
  32. $this->getFields = implode(",", $getFields);
  33. else
  34. $this->getFields = $getFields;
  35.  
  36. $this->authurl = $authurl;
  37. }
  38. public function getAuthUrl()
  39. {
  40. $params = array(
  41. 'client_id' => $this->client_id,
  42. 'redirect_uri' => $this->redirect_uri,
  43. 'response_type' => 'code'
  44. );
  45. return $this->OAuthURL . '/authorize/?' . urldecode(http_build_query($params));
  46.  
  47. }
  48. public function getUser($code)
  49. {
  50. if (isset($_GET['code'])) {
  51. $params = array(
  52. 'client_id' => $this->client_id,
  53. 'client_secret' => $this->client_secret,
  54. 'code' => $code,
  55. 'redirect_uri' => $this->redirect_uri
  56. );
  57.  
  58. $token = json_decode(file_get_contents($this->OAuthURL.'/access_token' . '?' . urldecode(http_build_query($params))), true);
  59.  
  60. if (isset($token['access_token'])) {
  61. $params = array(
  62. 'uids' => $token['user_id'],
  63. 'fields' => $this->getFields,
  64. 'access_token' => $token['access_token']
  65. );
  66.  
  67. $userInfo = json_decode(file_get_contents('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true);
  68. if (isset($userInfo['response'][0]['uid'])) {
  69. return $userInfo['response'][0];
  70. }
  71. }
  72. }
  73. }
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement