鹽城網站建設 -> 信息中心 -> 網絡編程 -> PHP

通過天貓精品庫API采集商品函數

日期:2019-03-01 16:31:04 閱讀:156次 【 字體:

//add by wangtongphp QQ1006440989 通過天貓精品庫API采集商品
    public function infinityCollect($q,$cat,$start,$sort,$brand,$post_fee,$start_price,$end_price,$aution_tag)
    {
        setTimeLimit(3600);
        global $_FANWE;
        include_once FANWE_ROOT.'sdks/taobao/TopClient.php';
        include_once FANWE_ROOT.'sdks/taobao/request/TmallItemsDiscountSearchRequest.php';
        Cache::getInstance()->loadCache('business');
        
        $client = new TopClient;
        $client->appkey = trim($_FANWE['cache']['business']['taobao']['app_key']);
        $client->secretKey = trim($_FANWE['cache']['business']['taobao']['app_secret']);
        
        
        $req = new TmallItemsDiscountSearchRequest;
        $req->setQ("%E8%80%90%E5%85%8B");
        $req->setCat("2");
        $req->setStart(0);
        $req->setSort("sort=s");    
        $req->setBrand(20531);
        $req->setPostFee(-1);
        $req->setStartPrice("100");
        $req->setEndPrice("500");
        $req->setAuctionTag(3458);
        $resp = $client->execute($req);
        
        $result = array('status'=>0,'count'=>0,'max_page'=>0);
        
        var_dump($resp);
        if(isset($resp->taobaoke_items) && isset($resp->taobaoke_items->taobaoke_item))
        {
            $max_page = ceil(((int)$resp->total_results) / 40);
            $list = (array)$resp->taobaoke_items;
            $list = $list['taobaoke_item'];
            foreach($list as $item)
            {
                usleep(10);
                $item = (array)$item;
                $item['num_iid'] = (float)$item['num_iid'];
                $item['keyid'] = 'taobao_'.$item['num_iid'];
                
                $bln = (int)FDB::resultFirst('SELECT COUNT(id) FROM '.FDB::table('goods')." WHERE keyid='".$item['keyid']."'");
                if($bln)
                    continue;
                    
                $bln = (int)FDB::resultFirst('SELECT COUNT(id) FROM '.FDB::table('goods_disable')." WHERE keyid='".$item['keyid']."'");
                if($bln)
                    continue;
                
                $item['nick'] = addslashes($item['nick']);
                //add by wangtongphp  如果不是天貓店鋪,過濾掉;旗艦店、專賣店、專營店留下;
                if(!(mb_stripos($item['nick'],'旗艦店')))
                {
                    continue;
                }
                
                
                $item['title'] = addslashes(strip_tags($item['title']));
                //add by wangtongphp  如果是男的,過濾;
                if(mb_stripos($item['title'],'男'))
                {
                    continue;
                }
                
                $item['price'] = (float)$item['price'];
                $item['click_url'] = addslashes($item['click_url']);
                $item['shop_click_url'] = addslashes($item['shop_click_url']);
                $item['pic_url'] = addslashes($item['pic_url']);
                $item['item_location'] = addslashes($item['item_location']);
                $item['volume'] = (int)$item['volume'];
                $item['commission_rate'] = (float)$item['commission_rate'] / 100;
                $item['commission'] = (float)$item['commission'];
                $item['commission_num'] = (int)$item['commission_num'];
                $item['commission_volume'] = (float)$item['commission_volume'];
                FDB::insert('taobao_collect',$item,false,true);
            }
            
            $result['status'] = 1;
            $result['count'] = count($list);
            $result['max_page'] = $max_page;
        }
        return $result;
    }







上一篇:長輪詢while循環 php 卡死的問題..
下一篇:php接收淘寶客數據SimpleXMLEleme..
最新文章
會員 客服 QQ 電話 充值 工單
Top

24小時客服熱線

0515-87213010

18036323215

海南飞鱼游戏技巧