PHP
17
Вклад в тег
function VKaddGoodsOnMarket ($name,$description,$category_id,$price,$photourl) {
$vkToken = '';
$vkGroupID = '';
$vkVersionAPI = '5.60';
//Получаем ссылку для загрузки фото
$GET_getMarketUploadServer = [
'group_id' => $vkGroupID,
'main_photo' => 1,
'access_token' => $vkToken,
'v' => $vkVersionAPI
];
$resukt_url_dp = json_decode(file_get_contents('https://api.vk.com/method/photos.getMarketUploadServer?'.http_build_query($GET_getMarketUploadServer)), TRUE);
//Загружаем фото КУРЛом, отправляя ПОСТ на полученю ссылку
$curl_file = curl_file_create($photourl,'image/jpeg','test_name.jpg');
$ch=curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $resukt_url_dp['response']['upload_url'],
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array("photo" => $curl_file)
));
//Получим массив с хешем и прочим
$img_attach = json_decode(curl_exec($ch), true);
//Сохраняем фоточку отпрявляя ГЕТ запрос в ВК
$GET_saveMarketPhoto = [
'group_id' => $vkGroupID,
'photo' => stripslashes($img_attach['photo']),
'server' => $img_attach['server'],
'hash' => $img_attach['hash'],
'crop_data' => $img_attach['crop_data'],
'crop_hash' => $img_attach['crop_hash'],
'access_token' => $vkToken,
'v' => $vkVersionAPI
];
$photo = json_decode(file_get_contents('https://api.vk.com/method/photos.saveMarketPhoto?'.http_build_query($GET_saveMarketPhoto)), TRUE);
$photoGoods = $photo['response'][0]['id'];
$GET_marketadd = [
'owner_id' => '-'.$vkGroupID.'',
'name' => $name,
'description' => $description,
'category_id' => $category_id,
'price' => $price,
'main_photo_id' => $photoGoods,
'access_token' => $vkToken,
'v' => $vkVersionAPI
];
$addMarket = json_decode(file_get_contents('https://api.vk.com/method/market.add?'.http_build_query($GET_marketadd)), TRUE);
return $addMarket;
}