Advertisement
wnull

Untitled

Oct 20th, 2018
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2.  
  3. /* by Let's say Pie a.k.a. Vasily Pirajog [20/10/2018 19:00] */
  4.  
  5. $group_id     = '162947920';
  6. $access_token = '1f16e77a65f0adf6eec18dba97f3ccf5c1f4d4dde272c03f602eabec8e29155e032044ed763f68a3e8216';
  7. $message      = 'Hello, world!';
  8. $image        = 'img/corgiya18.jpg';
  9.  
  10. $url = vk('photos.getWallUploadServer', [
  11.     'group_id' => $group_id,
  12.     'v' => '5.85',
  13.     'access_token' => $access_token
  14. ])->response->upload_url; // Обращаемся сразу к <response[upload_url]>
  15.  
  16. if (isset($url))
  17. {
  18.     $upload = json_decode(curl($url, ['photo' => new CURLFile($image)]));
  19.  
  20.     if (isset($upload->server))
  21.     {
  22.         $save = vk('photos.saveWallPhoto', [
  23.             'group_id' => $group_id,
  24.             'server' => $upload->server,
  25.             'access_token' => $access_token,
  26.             'hash' => $upload->hash,
  27.             'photo' => $upload->photo,
  28.             'v' => '5.85'
  29.         ])->response[0]; // Обращаемся сразу к <response[0]>
  30.  
  31.         if (isset($save))
  32.         {
  33.             $post = vk('wall.post', [
  34.                 'owner_id' => '-'.$group_id,
  35.                 'access_token' => $access_token,
  36.                 'from_group' => 1,
  37.                 'message' => $message,
  38.                 'attachments' => 'photo'.$save->owner_id.'_'.$save->id,
  39.                 'v' => '5.85'
  40.             ]);
  41.  
  42.             print_r($post);
  43.         }
  44.     }
  45. }
  46.  
  47. function vk($method, $params)
  48. {
  49.     return json_decode(curl('https://api.vk.com/method/'.$method, $params));
  50. }
  51.  
  52. function curl($url, $params = false)
  53. {
  54.     $ch = curl_init($url);
  55.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  56.  
  57.     if (isset($params))
  58.     {
  59.         curl_setopt($ch, CURLOPT_POST, 1);
  60.         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  61.     }
  62.  
  63.     $upd = curl_exec($ch);
  64.     curl_close($ch);
  65.  
  66.     return $upd;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement