Попытка опубликовать данные в API с помощью curl (я не могу получить правильные данные) - PullRequest
0 голосов
/ 01 февраля 2020

Я пытаюсь получить один сайт товаров по категориям. Я хочу получить информацию о продукте по месту нахождения. Категория планшета нажмите здесь (Вы можете изменить язык на engli sh) Теперь вы можете видеть товары для планшетов по категориям, все товары в наличии. После, пожалуйста, наверху выберите район доставки Почтовый индекс 10240, район Хуамарк. После того, как товарный запас изменился, только у двух товаров есть «на складе», остальные - «нет в наличии»

Мой код - получение товаров по категориям и области доставки, но все запасы товаров поступают «в наличии», как правило, для Humark. Площадь должна только 2 продукта "в наличии" и другие "Нет в наличии". Так что я не могу получить данные по области доставки. Мне чего-то не хватает, но я не знаю, что Спасибо.

<?php
 
function curl_post_cookie($post_url,$navigate_url,$post_data,$post_data2){
    ini_set('max_execution_time', 0);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_COOKIESESSION, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HEADER,0);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36');
 
    curl_setopt($curl, CURLOPT_NOBODY, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
    curl_setopt($curl, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt');
    curl_setopt($curl, CURLOPT_COOKIE, "cookiename=0");
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
 
    curl_setopt($curl, CURLOPT_URL, $post_url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
    $html = curl_exec($curl);  
     
    $set = json_decode($html,true);
	
	//i have a token but idont know where i can use this token.
    $token = $set['result']['quote']['token'];
  
    curl_setopt($curl, CURLOPT_URL, $navigate_url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data2));
 
    $html = curl_exec($curl);
    return json_decode($html,true);
 
 
}
 
 
function getCategoryProducts($postcode,$stock_id,$subdistrict_id,$category_id,$page_no){
       
$category_url = "https://www.bigc.co.th/api/categories/getproductListBycateId?_store=1&stock_id=".$stock_id; //products by category api url
$service_url = "https://www.bigc.co.th/api/servicegate/saveServiceGate?_store=1"; // defination delivery area 
         
        // delivery area service post datas
        $post_data =array();
        $post_data['store_id'] = "1";
        $post_data['type'] = "delivery";
        $post_data['postcode'] = $postcode;
        $post_data['stock'] = $stock_id;
        $post_data['subdistrict_id'] = $subdistrict_id;
 
        // category service post datas
        $post_data2 = array(
            'cate_id'=>$category_id,
            'stock_id' => $stock_id,
            'ignore_items'=>"",
            'page_no'=>$page_no,
            'page_size'=>100,
            'selected_categories'=> "",
            'selected_brands'=>"",
            'sort_by'=>"bestsellers:desc",
            'price_from'=>"",
            'price_to'=>"",
            'filter'=>array()
        );
       
        $data = curl_post_cookie($service_url,$category_url,$post_data,$post_data2);
        return $data;
}
 
$postcode = '10240'; //BANGKOK Postcode id
$subdistrict_id = '50';  // HUAMAK id
$category_id = '324'; // Tablet Category id
$page_no= 1;
$stock_id = 146; //is a location area code, getting products by stock_id
 
echo "";
print_r(getCategoryProducts($postcode,$stock_id,$subdistrict_id,$category_id,$page_no));
echo "
";
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...