元气优淘服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
youtao/service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java

196 lines
7.9 KiB

package com.hfkj.service.taobao;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.entity.BsUser;
import com.hfkj.service.user.BsUserService;
import com.taobao.top.DefaultTopApiClient;
import com.taobao.top.TopApiClient;
import com.taobao.top.ability304.Ability304;
import com.taobao.top.ability304.request.TaobaoTopAuthTokenCreateRequest;
import com.taobao.top.ability304.response.TaobaoTopAuthTokenCreateResponse;
import com.taobao.top.ability375.Ability375;
import com.taobao.top.ability375.request.TaobaoTbkTpwdCreateRequest;
import com.taobao.top.ability375.response.TaobaoTbkTpwdCreateResponse;
import com.taobao.top.ability425.Ability425;
import com.taobao.top.ability425.request.TaobaoTbkScInvitecodeGetRequest;
import com.taobao.top.ability425.request.TaobaoTbkScPublisherInfoGetRequest;
import com.taobao.top.ability425.request.TaobaoTbkScPublisherInfoSaveRequest;
import com.taobao.top.ability425.response.TaobaoTbkScInvitecodeGetResponse;
import com.taobao.top.ability425.response.TaobaoTbkScPublisherInfoGetResponse;
import com.taobao.top.ability425.response.TaobaoTbkScPublisherInfoSaveResponse;
import com.taobao.top.defaultability.Defaultability;
import com.taobao.top.defaultability.domain.*;
import com.taobao.top.defaultability.request.TaobaoTbkDgGeneralLinkConvertRequest;
import com.taobao.top.defaultability.request.TaobaoTbkDgMaterialOptionalUpgradeRequest;
import com.taobao.top.defaultability.response.TaobaoTbkDgGeneralLinkConvertResponse;
import com.taobao.top.defaultability.response.TaobaoTbkDgMaterialOptionalUpgradeResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
public class TaoBaoService {
private static Logger log = LoggerFactory.getLogger(TaoBaoService.class);
private static String appKey = "34807616";
private static String appsecret = "f04baedca9cd794665dfa04a2fcbfd86";
private static String url = "https://eco.taobao.com/router/rest";
@Resource
private BsUserService userService;
/**
* @MethodName material
* @Description:淘宝客-推广者-物料id列表查询
* @param title
* @param pageNo
* @param pageSize
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/9/10 下午1:52
*/
public static JSONObject material(String title , Long pageNo , Long pageSize , String specialId) throws Exception {
if (StringUtils.isBlank(title)) {
title = "百货";
}
log.info("============ 淘宝客-推广者-物料id列表查询-START =============");
TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url);
Defaultability apiPackage = new Defaultability(client);
// create domain
TaobaoTbkOptimusTouMaterialIdsGetMaterialQuery taobaoTbkOptimusTouMaterialIdsGetMaterialQuery = new TaobaoTbkOptimusTouMaterialIdsGetMaterialQuery();
taobaoTbkOptimusTouMaterialIdsGetMaterialQuery.setSubject(1L);
taobaoTbkOptimusTouMaterialIdsGetMaterialQuery.setMaterialType(1L);
// create request
TaobaoTbkDgMaterialOptionalUpgradeRequest request = new TaobaoTbkDgMaterialOptionalUpgradeRequest();
request.setQ(title);
request.setPageNo(pageNo);
request.setRelationId(specialId);
request.setHasCoupon(true);
request.setPageSize(pageSize);
request.setAdzoneId(115764450446L);
request.setUcrowdRankItems(new ArrayList<>());
TaobaoTbkDgMaterialOptionalUpgradeResponse response = apiPackage.taobaoTbkDgMaterialOptionalUpgrade(request);
if(!response.isSuccess()){
System.out.println(response.getSubMsg());
}
log.info("请求接口:" + "taobaoTbkOptimusTouMaterialIdsGet");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + response);
log.info("============ 淘宝客-推广者-物料id列表查询--END ==============");
return JSONObject.parseObject(JSON.toJSONString(response));
}
/**
* @MethodName createCommand
* @Description: 淘口令生成
* @param clickUrl
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/9/10 下午2:00
*/
public static JSONObject createCommand(String clickUrl) throws Exception {
log.info("============ 淘口令生成-START =============");
TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url);
Ability375 apiPackage = new Ability375(client);
// create domain
// create request
TaobaoTbkTpwdCreateRequest request = new TaobaoTbkTpwdCreateRequest();
request.setUrl(clickUrl);
TaobaoTbkTpwdCreateResponse response = apiPackage.taobaoTbkTpwdCreate(request);
log.info("请求接口:" + "taobaoTbkTpwdCreate");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + response);
log.info("============ 淘口令生成--END ==============");
return JSONObject.parseObject(JSON.toJSONString(response));
}
/**
* @MethodName publisher
* @Description: 淘宝客-公用-私域用户备案
* @param token
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/9/23 上午11:40
*/
public static JSONObject publisher(String token , String code) throws Exception {
log.info("============ 淘宝客-公用-私域用户备案-START =============");
TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url);
Ability425 apiPackage = new Ability425(client);
// create domain
// create request
TaobaoTbkScPublisherInfoSaveRequest request = new TaobaoTbkScPublisherInfoSaveRequest();
request.setInviterCode(code);
request.setInfoType(1L);
request.setNote("元气");
TaobaoTbkScPublisherInfoSaveResponse response = apiPackage.taobaoTbkScPublisherInfoSave(request,token);
log.info("请求接口:" + "taobaoTbkScPublisherInfoSave");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + response);
log.info("============ 淘宝客-公用-私域用户备案--END ==============");
if(!response.isSuccess()){
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getSubMsg());
}
return JSONObject.parseObject(JSON.toJSONString(response));
}
/**
* @MethodName getToken
* @Description:获取Access Token
* @param code
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/9/23 上午11:57
*/
public static JSONObject getToken(String code) throws Exception {
log.info("============ 获取Access Token-START =============");
TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url);
Ability304 apiPackage = new Ability304(client);
// create domain
// create request
TaobaoTopAuthTokenCreateRequest request = new TaobaoTopAuthTokenCreateRequest();
request.setCode(code);
TaobaoTopAuthTokenCreateResponse response = apiPackage.taobaoTopAuthTokenCreate(request);
log.info("请求接口:" + "taobaoTopAuthTokenCreate");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + response);
log.info("============ 获取Access Token--END ==============");
if(!response.isSuccess()){
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getSubMsg());
}
return JSONObject.parseObject(JSON.toJSONString(response));
}
}