public function fetch($url)
    {
        global $_FANWE;
        $id = $this->getID($url);
        if ($id == 0) {
            return false;
        }
        $key = 'taobao_' . $id;
        $share_goods = FDB::resultFirst('SELECT share_id,goods_id FROM ' . FDB::table('share_goods') . ' 
			WHERE uid = ' . $_FANWE['uid'] . " AND goods_key = '{$key}'");
        if ($share_goods) {
            $result['status'] = -1;
            $result['share_id'] = $share_goods['share_id'];
            $result['goods_id'] = $share_goods['goods_id'];
            return $result;
        }
        $client = new TopClient();
        $client->appkey = $_FANWE['cache']['business']['taobao']['app_key'];
        $client->secretKey = $_FANWE['cache']['business']['taobao']['app_secret'];
        $req = new ItemGetRequest();
        $req->setFields("detail_url,title,nick,pic_url,price");
        $req->setNumIid($id);
        $resp = $client->execute($req);
        if (!isset($resp->item)) {
            return false;
        }
        $result = array();
        $goods = (array) $resp->item;
        if (empty($goods['detail_url']) || empty($goods['pic_url'])) {
            return false;
        }
        if (FS("Image")->getIsServer()) {
            $args = array();
            $args['pic_url'] = $goods['pic_url'];
            $server = FS("Image")->formatServer($_FANWE['request']['image_server'], 'DE');
            $server = FS("Image")->getImageUrlToken($args, $server, 1);
            $body = FS("Image")->sendRequest($server, 'savetemp', true);
            if (empty($body)) {
                return false;
            }
            $image = unserialize($body);
            $result['image_server'] = $server['image_server'];
        } else {
            $image = copyFile($goods['pic_url'], "temp", false);
            if ($image === false) {
                return false;
            }
            $image['server_code'] = '';
        }
        $result['item']['key'] = $key;
        $result['item']['name'] = $goods['title'];
        $result['item']['price'] = $goods['price'];
        $result['item']['img'] = $image['path'];
        $result['item']['server_code'] = $image['server_code'];
        $result['item']['pic_url'] = $goods['pic_url'] . '_100x100.jpg';
        $result['item']['url'] = $goods['detail_url'];
        $tao_ke_pid = $_FANWE['cache']['business']['taobao']['tk_pid'];
        $shop_click_url = '';
        if (!empty($tao_ke_pid)) {
            $req = new TaobaokeItemsDetailGetRequest();
            $req->setFields("click_url,shop_click_url");
            $req->setNumIids($id);
            $req->setPid($tao_ke_pid);
            $resp = $client->execute($req);
            if (isset($resp->taobaoke_item_details)) {
                $taoke = (array) $resp->taobaoke_item_details->taobaoke_item_detail;
                if (!empty($taoke['click_url'])) {
                    $result['item']['taoke_url'] = $taoke['click_url'];
                }
                if (!empty($taoke['shop_click_url'])) {
                    $shop_click_url = $taoke['shop_click_url'];
                }
            }
        }
        if (!empty($goods['nick'])) {
            $req = new ShopGetRequest();
            $req->setFields("sid,nick,pic_path");
            $req->setNick($goods['nick']);
            $resp = $client->execute($req);
            if (isset($resp->shop)) {
                $shop = (array) $resp->shop;
                $result['shop']['name'] = $shop['nick'];
                if (!empty($shop['pic_path'])) {
                    if (FS("Image")->getIsServer()) {
                        $args = array();
                        $args['pic_url'] = 'http://logo.taobao.com/shop-logo' . $shop['pic_path'];
                        $server = FS("Image")->getImageUrlToken($args, '', 1);
                        $body = FS("Image")->sendRequest($server, 'savetemp', true);
                        if (!empty($body)) {
                            $image = unserialize($body);
                        } else {
                            $image = false;
                        }
                    } else {
                        $image = copyFile('http://logo.taobao.com/shop-logo' . $shop['pic_path'], "temp", false);
                        if ($image === false) {
                            $image['server_code'] = '';
                        }
                    }
                    if ($image !== false) {
                        $result['shop']['logo'] = $image['path'];
                        $result['shop']['server_code'] = $image['server_code'];
                    }
                }
                $result['shop']['shop_id'] = $shop['sid'];
                $result['shop']['url'] = 'http://shop' . $shop['sid'] . '.taobao.com';
                if (!empty($shop_click_url)) {
                    $result['shop']['taoke_url'] = $shop_click_url;
                }
            }
        }
        return $result;
    }
    public function fetch($url)
    {
        global $_FANWE;
        $id = $this->getID($url);
        if ($id == 0) {
            return false;
        }
        $key = 'taobao_' . $id;
        $share_goods = FDB::resultFirst('SELECT share_id,goods_id FROM ' . FDB::table('share_goods') . ' 
			WHERE uid = ' . $_FANWE['uid'] . " AND goods_key = '{$key}'");
        if ($share_goods) {
            $result['status'] = -1;
            $result['share_id'] = $share_goods['share_id'];
            $result['goods_id'] = $share_goods['goods_id'];
            return $result;
        }
        //http://container.open.taobao.com/container?appkey=12324287&encode=utf-8
        $client = new TopClient();
        $client->appkey = $_FANWE['cache']['business']['taobao']['app_key'];
        $client->secretKey = $_FANWE['cache']['business']['taobao']['app_secret'];
        $req = new ItemGetRequest();
        $req->setFields("detail_url,title,nick,pic_url,price");
        $req->setNumIid($id);
        $resp = $client->execute($req);
        if (!isset($resp->item)) {
            return false;
        }
        $result = array();
        $goods = (array) $resp->item;
        if (empty($goods['detail_url']) || empty($goods['pic_url'])) {
            return false;
        }
        $image = copyFile($goods['pic_url'], "temp", md5(microtime(true)) . random('6') . ".jpg", false);
        if ($image === false) {
            return false;
        }
        $result['item']['key'] = $key;
        $result['item']['name'] = $goods['title'];
        $result['item']['price'] = $goods['price'];
        $result['item']['img'] = $image['url'];
        $result['item']['pic_url'] = $goods['pic_url'] . '_100x100.jpg';
        $result['item']['url'] = $goods['detail_url'];
        $tao_ke_pid = $_FANWE['cache']['business']['taobao']['tk_pid'];
        $shop_click_url = '';
        if (!empty($tao_ke_pid)) {
            $req = new TaobaokeItemsDetailGetRequest();
            $req->setFields("click_url,shop_click_url");
            $req->setNumIids($id);
            $req->setPid($tao_ke_pid);
            $resp = $client->execute($req);
            if (isset($resp->taobaoke_item_details)) {
                $taoke = (array) $resp->taobaoke_item_details->taobaoke_item_detail;
                if (!empty($taoke['click_url'])) {
                    $result['item']['taoke_url'] = $taoke['click_url'];
                }
                if (!empty($taoke['shop_click_url'])) {
                    $shop_click_url = $taoke['shop_click_url'];
                }
            }
        }
        if (!empty($goods['nick'])) {
            $req = new ShopGetRequest();
            $req->setFields("sid,nick,pic_path");
            $req->setNick($goods['nick']);
            $resp = $client->execute($req);
            if (isset($resp->shop)) {
                $shop = (array) $resp->shop;
                $result['shop']['name'] = $shop['nick'];
                if (!empty($shop['pic_path'])) {
                    $image = copyFile('http://logo.taobao.com/shop-logo' . $shop['pic_path'], "temp", md5(microtime(true)) . random('6') . ".jpg", false);
                    if ($image !== false) {
                        $result['shop']['logo'] = $image['url'];
                    }
                }
                $result['shop']['shop_id'] = $shop['sid'];
                $result['shop']['url'] = 'http://shop' . $shop['sid'] . '.taobao.com';
                if (!empty($shop_click_url)) {
                    $result['shop']['taoke_url'] = $shop_click_url;
                }
            }
        }
        return $result;
    }
Ejemplo n.º 3
0
 public function getGoods($url)
 {
     //商品基本信息
     $id = $this->getId($url);
     $topClient = new TopClient();
     $topClient->appkey = self::$appkey;
     $topClient->secretKey = self::$secretKey;
     $itemReq = new ItemGetRequest();
     $itemReq->setFields("detail_url,nick,props_name,num_iid,title,num_iid,input_str,pic_url,location,price,item_img,prop_img");
     $itemReq->setNumIid($id);
     $objResult = $topClient->execute($itemReq);
     if (!isset($objResult->item)) {
         return false;
     }
     $arrItem = (array) $objResult->item;
     $goodsInfo = array();
     if (empty($arrItem['num_iid']) || empty($arrItem['title'])) {
         return false;
     }
     $goodsInfo['goods_name'] = $arrItem['title'];
     $goodsInfo['goods_url'] = $arrItem['detail_url'];
     $goodsInfo['goods_site'] = self::$site;
     $goodsInfo['nick'] = $arrItem['nick'];
     $goodsInfo['goods_price'] = $arrItem['price'];
     $goodsInfo['goods_brand'] = $arrItem['props_name'];
     $goodsInfo['goods_pic'] = $arrItem['pic_url'];
     $goodsInfo['goods_tags'] = $arrItem['input_str'];
     $goodsInfo['item_img'] = isset($arrItem['item_imgs']) ? $arrItem['item_imgs'] : '';
     $goodsInfo['prop_img'] = isset($arrItem['prop_imgs']) ? $arrItem['prop_imgs'] : '';
     $goodsInfo['goods_key'] = $this->getKey($url);
     //淘宝信息
     $goodsInfo['taoke_url'] = '';
     $goodsInfo['shopclickurl'] = '';
     $goodsInfo['seller_credit_score'] = '';
     if (!empty(self::$pid)) {
         $objTaoke = new TaobaokeItemsDetailGetRequest();
         $objTaoke->setFields("click_url,shop_click_url,seller_credit_score");
         $objTaoke->setNumIids($id);
         $objTaoke->setPid(self::$pid);
         $objResult = $topClient->execute($objTaoke);
         if (isset($objResult->taobaoke_item_details)) {
             $arrTaoke = (array) $objResult->taobaoke_item_details->taobaoke_item_detail;
             if (!empty($arrTaoke['click_url'])) {
                 $goodsInfo['taoke_url'] = $arrTaoke['click_url'];
             }
             if (!empty($arrTaoke['shop_click_url'])) {
                 $goodsInfo['shopclickurl'] = $arrTaoke['shop_click_url'];
             }
             if (!empty($arrTaoke['shop_click_url'])) {
                 $goodsInfo['seller_credit_score'] = $arrTaoke['seller_credit_score'];
             }
         }
     }
     //店铺信息
     $goodsInfo['shop_name'] = '';
     if (!empty($arrItem['nick'])) {
         $objShop = new ShopGetRequest();
         $objShop->setFields("sid,cid,title,nick,desc,bulletin,pic_path,created,modified");
         $objShop->setNick($arrItem['nick']);
         $objResult = $topClient->execute($objShop);
         if (isset($objResult->shop)) {
             $arrShop = (array) $objResult->shop;
             if (!empty($arrShop['title'])) {
                 $goodsInfo['shop_name'] = $arrShop['title'];
             }
         }
     }
     return $goodsInfo;
 }
Ejemplo n.º 4
0
function xt_taobaoke_item($num_iids = '', $track_iids = '', $fields = 'click_url,shop_click_url,seller_credit_score,detail_url,num_iid,title,nick,auction_point,cid,pic_url,num,price,location,post_fee,express_fee,ems_fee,item_imgs')
{
    $app = xt_taobao_is_ready();
    if (!$app) {
        return new WP_Error('系统错误', '尚未配置淘宝开放平台!');
    }
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/RequestCheckUtil.php';
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/TopClient.php';
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/request/TaobaokeItemsDetailGetRequest.php';
    $client = new TopClient();
    $client->format = 'json';
    $client->appkey = $app['appKey'];
    $client->secretKey = $app['appSecret'];
    $req = new TaobaokeItemsDetailGetRequest();
    $req->setFields($fields);
    if (!empty($num_iids)) {
        $req->setNumIids($num_iids);
    } elseif (!empty($track_iids)) {
        $req->setTrackIids($track_iids);
    } else {
        return new WP_Error('500', '必须指定num_iids或track_iids');
    }
    $req->setOuterCode(xt_outercode());
    $resp = $client->execute($req);
    if (isset($resp->sub_code)) {
        return new WP_Error($resp->sub_code > 0 ? $resp->sub_code : '500', $resp->sub_msg);
    } elseif (isset($resp->code)) {
        return new WP_Error($resp->code > 0 ? $resp->code : '500', $resp->msg);
    }
    $items = array();
    if (isset($resp->taobaoke_item_details)) {
        $items = $resp->taobaoke_item_details->taobaoke_item_detail;
    }
    return $items;
}