| | |
| | | package com.yeshi.fanli.util.taobao;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.taobao.TbImgUtil;
|
| | |
|
| | | import com.yeshi.fanli.dto.taobao.TaoBaoShopInfoDTO;
|
| | | import com.yeshi.common.entity.PageEntity;
|
| | | import com.yeshi.common.entity.taobao.TaoBaoShopInfo;
|
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
|
| | | import com.yeshi.fanli.dto.taobao.api.TaoKeOfficialActivityConvertResultDTO;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinReport;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.SearchShopFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoHead;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoProvince;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo;
|
| | | import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.entity.taobao.*;
|
| | | import com.yeshi.fanli.exception.taobao.TaoBaoAuthException;
|
| | | import com.yeshi.fanli.exception.taobao.TaoBaoTokenParseException;
|
| | | import com.yeshi.fanli.exception.taobao.TaoKeApiException;
|
| | |
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.log.TLJLogHelper;
|
| | | import com.yeshi.fanli.log.TaoKeLogHelper;
|
| | | import com.yeshi.fanli.tag.PageEntity;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | import com.yeshi.goods.facade.dto.taobao.TaoBaoShopInfoDTO;
|
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoHead;
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.MoneyBigDecimalUtil;
|
| | | import org.yeshi.utils.TimeUtil;
|
| | | import org.yeshi.utils.taobao.TbImgUtil;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.*;
|
| | |
|
| | | //淘宝客API接口
|
| | | public class TaoKeApiUtil {
|
| | |
| | | /**
|
| | | * 获取商品详情,简版
|
| | | *
|
| | | * @param id
|
| | | * @param ids
|
| | | * @return
|
| | | * @throws TaobaoGoodsDownException
|
| | | */
|
| | | public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids) throws TaobaoGoodsDownException {
|
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
|
| | |
| | | /**
|
| | | * 获取商品详情,简版
|
| | | *
|
| | | * @param id
|
| | | * @param ids
|
| | | * @param ip
|
| | | * @return
|
| | | * @throws TaobaoGoodsDownException
|
| | | */
|
| | | public static List<TaoBaoGoodsBrief> getBatchGoodsInfos(String ids, String ip) throws TaobaoGoodsDownException {
|
| | | Map<String, String> map = new HashMap<>();
|
| | |
| | | * @return
|
| | | * @throws TaobaoGoodsDownException
|
| | | */
|
| | | public static TaoBaoGoodsBrief searchGoodsDetail(Long id) throws TaobaoGoodsDownException {
|
| | | public static TaoBaoGoodsBrief searchGoodsDetail(Long id, String specialId, String relationId) throws TaobaoGoodsDownException {
|
| | | TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
|
| | | if (goods == null)
|
| | | return null;
|
| | |
| | | filter.setPage(1);
|
| | | filter.setPageSize(50);
|
| | | TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
|
| | | goods.getUserType());
|
| | | goods.getUserType(), specialId, relationId);
|
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null)
|
| | | for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
|
| | | System.out.println(goods.getAuctionId() + ":" + g.getAuctionId());
|
| | |
| | | // 从转链搜索
|
| | | TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
|
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
|
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
|
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), specialId, relationId);
|
| | |
|
| | | if (newGoods != null) {
|
| | | goods.setTkRate(newGoods.getTkRate());
|
| | |
| | |
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief searchGoodsDetail(Long id) throws TaobaoGoodsDownException {
|
| | | return searchGoodsDetail(id, null, null);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 搜索商品详情-详细
|
| | | *
|
| | |
| | | filter.setPage(1);
|
| | | filter.setPageSize(50);
|
| | | TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
|
| | | goods.getUserType(), app);
|
| | | goods.getUserType(), app, null, null);
|
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null)
|
| | | for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
|
| | | if (goods.getAuctionId().longValue() == g.getAuctionId()) {
|
| | |
| | | // 从转链搜索
|
| | | TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
|
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
|
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
|
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), null, null);
|
| | |
|
| | | if (newGoods != null) {
|
| | | goods.setTkRate(newGoods.getTkRate());
|
| | | goods.setAuctionUrl(newGoods.getAuctionUrl());
|
| | | goods.setCouponLink(newGoods.getCouponLink());
|
| | | if (!StringUtil.isNullOrEmpty(newGoods.getCouponInfo())) {
|
| | | List<BigDecimal> couponInfo = TaoBaoCouponUtil.getCouponInfo(newGoods.getCouponInfo());
|
| | | if (couponInfo != null && couponInfo.size() > 1) {
|
| | |
| | | * @return
|
| | | * @throws TaobaoGoodsDownException
|
| | | */
|
| | | public static TaoBaoGoodsBrief searchGoodsDetailForConvert(Long id, TaoKeAppInfo app)
|
| | | public static TaoBaoGoodsBrief searchGoodsDetailForConvert(Long id, TaoKeAppInfo app, String specialId, String relationId)
|
| | | throws TaobaoGoodsDownException {
|
| | | TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
|
| | | if (goods == null)
|
| | |
| | | filter.setPage(1);
|
| | | filter.setPageSize(50);
|
| | | TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
|
| | | goods.getUserType(), app);
|
| | | goods.getUserType(), app, specialId, relationId);
|
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null)
|
| | | for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
|
| | | if (goods.getAuctionId().longValue() == g.getAuctionId()) {
|
| | |
| | | filter.setPage(1);
|
| | | filter.setPageSize(50);
|
| | | TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
|
| | | goods.getUserType());
|
| | | goods.getUserType(), null, null);
|
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null)
|
| | | for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
|
| | | if (goods.getAuctionId().longValue() == g.getAuctionId()) {
|
| | |
| | | * 商品物料搜索
|
| | | *
|
| | | * @param filter
|
| | | * @param specialId
|
| | | * @param relationId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoSearchResult searchWuLiao(SearchFilter filter) {
|
| | | public static TaoBaoSearchResult searchWuLiao(SearchFilter filter, String specialId, String relationId) {
|
| | |
|
| | | if (filter.getKey() != null && filter.getKey().trim().equalsIgnoreCase(""))
|
| | | return null;
|
| | |
| | | map.put("method", "taobao.tbk.dg.material.optional");
|
| | | map.put("page_size", filter.getPageSize() == 0 ? "20" : filter.getPageSize() + "");
|
| | | map.put("page_no", (filter.getPage() <= 0 ? 1 : filter.getPage()) + "");
|
| | | if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(specialId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("relation_id", relationId);
|
| | | }
|
| | |
|
| | | // map.put("material_id", "3756");
|
| | |
|
| | | pageEntity.setPageIndex(filter.getPage());
|
| | |
| | | /**
|
| | | * 商品物料搜索
|
| | | *
|
| | | * @param filter
|
| | | * @param title
|
| | | * @param zkPrice
|
| | | * @param provcity
|
| | | * @param userType
|
| | | * @param specialId
|
| | | * @param relationId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoSearchResult searchWuLiaoForDetail(String title, BigDecimal zkPrice, String provcity,
|
| | | int userType) {
|
| | | int userType, String specialId, String relationId) {
|
| | | if (provcity.trim().contains(" "))
|
| | | provcity = provcity.split(" ")[provcity.split(" ").length - 1];
|
| | | TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
|
| | |
| | | map.put("is_tmall", (userType == 1) + "");
|
| | | map.put("q", title);
|
| | | map.put("itemloc", provcity);
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(specialId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("relation_id", relationId);
|
| | | }
|
| | |
|
| | | String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
|
| | | System.out.println(resultStr);
|
| | |
| | | /**
|
| | | * 商品物料搜索
|
| | | *
|
| | | * @param filter
|
| | | * @param title
|
| | | * @param zkPrice
|
| | | * @param provcity
|
| | | * @param userType
|
| | | * @param app
|
| | | * @param specialId
|
| | | * @param relationId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoSearchResult searchWuLiaoForDetail(String title, BigDecimal zkPrice, String provcity,
|
| | | int userType, TaoKeAppInfo app) {
|
| | | int userType, TaoKeAppInfo app, String specialId, String relationId) {
|
| | | if (provcity.trim().contains(" "))
|
| | | provcity = provcity.split(" ")[provcity.split(" ").length - 1];
|
| | | TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
|
| | |
| | | map.put("is_tmall", (userType == 1) + "");
|
| | | map.put("q", title);
|
| | | map.put("itemloc", provcity);
|
| | | if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(specialId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("relation_id", relationId);
|
| | | }
|
| | |
|
| | | String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, app);
|
| | | JSONObject data = JSONObject.fromObject(resultStr);
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | public static String getTKToken(String logo, String text, String url, boolean simpleToken) {
|
| | | if (simpleToken) {
|
| | | return getSimpleTKToken(logo, text, url);
|
| | | } else {
|
| | | return getTKToken(logo, text, url);
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | public static String getSimpleTKToken(String logo, String text, String url) {
|
| | | if (text == null)
|
| | | return null;
|
| | | if (text.length() < 5)
|
| | | text = "好货:" + text;
|
| | |
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("method", "taobao.tbk.tpwd.create");
|
| | | map.put("url", url);
|
| | | map.put("text", text);
|
| | | map.put("logo", logo);
|
| | | String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
|
| | |
|
| | | JSONObject data = JSONObject.fromObject(resultStr);
|
| | | if (data.optJSONObject("tbk_tpwd_create_response").optJSONObject("data") != null)
|
| | | return data.optJSONObject("tbk_tpwd_create_response").optJSONObject("data").optString("password_simple");
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取券详细信息
|
| | | *
|
| | |
| | | * @return
|
| | | */
|
| | | public static QuanInfo getQuanInfo(Long auctionId, String activityId) {
|
| | | QuanInfo info = new QuanInfo();
|
| | | QuanInfo info = new TaoKeApiUtil.QuanInfo();
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("method", "taobao.tbk.coupon.get");
|
| | | map.put("item_id", auctionId + "");
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 店铺搜索
|
| | | *
|
| | | * @param key -店铺名称
|
| | | * @param page -页码
|
| | | * @param filter
|
| | | * @return
|
| | | */
|
| | | public static List<TaoBaoShopInfo> searchShop(SearchShopFilter filter) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief specialConvertCoupon(Long auctionId, String specialId,String relationId, TaoKeAppInfo app) {
|
| | | public static TaoBaoGoodsBrief specialConvertCoupon(Long auctionId, TaoKeAppInfo app, String specialId, String relationId) {
|
| | | String pid = app.getPid();
|
| | | String[] sts = pid.split("_");
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("method", "taobao.tbk.coupon.convert");
|
| | | map.put("item_id", auctionId + "");
|
| | | map.put("adzone_id", sts[3]);
|
| | | if (!StringUtil.isNullOrEmpty(specialId)) {
|
| | | map.put("special_id", specialId);
|
| | | }
|
| | | if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("relation_id", specialId);
|
| | |
|
| | | if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2020-07-22", "yyyy-MM-dd")) {
|
| | | if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(specialId)) {
|
| | | map.put("special_id", specialId);
|
| | | } else if (!StringUtil.isNullOrEmpty(relationId)) {
|
| | | map.put("relation_id", relationId);
|
| | | }
|
| | | }
|
| | |
|
| | | try {
|
| | | String result = TaoKeBaseUtil.baseRequestForThreeTimes(map, app);
|
| | | System.out.println(result);
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | JSONObject resultJSON = json.optJSONObject("tbk_coupon_convert_response").optJSONObject("result")
|
| | | .optJSONObject("results");
|
| | |
| | |
|
| | | }
|
| | | String tkRate = resultJSON.optString("max_commission_rate");
|
| | | if (StringUtil.isNullOrEmpty(tkRate)) {
|
| | | tkRate = resultJSON.optString("min_commission_rate");
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(tkRate)) {
|
| | | goods.setTkRate(new BigDecimal(tkRate));
|
| | | }
|
| | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | | public static TaoBaoGoodsBrief specialConvertCoupon(Long auctionId, TaoKeAppInfo app) {
|
| | | return specialConvertCoupon(auctionId, null,null, app);
|
| | | }
|
| | |
|
| | | public static void juHuaSuan() {
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | public static class QuanInfo {
|
| | | public String coupon_start_time;// 开始时间
|
| | | public String coupon_end_time; // 券结束时间
|
| | | public BigDecimal coupon_amount;// 券金额
|
| | | public int coupon_total_count;// 券总数量
|
| | | public int coupon_remain_count;// 券剩余数量
|
| | | public BigDecimal coupon_start_fee;// 券起始金额
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | class QuanInfo {
|
| | | public String coupon_start_time;// 开始时间
|
| | | public String coupon_end_time; // 券结束时间
|
| | | public BigDecimal coupon_amount;// 券金额
|
| | | public int coupon_total_count;// 券总数量
|
| | | public int coupon_remain_count;// 券剩余数量
|
| | | public BigDecimal coupon_start_fee;// 券起始金额
|
| | | }
|
| | |
|