devServer: {
proxy: {
'/api': 'http://localhost:3000'
}
}
/* start */
SELECT comment FROM baza ORDER BY id DESC limit 0, 3
/* 1 click show more */
SELECT comment FROM baza ORDER BY id DESC limit 3, 3
/* 2 click show more */
SELECT comment FROM baza ORDER BY id DESC limit 6, 3
$tmp = '{"ok":true,"result":{"message_id":45,"chat":{"id":-1001220061819,"title":"Test_channel","username":"testldasasd","type":"channel"},"date":1554636998,"photo":[{"file_id":"AgADBAADzagxG360VFHIPPb3hmpSXDkBLRsABMiOIyUl07R4Y5UCAAEC","file_size":1938,"width":90,"height":90},{"file_id":"AgADBAADzagxG360VFHIPPb3hmpSXDkBLRsABFNMe6LznfP8ZJUCAAEC","file_size":28529,"width":319,"height":320},{"file_id":"AgADBAADzagxG360VFHIPPb3hmpSXDkBLRsABMaa3B3X6gYXZZUCAAEC","file_size":74939,"width":554,"height":555}],"caption":"\u0411\u043b\u043e\u043a\u043d\u043e\u0442 \n\ud83d\udc49http://ali.pub/39kqrl\n\ud83d\udcb0 \u0426\u0435\u043d\u0430: 49,26 \u20bd\n#\u041e\u0444\u0438\u0441\u043d\u044b\u0435_\u0438_\u0448\u043a\u043e\u043b\u044c\u043d\u044b\u0435_\u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \n#\u0417\u0430\u043f\u0438\u0441\u043d\u044b\u0435_\u043a\u043d\u0438\u0433\u0438_\u0438_\u0431\u043b\u043e\u043a\u043d\u043e\u0442\u044b\n#\u0414\u0435\u0448\u0435\u0432\u043b\u0435_300\u0420","caption_entities":[{"offset":11,"length":21,"type":"url"},{"offset":50,"length":34,"type":"hashtag"},{"offset":86,"length":26,"type":"hashtag"},{"offset":113,"length":13,"type":"hashtag"}]}}';
$tmpArray = json_decode($tmp, true);
echo $tmpArray['result']['date'];
class Model_Vk {
private $access_token;
private $url = "https://api.vk.com/method/";
/**
* Конструктор
*/
public function __construct($access_token) {
$this->access_token = $access_token;
}
/**
* Делает запрос к Api VK
* @param $method
* @param $params
*/
public function method($method, $params = null) {
$p = "";
if( $params && is_array($params) ) {
foreach($params as $key => $param) {
$p .= ($p == "" ? "" : "&") . $key . "=" . urlencode($param);
}
}
$response = file_get_contents($this->url . $method . "?" . ($p ? $p . "&" : "") . "access_token=" . $this->access_token);
if( $response ) {
return json_decode($response);
}
return false;
}
public function uploadImage($file, $group_id = null, $album_id = null) {
$params = array();
if( $group_id ) {
$params['group_id'] = $group_id;
}
if( $album_id ) {
$params['album_id'] = $album_id;
}
//Получаем сервер для загрузки изображения
$response = $this->method("photos.getUploadServer", $params);
if( isset($response) == false ) {
print_r($response);
exit;
}
$server = $response->response->upload_url;
$postparam=array("file1"=>"@".$file);
//Отправляем файл на сервер
$ch = curl_init($server);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postparam);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data; charset=UTF-8'));
$json = json_decode(curl_exec($ch));
curl_close($ch);
//Сохраняем файл в альбом
$photo = $this->method("photos.save", array(
"server" => $json->server,
"photos_list" => $json->photos_list,
"album_id" => $album_id,
"hash" => $json->hash,
'gid' => $group_id
));
if( isset($photo->response[0]->id) ) {
return $photo->response[0]->id;
} else {
return false;
}
}
}
$access_token = "токен";
$group_id = "ид группы";
$album_id = 'ид альбома в который будем грузить';
$image_path = путь к файлу;
$vk = new Model_Vk($access_token);
//Загружаем изображение
$upload_img = $vk->uploadImage($image_path,$group_id,$album_id);