123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/10/13
- * Time: 14:16
- */
- namespace App\Support;
- use App\Log;
- use App\Service\HttpService;
- class HaoDanKuApi
- {
- const MAX_RETRY_NUM = 3;
- /**
- * 精选文案API
- * @param $minId integer 分页,来源于上次获取后的数据的min_id值,默认开始请求值为1
- * @param $back integer 每页返回条数(请在1,2,10,20,50,100,120,200,500,1000中选择一个数值返回)
- * @param $retry integer 重试次数
- * @return mixed
- */
- public static function excellent_editor($minId, $back, $retry=0)
- {
- $requestUrl = config('haodanku.request_url').'excellent_editor?';
- $params['apikey'] = config('haodanku.api_key');
- $params['min_id'] = $minId;
- $params['back'] = $back;
- $requestUrl = $requestUrl.http_build_query($params);
- $result = HttpService::httpGet($requestUrl);
- $result = json_decode($result, 1);
- Log::info('excellent_editor', [
- 'desc' => '精选文案',
- 'params' => $params,
- 'result' => $result
- ], 'haodanku-api');
- if((!isset($result['code']) || $result['code'] !=1)){
- if($retry<self::MAX_RETRY_NUM) {
- // 请求失败 发起重试
- $retry++;
- return HaoDanKuApi::excellent_editor($minId, $back, $retry);
- }
- }
- return $result;
- }
- /**
- * 淘宝超级搜索API
- * 本接口同时包含好单库精选高佣商品和联盟全网商品(好单库精选高佣靠前)
- * @param $keyword string 搜索关键词,同时也支持宝贝ID搜索即keyword=itemid(由于存在特殊符号搜索的关键词必须进行两次urlencode编码)
- * @param null $searchType integer 搜索来源(1.综合(好单库+联盟);2.好单库商品;3.联盟商品)
- * @param $minId integer 分页,来源于上次获取后的数据的min_id值,默认开始请求值为1
- * @param $back integer 每页返回条数(请在1,2,10,20,50,100中选择一个数值返回)
- * @param null $tbP integer 淘宝分页,来源于上次获取后的数据的tb_p值,默认开始请求值为1
- * @param null $sort integer 0.综合,1.最新,2.销量(高到低),3.销量(低到高),4.价格(低到高),5.价格(高到低),6.佣金比例(高到低)
- * @param null $isTmall integer 是否只取天猫商品:0否;1是,默认是0
- * @param null $isCoupon integer 是否只取有券商品:0否;1是,默认是0
- * @param null $isShopping integer 是否只取偏远地区包邮商品:0否;1是,默认是0
- * @param null $limitRate integer 佣金比例过滤0~100
- * @param null $startPrice integer 最低原价(默认为0),例如传10则只取大于等于10元的原价商品数据
- * @param null $sonCategory string 淘宝子类目筛选(多个请用“,”分隔,最多支持10个)
- * @param $retry integer 重试次数
- * @return mixed
- */
- public static function supersearch($keyword, $searchType = null, $minId, $back, $tbP = null, $sort = null, $isTmall = null
- , $isCoupon = null, $isShopping = null, $limitRate = null, $startPrice = null, $sonCategory = null, $retry = 0)
- {
- $requestUrl = config('haodanku.request_url').'supersearch?';
- $params['apikey'] = config('haodanku.api_key');
- $params['v'] = config('haodanku.v');
- $params['min_id'] = $minId;
- $params['back'] = $back;
- $params['keyword'] = $keyword;
- if(!is_null($searchType)) $params['search_type'] = $searchType;
- if(!is_null($tbP)) $params['tb_p'] = $tbP;
- if(!is_null($sort)) $params['sort'] = $sort;
- if(!is_null($isTmall)) $params['is_tmall'] = $isTmall;
- if(!is_null($isCoupon)) $params['is_coupon'] = $isCoupon;
- if(!is_null($isShopping)) $params['is_shopping'] = $isShopping;
- if(!is_null($limitRate)) $params['limitrate'] = $limitRate;
- if(!is_null($startPrice)) $params['startprice'] = $startPrice;
- if(!is_null($sonCategory)) $params['son_category'] = $sonCategory;
- $requestUrl = $requestUrl.http_build_query($params);
- $result = HttpService::httpGet($requestUrl);
- $result = json_decode($result, 1);
- Log::info('supersearch', [
- 'desc' => '淘宝超级搜索',
- 'params' => $params,
- 'result' => $result
- ], 'haodanku-api');
- if((!isset($result['code']) || $result['code'] !=1)){
- if($retry<self::MAX_RETRY_NUM) {
- // 请求失败 发起重试
- $retry++;
- return HaoDanKuApi::supersearch($keyword, $searchType, $minId, $back, $tbP, $sort, $isTmall, $isCoupon
- , $isShopping, $limitRate, $startPrice, $sonCategory, $retry);
- }
- }
- return $result;
- }
- /**
- * 淘宝商品转链
- * 单个商品转链,生成淘口令
- * @param $itemId integer 宝贝ID
- * @param null $xid string 团长与下游渠道合作的特殊标识,用于统计渠道推广效果(*itemid、xid二选一 或 二选二)
- * @param $pid string 推广位ID(需是授权淘宝号下的推广位,如果请求的时候携带了渠道id请求,则该pid需是渠道管理下面的渠道专属推广位)
- * @param null $relationId string 渠道ID
- * @param null $specialId string 会员运营ID
- * @param null $externalId string 淘宝客外部用户标记,如自身系统账户ID;微信ID等
- * @param $tbName string 授权后的淘宝名称(多授权淘宝号时用于区分哪个淘宝账户的)
- * @param null $activityId string 阿里妈妈推广券ID
- * @param null $me string 营销计划
- * @param null $accessToken string 授权之后的淘宝授权token
- * @param null $getTaoword integer 是否返回淘口令(0.否;1.是)(默认0)
- * @param null $title string 商品标题(用于返回淘口令*get_taoword等于1时为必填参数*,需超过8个字符)
- * @param null $logo string 商品主图链接地址
- * @param null $isSpecial integer 特殊玩法处理:1.签到红包;2.百亿补贴;3.淘宝吃货;4.超值买返;5.淘特补贴;6.首单礼金(*玩法转链请按照官方玩法使用)
- * @param null $promotionType string 1-自购省,2-推广赚(代理模式专属ID,代理模式必填,非代理模式不用填写该字段)
- * @param null $bizSceneId string 1-动态ID转链场景,2-消费者比价场景(不填默认为1)
- * @param int $retry integer 重试次数
- * @return mixed
- */
- public static function ratesurl($itemId, $xid = null, $pid, $relationId = null, $specialId = null, $externalId = null
- , $tbName, $activityId = null, $me = null, $accessToken = null, $getTaoword = null, $title = null, $logo = null
- , $isSpecial = null, $promotionType = null, $bizSceneId = null, $retry = 0)
- {
- $requestUrl = config('haodanku.request_url').'ratesurl?';
- $params['apikey'] = config('haodanku.api_key');
- $params['itemid'] = $itemId;
- $params['tb_name'] = $tbName;
- if(!is_null($xid)) $params['xid'] = $xid;
- if(!is_null($pid)) $params['pid'] = $pid;
- if(!is_null($relationId)) $params['relation_id'] = $relationId;
- if(!is_null($specialId)) $params['special_id'] = $specialId;
- if(!is_null($externalId)) $params['external_id'] = $externalId;
- if(!is_null($activityId)) $params['activityid'] = $activityId;
- if(!is_null($me)) $params['me'] = $me;
- if(!is_null($accessToken)) $params['access_token'] = $accessToken;
- if(!is_null($getTaoword)) $params['get_taoword'] = $getTaoword;
- if(!is_null($title)) $params['title'] = $title;
- if(!is_null($logo)) $params['logo'] = $logo;
- if(!is_null($isSpecial)) $params['is_special'] = $isSpecial;
- if(!is_null($promotionType))$params['promotion_type'] = $promotionType;
- if(!is_null($bizSceneId)) $params['biz_scene_id'] = $bizSceneId;
- $result = HttpService::HttpPost($requestUrl, $params);
- $result = json_decode($result, 1);
- Log::info('ratesurl', [
- 'desc' => '淘宝商品转链',
- 'params' => $params,
- 'result' => $result
- ], 'haodanku-api');
- if((!isset($result['code']) || $result['code'] !=1)){
- if($retry<self::MAX_RETRY_NUM) {
- // 请求失败 发起重试
- $retry++;
- return HaoDanKuApi::ratesurl($itemId, $xid, $pid, $relationId, $specialId, $externalId, $tbName, $activityId
- , $me, $accessToken, $getTaoword, $title, $logo, $isSpecial, $promotionType, $bizSceneId, $retry);
- }
- }
- return $result;
- }
- /**
- * 单品详情API
- * 该接口基于好单库和淘宝联盟的商品数据进行搜索,优先搜索好单库优质商品
- * @param $itemId string 获取详情的宝贝ID(目前仅支持好单库站内商品获取详情)itemid字段支持多个商品ID传入(使用英文逗号隔开),
- * 例如:111,222,333;批量查询上限为10个。数据将在all_data内返回.
- * @param int $retry integer 重试次数
- * @return mixed
- */
- public static function item_detail($itemId, $retry = 0)
- {
- $requestUrl = config('haodanku.request_url').'item_detail?';
- $params['apikey'] = config('haodanku.api_key');
- $params['itemid'] = $itemId;
- $requestUrl = $requestUrl.http_build_query($params);
- $result = HttpService::httpGet($requestUrl);
- $result = json_decode($result, 1);
- Log::info('item_detail', [
- 'desc' => '商品详情',
- 'params' => $params,
- 'result' => $result
- ], 'haodanku-api');
- if((!isset($result['code']) || $result['code'] !=1)){
- if($retry<self::MAX_RETRY_NUM) {
- // 请求失败 发起重试
- $retry++;
- return HaoDanKuApi::item_detail($itemId, $retry);
- }
- }
- return $result;
- }
- /**
- * 热搜关键词记录API
- * 该接口返回好单库统计的搜索热词
- * @param $minId integer 分页页码
- * @param $back integer 每页返回条数,默认10
- * @param int $retry 重试次数
- * @return mixed
- */
- public static function hot_key($minId, $back, $retry=0)
- {
- $requestUrl = config('haodanku.request_url').'hot_key?';
- $params['apikey'] = config('haodanku.api_key');
- $params['min_id'] = $minId;
- $params['back'] = $back;
- $requestUrl = $requestUrl.http_build_query($params);
- $result = HttpService::httpGet($requestUrl);
- $result = json_decode($result, 1);
- Log::info('hot_key', [
- 'desc' => '热搜关键词记录',
- 'params' => $params,
- 'result' => $result
- ], 'haodanku-api');
- if((!isset($result['code']) || $result['code'] !=1)){
- if($retry<self::MAX_RETRY_NUM) {
- // 请求失败 发起重试
- $retry++;
- return HaoDanKuApi::hot_key($minId, $back, $retry);
- }
- }
- return $result;
- }
- /**
- * 猜你喜欢API
- * 该接口主要是根据传过过来的宝贝ID查出这个宝贝的二级类目,取出相同类目下的产品返回
- * @param $itemId string 获取猜你喜欢的类型商品的宝贝ID,可以优先获取相同二级类目下的商品
- * @param $back int 返回条数,默认10条,最大支持50条
- * @param int $retry int 重试次数
- * @return mixed
- */
- public static function get_similar_info($itemId, $back = null, $retry = 0)
- {
- $requestUrl = config('haodanku.request_url').'get_similar_info?';
- $params['apikey'] = config('haodanku.api_key');
- $params['itemid'] = $itemId;
- if(!is_null($back)) $params['back'] = $back;
- $requestUrl = $requestUrl.http_build_query($params);
- $result = HttpService::httpGet($requestUrl);
- $result = json_decode($result, 1);
- Log::info('get_similar_info', [
- 'desc' => '猜你喜欢',
- 'params' => $params,
- 'result' => $result
- ], 'haodanku-api');
- if((!isset($result['code']) || $result['code'] !=1)){
- if($retry<self::MAX_RETRY_NUM) {
- // 请求失败 发起重试
- $retry++;
- return HaoDanKuApi::get_similar_info($itemId, $back, $retry);
- }
- }
- return $result;
- }
- /**
- * 各大榜单API
- * @param $saleType integer 榜单类型:sale_type=1是实时销量榜(近2小时销量),type=2是今日爆单榜,type=3是昨日爆单榜,type=4是出单指数榜
- * @param null $cid integer 商品类目:0全部,1女装,2男装,3内衣,4美妆,5配饰,6鞋品,7箱包,8儿童,9母婴,10居家,11美食,12数码,13家电,14其他,15车品,16文体,17宠物
- * @param $minId integer 作为请求地址中获取下一页的参数值,默认是1
- * @param $back integer 每页返回条数(请在1,2,10,20,50,100中选择一个数值返回,最多返回top100条数据)
- * @param null $itemType 是否只获取营销返利商品,1是,0否
- * @param $retry int 重试次数
- * @return mixed
- */
- public static function sales_list($saleType, $minId, $back, $cid = null, $itemType = null, $retry = 0)
- {
- $requestUrl = config('haodanku.request_url').'sales_list?';
- $params['apikey'] = config('haodanku.api_key');
- $params['v'] = config('haodanku.v');
- $params['min_id'] = $minId;
- $params['back'] = $back;
- $params['sale_type']= $saleType;
- if(!is_null($cid)) $params['cid'] = $cid;
- if(!is_null($itemType)) $params['item_type'] = $itemType;
- $requestUrl = $requestUrl.http_build_query($params);
- $result = HttpService::httpGet($requestUrl);
- $result = json_decode($result, 1);
- Log::info('sales_list', [
- 'desc' => '各大榜单',
- 'params' => $params,
- 'result' => $result
- ], 'haodanku-api');
- if((!isset($result['code']) || $result['code'] !=1)){
- if($retry<self::MAX_RETRY_NUM) {
- // 请求失败 发起重试
- $retry++;
- return HaoDanKuApi::sales_list($saleType, $cid, $minId, $back, $itemType, $retry);
- }
- }
- return $result;
- }
- public static function fieldMapping()
- {
- return [
- 'itemid' => 'item_id',
- 'itemtitle' => 'item_title',
- 'itemshorttitle'=> 'item_short_title',
- 'itemdesc' => 'item_desc',
- 'itemprice' => 'item_price',
- 'itemsale' => 'item_sale',
- 'itempic' => 'item_pic',
- 'itempic_copy' => 'item_pic_copy',
- 'itemendprice' => 'item_end_price',
- 'shoptype' => 'shop_type',
- 'couponurl' => 'coupon_url',
- 'couponmoney' => 'coupon_money',
- 'videoid' => 'video_id',
- 'couponinfo' => 'coupon_info',
- 'guide_article' => 'guide_article',
- 'text' => 'text',
- 'copy_text' => 'copy_text',
- 'time' => 'time',
- 'is_live' => 'is_live',
- 'taobao_image' => 'taobao_image',
- 'original_text' => 'original_text',
- ];
- }
- }
|