Advertisement
nullius

vk poster

Jul 20th, 2011
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.23 KB | None | 0 0
  1. <?php
  2.  
  3. sendVk("опаопа");
  4.  
  5. function sendVK($message) {
  6.     $user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.2.13) ' .
  7.     'Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729)';
  8.     $cookie = '';
  9.     $login = 'my_login';            // изменить
  10.     $password = 'my_pass';          //
  11.     $group_page = 'http://vk.com/my_page';  //
  12.  
  13.     /**
  14.     * Логинимся
  15.     */
  16.     $answer = auth($login, $password);
  17.     /**
  18.     * Получаем ид сессии и куки
  19.     */
  20.     $sid = substr($answer, strpos($answer, "setCookieEx('sid', '") + 20, 60);
  21.     $cookie = 'remixsid=' . $sid;
  22.     /**
  23.     * Получаем страницу
  24.     */
  25.     $page = getPage($group_page, $cookie);
  26.  
  27.     sendPost($page,$message, $cookie);
  28. }
  29.  
  30. function sendPost($page, $message, $cookie) {
  31.     $post_hash = substr($page, strpos($page, '"post_hash":"') + 13, 18);
  32.     $group_id = substr($page, strpos($page, '"group_id":') + 11, 7);
  33.  
  34.     $ch = curl_init();
  35.  
  36.     $fields = "act=post&al=1&hash={$post_hash}&message={$message}&to_id=-{$group_id}&type=all&official=1";
  37.  
  38.     curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  39.     curl_setopt($ch, CURLOPT_POST, true);
  40.     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  41.     curl_setopt($ch, CURLOPT_URL, 'http://vk.com/al_wall.php');
  42.  
  43.     ob_start();
  44.     $answer = curl_exec($ch);
  45.     ob_end_clean();
  46. }
  47.  
  48. function auth($login, $password) {
  49.     $ch = curl_init();
  50.  
  51.     curl_setopt($ch, CURLOPT_POST, true);
  52.     curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  53.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  54.     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  55.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  56.     curl_setopt($ch, CURLOPT_URL, 'http://login.vk.com/?act=login');
  57.     $post = array(
  58.     'act' => 'login',
  59.     'q' => '',
  60.     'al_frame' => '1',
  61.     'expire' => '',
  62.     'captcha_sid' => '',
  63.     'captcha_key' => '',
  64.     'from_host' => 'vkontakte.ru',
  65.     'email' => $login,
  66.     'pass' => $password
  67.     );
  68.  
  69.     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
  70.  
  71.     $answer = curl_exec($ch);
  72.    
  73.     return $answer;
  74. }
  75.  
  76. function getPage($url, $cookie) {
  77.     $ch = curl_init();
  78.  
  79.     curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  80.     curl_setopt($ch, CURLOPT_POST, true);
  81.     curl_setopt($ch, CURLOPT_URL, $url);
  82.  
  83.     ob_start();
  84.     curl_exec($ch);
  85.     $answer = ob_get_contents();
  86.     ob_end_clean();
  87.    
  88.     return $answer;
  89. }
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement