<?php

namespace marketplace;

require_once(DIR_SYSTEM . '/library/aliexpress/TopSdk.php');

final class Ali
{

    private $registry, $db, $session, $url, $config, $log, $customer, $currency, $tax, $parameters;
    private $api_key = '32771436';
    private $api_secret = '1040cb64dfae83b9fd6cecfe755ce1ed';
    private $access_token = '50002001226qBELzgulITfWtFffBSCNStHkiNK15384507XgwyBk3nRpCSRGl0l2z1Yf';
    private $refresh_token = '50003001126z8UMZzg2DLvEwRlaCDygLrYhkhx14b8f5d2IyjwuHjblpQjw9r4ktzsos';
    private $user_id = 339453812950;
    private $nick = 'tr1418800750zotz';
    private $client = null;

    public function __construct($registry)
    {
        $this->db = $registry->get('db');
        $this->config = $registry->get('config');
        $this->session = $registry->get('session');
        $this->url = $registry->get('url');
        $this->log = $registry->get('log');
        $this->customer = $registry->get('customer');
        $this->currency = $registry->get('currency');
        $this->tax = $registry->get('tax');
        $this->registry = $registry;
        $this->client = new \TopClient;
        $this->client->appkey = $this->api_key;
        $this->client->secretKey = $this->api_secret;
        $this->client->format = 'json';

    }

    public function test()
    {

        $this->get_url();
    }

    public function login($api_info)
    {

        $this->access_token = $api_info['access_token'];
    }

    public function get_auth_url($params = array())
    {
        $state = $params['domain_id'] . '_' . $params['domain_marketplace_id'];
        return array('status' => true, 'message' => '', 'result' => array('url' => 'https://oauth.aliexpress.com/authorize?response_type=code&client_id=' . $this->api_key . '&redirect_uri=http://www.dilegitim.net/api/index.php?route=api/callback/aliexpress&state=' . $state . '&view=web&sp=ae'));
    }


    public function checkApi($params)
    {


        $url = 'https://oauth.aliexpress.com/token';
        $postfields = array('grant_type' => 'authorization_code',
            'client_id' => $this->api_key,
            'client_secret' => $this->api_secret,
            'code' => $params['ali_access_code'],
            'sp' => 'ae',
            'redirect_uri' => 'http://www.dilegitim.net/api/index.php?route=api/callback/aliexpress');
        $post_data = '';

        foreach ($postfields as $key => $value) {
            $post_data .= "$key=" . urlencode($value) . "&";
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        //Specify the POST data.
        curl_setopt($ch, CURLOPT_POST, true);

        //Add variables.
        curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_data, 0, -1));
        $output = json_decode(curl_exec($ch), 1);
        $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if (isset($output['error_code'])) {
            $status = false;
            $message = 'error_access_token';

        } else {
            $message = 'success_access_token';
            $status = true;
        }

        return array('status' => $status, 'message' => $message, 'result' => $output);


    }


    public function get_url()
    {

        /*
                $auth_url=$this->get_auth_url();
                echo $auth_url;
                return;
        */


    }


    public function add_product($product_info, $api_info)
    {



        $this->login($api_info);

        $language_code=explode('-',$product_info['defaults']['language_code'])[0];
        $country_code=$product_info['defaults']['country_code'];



        $req = new \AliexpressSolutionProductPostRequest;
        $post_product_request = new \PostProductRequestDto;
        $post_product_request->subject = mb_substr($product_info['title'],0,127);
        $post_product_request->description = html_entity_decode($product_info['description'] ? $product_info['description'] : $product_info['title']);
        $post_product_request->language = $language_code;
        // $post_product_request->product_unit = "100000015";
        // $multi_language_description_list = new \SingleLanguageDescriptionDto;
        // $multi_language_description_list->language="es";
        //  $multi_language_description_list->web_detail="{\"moduleList\":[{\"html\":{\"content\":\"test web description\"},\"type\":\"html\"}],\"version\":\"2.0.0\"}";
        // $multi_language_description_list->mobile_detail="{\"moduleList\":[{\"html\":{\"content\":\"test mobile description\"},\"type\":\"html\"}],\"version\":\"2.0.0\"}";
        // $post_product_request->multi_language_description_list = $multi_language_description_list;
        //  $multi_language_subject_list = new \SingleLanguageTitleDto;
        // $multi_language_subject_list->subject="Versión Global Xiaomi Redmi Note 5";
        // $multi_language_subject_list->language="tr";
        //  $post_product_request->multi_language_subject_list = $multi_language_subject_list;
        // $post_product_request->group_id="262007001";
        $post_product_request->aliexpress_category_id = $product_info['category_id'];
        $post_product_request->category_id = $product_info['category_id'];
        // $post_product_request->brand_name = "Xiaomi";
        $post_product_request->main_image_urls_list = $product_info['images'];

        //$attribute_list->attribute_value = "1920*1080";
        //$attribute_list->attribute_name = "Resolution";

        foreach ($product_info['attributes'] as $attribute) {
            $attribute_list = new \AttributeDto;

            $attribute_list->aliexpress_attribute_value_id = $attribute['value'];
            $attribute_list->aliexpress_attribute_name_id = $attribute['name'];
            $post_product_request->attribute_list[] = $attribute_list;

        }

        $sku_info_list = new \SkuInfoDto;
        foreach ($product_info['attributes'] as $attribute) {

            //  $sku_info_list->bar_code = "2012331233258";
            $sku_attributes_list = new \SkuAttributeDto;
            $sku_attributes_list->sku_image_url = "";
            $sku_attributes_list->sku_attribute_name_id = $attribute['value'];
            $sku_attributes_list->sku_attribute_value_id = $attribute['name'];
            $sku_info_list->sku_attributes_list[] = $sku_attributes_list;

        }

        $sku_info_list->inventory = $product_info['quantity'];
        $sku_info_list->price = $product_info['list_price'];
        $sku_info_list->sku_code = $product_info['model'];
        $sku_info_list->discount_price = $product_info['sale_price'];

        $post_product_request->sku_info_list = $sku_info_list;

        $post_product_request->inventory_deduction_strategy = "payment_success_deduct";
        $post_product_request->weight = $product_info['weight']?$product_info['weight']:0;
        $post_product_request->package_length = (int) ($product_info['length'] ? $product_info['length']:"10");
        $post_product_request->package_height = (int)($product_info['height']?$product_info['height']:"10");
        $post_product_request->package_width = (int)($product_info['width'] ? $product_info['width']:"10");
        // $multi_country_price_configuration = new \MultiCountryPriceConfigurationDto;
        // $multi_country_price_configuration->price_type = "absolute";
        $country_price_list = new \SingleCountryPriceDto;
        $country_price_list->ship_to_country = $country_code;
        $sku_price_by_country_list = new \SingleSkuPriceByCountryDto;
        $sku_price_by_country_list->sku_code = $product_info['model'];
        $sku_price_by_country_list->value = $product_info['quantity'];
        $sku_price_by_country_list->price = $product_info['list_price'];
        $sku_price_by_country_list->discount_price = $product_info['sale_price'];
        $country_price_list->sku_price_by_country_list = $sku_price_by_country_list;
        // $multi_country_price_configuration->country_price_list = $country_price_list;
        // $post_product_request->multi_country_price_configuration = $multi_country_price_configuration;
        $post_product_request->freight_template_id = $product_info['defaults']['shipping_template'];
        $post_product_request->size_chart_id = "100";
        $post_product_request->shipping_lead_time = $product_info['defaults']['shipping_time'] ? $product_info['defaults']['shipping_time']:3;
        $post_product_request->service_policy_id = "0";

        // print_r($post_product_request);return;
        //$api_info['access_token']='dsfdsfdsf';
        $req->setPostProductRequest(json_encode($post_product_request));

        return $this->error_check($req);


    }

    public function error_check($req)
    {

        $status = false;
        //  $this->access_token='89687678';

        $resp = json_decode(json_encode($this->client->execute($req, $this->access_token)), 1);


        if (isset($resp['code'])) {
            if (isset($resp['sub_msg'])) {
                return array('status' => false, 'message' => $resp['sub_msg'], 'result' => $resp);

            } else {

                return array('status' => false, 'message' => $resp['msg'], 'result' => $resp);

            }
        } else {

            if (isset($resp['result'])) {

                return array('status' => true, 'message' => '', 'result' => $resp['result']);
            }else {

                return array('status' => true, 'message' => '', 'result' => $resp);

            }

        }


    }


    public function shipping_templates($api_info)
    {

        $this->login($api_info);
        $req = new \AliexpressFreightRedefiningListfreighttemplateRequest;
        return $this->error_check($req);

    }

    public function get_products($query_info, $api_info)
    {

        $this->login($api_info);
        $req = new \AliexpressSolutionProductListGetRequest;
        $aeop_a_e_product_list_query = new \ItemListQuery;
        // $aeop_a_e_product_list_query->current_page="2";
        //$aeop_a_e_product_list_query->excepted_product_ids="[32962333569,32813963253]";
        //$aeop_a_e_product_list_query->off_line_time="7";
        //$aeop_a_e_product_list_query->owner_member_id="aliqatest01";
        $aeop_a_e_product_list_query->page_size = "100";
        // $aeop_a_e_product_list_query->product_id="123";
        $aeop_a_e_product_list_query->product_status_type = "onSelling";
        // $aeop_a_e_product_list_query->subject="knew odd";
        // $aeop_a_e_product_list_query->ws_display="expire_offline";
        //  $aeop_a_e_product_list_query->have_national_quote="n";
        // $aeop_a_e_product_list_query->group_id="1234";
        // $aeop_a_e_product_list_query->gmt_create_start="2012-01-01 12:13:14";
        // $aeop_a_e_product_list_query->gmt_create_end="2012-01-01 12:13:14";
        // $aeop_a_e_product_list_query->gmt_modified_start="2012-01-01 12:13:14";
        // $aeop_a_e_product_list_query->gmt_modified_end="2012-01-01 12:13:14";
        // $aeop_a_e_product_list_query->sku_code="123ABC";*/
        $req->setAeopAEProductListQuery(json_encode($aeop_a_e_product_list_query));
        $resp = $this->error_check($req);

        $product_list = array();

        if ($resp['status']) {

            if($resp['result']['product_count']>0){
                foreach ($resp['result']['aeop_a_e_product_display_d_t_o_list']['item_display_dto'] as $item) {

                    $product_info = $this->get_product(array('product_id' => $item['product_id']), $api_info);

                    if ($product_info['status']) {
                        $product_info = $product_info['result'];
                        if(isset($product_info['product_price'])){

                            $list_price=$product_info['product_price'];
                        }else if (isset($product_info['multi_language_subject_list']['product_price'])) {

                            $list_price=$product_info['multi_language_subject_list']['product_price'];

                        }
                        $sku_data=isset($product_info['aeop_ae_product_s_k_us']['global_aeop_ae_product_sku'][0]) ? $product_info['aeop_ae_product_s_k_us']['global_aeop_ae_product_sku'][0]:$product_info['aeop_ae_product_s_k_us']['global_aeop_ae_product_sku'];
                        $sku_code=isset($sku_data['sku_code']) ? $sku_data['sku_code'] : $item['product_id'];

                        $product_list[] = array(
                            'market_id'    => $item['product_id'],
                            'name'         => $item['subject'],
                            'product_code' => $item['product_id'],
                            'barcode'      => $item['product_id'],
                            'stock_code'   => $sku_code,
                            'currency_code'=> 'USD',

                            'model'        => $sku_code,
                            'list_price'   => $list_price,
                            'sale_price'   => $list_price,
                            'sale_status'  => 1,
                            'approval_status' => 1
                        );
                    }
                }

            }}
        return array('status' => true, 'message' => '', 'result' => $product_list);

    }


    public function get_product($query_info, $api_info)
    {


        $this->login($api_info);
        $req = new \AliexpressSolutionProductInfoGetRequest;
        $req->setProductId($query_info['product_id']);
        $resp = $this->error_check($req);
        if (isset($resp['result']['aeop_ae_product_propertys'])) {
            return array('status' => true, 'message' => '', 'result' => $resp['result']);
        } else {

            return array('status' => false, 'message' => '', 'result' => $resp['result']);
        }

    }

    public function update_all($product_info, $api_info)
    {


        $ali_info=unserialize($product_info['ali']);


        $this->login($api_info);

        $language_code=explode('-',$product_info['defaults']['language_code'])[0];
        $country_code=$product_info['defaults']['country_code'];



        $req = new \AliexpressSolutionProductEditRequest;
        $post_product_request = new \PostProductRequestDto;
        $post_product_request->subject = $product_info['title'];
        $post_product_request->product_id=$ali_info['product_id'];
        $post_product_request->description = html_entity_decode($product_info['description'] ? $product_info['description'] : $product_info['title']);
        $post_product_request->language = $language_code;
        // $post_product_request->product_unit = "100000015";
        // $multi_language_description_list = new \SingleLanguageDescriptionDto;
        // $multi_language_description_list->language="es";
        //  $multi_language_description_list->web_detail="{\"moduleList\":[{\"html\":{\"content\":\"test web description\"},\"type\":\"html\"}],\"version\":\"2.0.0\"}";
        // $multi_language_description_list->mobile_detail="{\"moduleList\":[{\"html\":{\"content\":\"test mobile description\"},\"type\":\"html\"}],\"version\":\"2.0.0\"}";
        // $post_product_request->multi_language_description_list = $multi_language_description_list;
        //  $multi_language_subject_list = new \SingleLanguageTitleDto;
        // $multi_language_subject_list->subject="Versión Global Xiaomi Redmi Note 5";
        // $multi_language_subject_list->language="tr";
        //  $post_product_request->multi_language_subject_list = $multi_language_subject_list;
        // $post_product_request->group_id="262007001";
        $post_product_request->aliexpress_category_id = $product_info['category_id'];
        $post_product_request->category_id = $product_info['category_id'];
        // $post_product_request->brand_name = "Xiaomi";
        $post_product_request->main_image_urls_list = $product_info['images'];

        //$attribute_list->attribute_value = "1920*1080";
        //$attribute_list->attribute_name = "Resolution";




        /*      foreach ($product_info['product_setting']['selected_attributes'] as $attribute) {
                  $attribute_list = new \AttributeDto;

                  $attribute_list->aliexpress_attribute_value_id = $attribute['value'];
                  $attribute_list->aliexpress_attribute_name_id = $attribute['name'];
                  $post_product_request->attribute_list[] = $attribute_list;

              }*/

        $sku_info_list = new \SkuInfoDto;
        /* foreach ($product_info['product_setting']['selected_attributes'] as $attribute) {

             //  $sku_info_list->bar_code = "2012331233258";
             $sku_attributes_list = new \SkuAttributeDto;
             $sku_attributes_list->sku_image_url = "";
             $sku_attributes_list->sku_attribute_name_id = $attribute['value'];
             $sku_attributes_list->sku_attribute_value_id = $attribute['name'];
             $sku_info_list->sku_attributes_list[] = $sku_attributes_list;

         }*/


        $sku_info_list->inventory = $product_info['quantity'];
        $sku_info_list->price = $product_info['list_price'];
        $sku_info_list->sku_code = $product_info['model'];
        $sku_info_list->discount_price = $product_info['sale_price'];

        $post_product_request->sku_info_list = $sku_info_list;


        $post_product_request->inventory_deduction_strategy = "payment_success_deduct";
        $post_product_request->weight = $product_info['weight']?$product_info['weight']:0;
        $post_product_request->package_length = (int)$product_info['length'] ? $product_info['length']:"10";
        $post_product_request->package_height = (int)$product_info['height']?$product_info['height']:"10";
        $post_product_request->package_width = (int)$product_info['width'] ? $product_info['width']:"10";
        // $multi_country_price_configuration = new \MultiCountryPriceConfigurationDto;
        // $multi_country_price_configuration->price_type = "absolute";
        $country_price_list = new \SingleCountryPriceDto;
        $country_price_list->ship_to_country = $country_code;
        $sku_price_by_country_list = new \SingleSkuPriceByCountryDto;
        $sku_price_by_country_list->sku_code = $product_info['model'];
        $sku_price_by_country_list->value = $product_info['quantity'];
        $sku_price_by_country_list->price = $product_info['list_price'];
        $sku_price_by_country_list->discount_price = $product_info['sale_price'];
        $country_price_list->sku_price_by_country_list = $sku_price_by_country_list;
        // $multi_country_price_configuration->country_price_list = $country_price_list;
        // $post_product_request->multi_country_price_configuration = $multi_country_price_configuration;
        $post_product_request->freight_template_id = $product_info['defaults']['shipping_template'];
        $post_product_request->size_chart_id = "100";
        $post_product_request->shipping_lead_time = $product_info['defaults']['shipping_time'] ? $product_info['defaults']['shipping_time']:3;
        $post_product_request->service_policy_id = "0";

        //print_r($post_product_request);return;
        //$api_info['access_token']='dsfdsfdsf';
        $req->setEditProductRequest(json_encode($post_product_request));

        return $this->error_check($req);

    }

    public function update_basic($product_data, $api_info)
    {


        $status=false;
        $update_price =  $this->update_price($product_data,$api_info);

        $update_stock =$this->update_stock($product_data,$api_info);
        $message=array();
        if($update_price['status']){
            $message[]='update_price_success';
        }else {
            $message[]=$update_price['message'];

        }
        if($update_stock['status']){
            $message[]='update_stock_success';
        }else {

            $message[]=$update_price['message'];
        }
        if($update_price['status'] ||$update_stock['status'] ){

            $status=true;
        }

        return array('status' => $status, 'message' => implode(',',$message), 'result' => array('update_price'=>$update_price['result'],'update_stock'=>$update_stock['result']));


    }


    public function update_stock($product_data, $api_info)
    {
        $ali_info=unserialize($product_data['ali']);

        $this->login($api_info);
        $req = new \AliexpressSolutionBatchProductInventoryUpdateRequest;
        $mutiple_product_update_list = new \SynchronizeProductRequestDto;
        $mutiple_product_update_list->product_id=$ali_info['product_id'];
        $multiple_sku_update_list = new \SynchronizeSkuRequestDto;
        $multiple_sku_update_list->sku_code=$product_data['model'];
        $multiple_sku_update_list->inventory=$product_data['quantity'];
        $mutiple_product_update_list->multiple_sku_update_list = $multiple_sku_update_list;
        $req->setMutipleProductUpdateList(json_encode($mutiple_product_update_list));
        $resp = $this->error_check($req);

        $message=[];

        if($resp['result']['update_success']){
            $status=true;
        }else {

            if($resp['result']['update_failed_list']['synchronize_product_response_dto']){


                foreach ($resp['result']['update_failed_list']['synchronize_product_response_dto'] as $error) {
                    $message[]='product_id:'.$error['product_id'].'-'.$error['error_message'];

                }
            }
            $status=false;
        }
        return array('status' => $status, 'message' => implode(',',$message), 'result' => $resp['result']);

    }

    public function update_price($product_data, $api_info)
    {


        $ali_info=unserialize($product_data['ali']);

        $this->login($api_info);
        $req = new \AliexpressSolutionBatchProductPriceUpdateRequest;
        $mutiple_product_update_list = new \SynchronizeProductRequestDto;
        $mutiple_product_update_list->product_id=$ali_info['product_id'];
        $multiple_sku_update_list = new \SynchronizeSkuRequestDto;
        $multiple_sku_update_list->price=$product_data['list_price'];
        if($product_data['list_price'] > $product_data['sale_price']){
            $multiple_sku_update_list->discount_price=$product_data['sale_price'];
        }
        $multiple_sku_update_list->sku_code=$product_data['model'];
        $mutiple_product_update_list->multiple_sku_update_list = $multiple_sku_update_list;

        $multi_country_price_configuration = new \MultiCountryPriceConfigurationDto;
        $multi_country_price_configuration->price_type="absolute";

        $country_price_list = new \SingleCountryPriceDto;
        $country_price_list->ship_to_country=$product_data['defaults']['country_code'];
        $sku_price_by_country_list = new \SingleSkuPriceByCountryDto;
        $sku_price_by_country_list->sku_code=$product_data['model'];
        $sku_price_by_country_list->price=$product_data['list_price'];

        if($product_data['list_price'] > $product_data['sale_price']){
            $sku_price_by_country_list->discount_price=$product_data['sale_price'];
        }
        $country_price_list->sku_price_by_country_list = $sku_price_by_country_list;
        $multi_country_price_configuration->country_price_list = $country_price_list;
        $mutiple_product_update_list->multi_country_price_configuration = $multi_country_price_configuration;

        $req->setMutipleProductUpdateList(json_encode($mutiple_product_update_list));
        $resp = $this->error_check($req);

        $message=[];

        if($resp['result']['update_success']){
            $status=true;
        }else {

            if($resp['result']['update_failed_list']['synchronize_product_response_dto']){


                foreach ($resp['result']['update_failed_list']['synchronize_product_response_dto'] as $error) {
                    $message[]='product_id:'.$error['product_id'].'-'.$error['error_message'];

                }
            }
            $status=false;
        }
        return array('status' => $status, 'message' => implode(',',$message), 'result' => $resp['result']);

    }


    public function open_for_sale($product_data, $api_info)
    {
        $this->login($api_info);
        $req = new \AliexpressPostproductRedefiningOnlineaeproductRequest;
        $req->setProductIds($product_data['product_id']);
        $resp = $this->error_check($req);
        return array('status' => $resp['result'], 'message' => '', 'result' => $resp['result']);
    }

    public function close_for_sale($product_data, $api_info)
    {

        $this->login($api_info);
        $req = new \AliexpressPostproductRedefiningOfflineaeproductRequest;
        $req->setProductIds($product_data['product_id']);
        return $this->error_check($req);


    }

    public function delete_product($product_data, $api_info)
    {

        $this->login($api_info);
        $req = new \AliexpressSolutionBatchProductDeleteRequest;
        $req->setProductIds($product_data['product_id']);
        return $this->error_check($req);


    }

    public function getOrderDetail($order_id, $api_info)
    {
        $c = new \TopClient;
        $c->appkey = $this->api_key;
        $c->secretKey = $this->api_secret;
        $req = new \AliexpressSolutionOrderInfoGetRequest;
        $param1 = new \OrderDetailQuery;
        $param1->ext_info_bit_flag="11111";
        $param1->order_id=$order_id;
        $req->setParam1(json_encode($param1));
        $resp = json_decode(json_encode($c->execute($req, $api_info['access_token'])), 1);


        return array('status' => true, 'message' => '', 'result' => $resp['result']);

    }


    public function get_orders($data, $api_info)
    {


        $c = new \TopClient;
        $c->appkey = $this->api_key;
        $c->secretKey = $this->api_secret;




        $req = new \AliexpressSolutionOrderGetRequest;

        $param0 = new \OrderQuery;



        $param0->create_date_end = date('Y-m-d H:i:s');
        $param0->create_date_start = "2021-05-28 12:12:12";
        //$param0->modified_date_start = "2017-10-12 12:12:12";
        // $param0->order_status_list = "SELLER_PART_SEND_GOODS";
        // $param0->buyer_login_id = "test";
        $param0->page_size = "20";
        //$param0->modified_date_end = "2017-10-12 12:12:12";
        $param0->current_page = "1";
        //$param0->order_status = "SELLER_PART_SEND_GOODS";
        $req->setParam0(json_encode($param0));
        $resp = json_decode(json_encode($c->execute($req, $api_info['access_token'])), 1);

        return array('status' => $resp['result']['success'], 'message' => '', 'result' => $resp['result']);


    }

    public function category_attributes($data, $api_info)
    {


        ini_set('max_execution_time', 0); //0=NOLIMIT
        ini_set('set_time_limit', 0); //0=NOLIMIT

        $c = new \TopClient;
        $c->appkey = $this->api_key;
        $c->secretKey = $this->api_secret;
        $req = new \AliexpressCategoryRedefiningGetchildattributesresultbypostcateidandpathRequest;
        $req->setParam1($data['category_id']);
        // $req->setParam2("2=200013977");
        $req->setLocale($data['language']);
        $resp = json_decode(json_encode($c->execute($req, $api_info['access_token'])), 1);

        return array('status' => $resp['result']['success'], 'message' => '', 'result' => $resp['result']['attributes']['aeop_attribute_dto']);

    }


    public function get_category($category_id = 0)
    {
        $c = new \TopClient;
        $c->appkey = $this->api_key;
        $c->secretKey = $this->api_secret;
        $req = new \AliexpressSolutionSellerCategoryTreeQueryRequest;
        $req->setCategoryId($category_id);
        $req->setFilterNoPermission("true");
        $resp = json_decode(json_encode($c->execute($req, $this->access_token)), 1);

        if (isset($resp['children_category_list'])) {
            return $resp['children_category_list']['category_info'];

        } else {
            return false;
        }
    }

}