public function fetch($url) { $id = $this->get_id($url); if (!$id) { return false; } $key = 'taobao_' . $id; $item_site = M('item_site')->where(array('code' => $this->_code))->find(); $api_config = unserialize($item_site['config']); //使用淘宝开放平台API vendor('Taobaotop.TopClient'); vendor('Taobaotop.RequestCheckUtil'); vendor('Taobaotop.Logger'); $tb_top = new TopClient(); $tb_top->appkey = $api_config['app_key']; $tb_top->secretKey = $api_config['app_secret']; $req = $tb_top->load_api('ItemGetRequest'); $req->setFields('detail_url,title,nick,pic_url,price,item_img'); $req->setNumIid($id); $resp = $tb_top->execute($req); if (!isset($resp->item)) { return false; } $item = (array) $resp->item; $result = array(); $result['item']['key_id'] = $key; $result['item']['title'] = strip_tags($item['title']); $result['item']['price'] = $item['price']; $result['item']['img'] = $item['pic_url']; $result['item']['url'] = $item['detail_url']; //商品相册 $result['item']['imgs'] = array(); $item_imgs = (array) $item['item_imgs']; $item_imgs = (array) $item_imgs['item_img']; foreach ($item_imgs as $_img) { $_img = (array) $_img; if ($_img['url']) { $result['item']['imgs'][] = array('url' => $_img['url'], 'ordid' => $_img['position']); } } if (empty($result['item']['imgs'])) { $result['item']['imgs'][] = array('url' => $result['item']['img']); } //淘客信息 $req = $tb_top->load_api('TaobaokeItemsDetailGetRequest'); $req->setFields("click_url"); $req->setNumIids($id); $resp = $tb_top->execute($req); if (isset($resp->taobaoke_item_details)) { $taoke = (array) $resp->taobaoke_item_details->taobaoke_item_detail; if ($taoke['click_url']) { $result['item']['url'] = $taoke['click_url']; } } $result['item']['url'] = Url::replace($result['item']['url'], array('spm' => '2014.21069764.' . $api_config['app_key'] . '.0')); return $result; }
public function fetch_tb($url) { $id = $this->get_id($url); if (!$id) { return false; } $item_site = M('items_site')->where(array('code' => $this->_code))->find(); $api_config = unserialize($item_site['config']); //使用淘宝开放平台API vendor('Taobaotop.TopClient'); vendor('Taobaotop.RequestCheckUtil'); vendor('Taobaotop.Logger'); $tb_top = new TopClient(); $tb_top->appkey = $api_config['app_key']; $tb_top->secretKey = $api_config['app_secret']; //淘客信息 $req = $tb_top->load_api('TaobaokeItemsDetailGetRequest'); $req->setFields("num_iid,title,nick,pic_url,click_url,price,detail_url,auction_point,commission"); $req->setNumIids($id); $resp = $tb_top->execute($req); if (isset($resp->taobaoke_item_details)) { $taoke = (array) $resp->taobaoke_item_details->taobaoke_item_detail; if ($taoke['click_url']) { $taoke['click_url'] = Url::replace($taoke['click_url'], array('spm' => '2014.' . $api_config['app_key'] . '.1.0')); } return $taoke; } return false; }
public function fetch_tmall($page) { $item_site = M('items_site')->where(array('code' => $this->_code))->find(); $api_config = unserialize($item_site['config']); //使用飞天侠开放平台API vendor('Ftxia.TopClient'); vendor('Ftxia.RequestCheckUtil'); vendor('Ftxia.Logger'); $top = new TopClient(); $top->appkey = $api_config['app_key']; $top->secretKey = $api_config['app_secret']; //淘客信息 $req = $top->load_api('TaobaokeItemsDetailGetRequest'); $req->setPage($page); $resp = $top->execute($req); if (isset($resp->tmall_items)) { $items = (array) $resp->tmall_items; return $taoke; } return false; }