def get_button(label, color, payload):
return {
"action": {
"type": "text",
"payload": json.dumps(payload),
"label": label
},
"color": color
}
keyboard = {
"one_time": False,
"buttons": [
[
get_button(label="Кнопка 1", color="positive", payload="{\"button\":\"1\"}"),
get_button(label="Кнопка 2", color="negative", payload="{\"button\":\"1\"}"),
get_button(label="Кнопка 3", color="primary", payload="{\"button\":\"1\"}"),
get_button(label="Кнопка 4", color="negative", payload="{\"button\":\"1\"}")
]
]
}
keyboard = json.dumps(keyboard, ensure_ascii=False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))
id = "151713772"
vk.method("messages.send", {"peer_id": id, "message": "Открыто главное меню!", "keyboard": keyboard,
"random_id": random.randint(1, 2147483647),"v": '5.101'})
$url = 'https://pp.userapi.com/c837420/v837420161/740a/GEjykJJjhkA.jpg';
$dir = __DIR__ . "/image";
$name = '1.jpg';
copy($url, $dir . DIRECTORY_SEPARATOR . $name);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$result = json_decode(curl_exec($ch),true);
print_r($result);
{$result['photos_list']}
<?php
// Только STANDALONE TOKEN
$token = 'token';
$group_id = 'id';
$album_id = 'id';
$v = '5.62'; //версия vk api
$image_path = dirname(__FILE__).'/111.jpg';//путь до картинки
$post_data = array("file1" => '@'.$image_path);
// получаем урл для загрузки
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$album_id}&group_id={$group_id}&v={$v}&access_token={$token}");
$url = json_decode($url)->response->upload_url;
print_r(json_decode($url));
print_r($url);
// отправка post картинки
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = json_decode(curl_exec($ch),true);
print_r($result);
// сохраняем
$safe = file_get_contents("https://api.vk.com/method/photos.save?server=".$result['server']."&photos_list=".$result['photos_list']."&album_id=".$result['aid']."&hash=".$result['hash']."&gid=".$group_id."&access_token=".$token);
$safe = json_decode($safe,true);
print_r($safe);
// итог
?>