function xt_taobaoke_items_search($params) { $app = xt_taobao_is_ready(); if (!$app) { return new WP_Error('系统错误', '尚未配置淘宝开放平台!'); } $params = _xt_taobaoke_items_search_params($params); if (empty($params['keyword']) && (empty($params['cid']) || intval($params['cid']) == 0)) { 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/TaobaokeItemsGetRequest.php'; $client = new TopClient(); $client->format = 'json'; $client->appkey = $app['appKey']; $client->secretKey = $app['appSecret']; $req = new TaobaokeItemsGetRequest(); $req->setFields($params['fields']); if (!empty($params['keyword'])) { $req->setKeyword($params['keyword']); } if (!empty($params['cid']) && intval($params['cid']) > 0) { $req->setCid(intval($params['cid'])); } if (!empty($params['start_price']) && intval($params['start_price']) > 0) { $req->setStartPrice($params['start_price']); } if (!empty($params['end_price']) && intval($params['end_price']) > 0) { $req->setEndPrice($params['end_price']); } if (!empty($params['sort'])) { $req->setSort($params['sort']); } if (!empty($params['start_credit'])) { $req->setStartCredit($params['start_credit']); } if (!empty($params['end_credit'])) { $req->setEndCredit($params['end_credit']); } if (!empty($params['start_commissionRate']) && intval($params['start_commissionRate']) > 0) { $req->setStartCommissionRate($params['start_commissionRate']); } if (!empty($params['end_commissionRate']) && intval($params['end_commissionRate']) > 0) { $req->setEndCommissionRate($params['end_commissionRate']); } $req->setCashOndelivery($params['cash_ondelivery'] ? "true" : "false"); $req->setMallItem($params['mall_item'] ? "true" : "false"); if (!empty($params['page_no'])) { $req->setPageNo(intval($params['page_no'])); } if (!empty($params['page_size'])) { $req->setPageSize(intval($params['page_size'])); } $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); } if (isset($resp->taobaoke_items) && isset($resp->taobaoke_items->taobaoke_item)) { return array('items' => $resp->taobaoke_items->taobaoke_item, 'total' => $resp->total_results); } return array('items' => array(), 'total' => 0); }