admin
2020-11-28 dc5be7d38446f70e6ff86df311119c32b41fe7f8
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java
@@ -1,28 +1,12 @@
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.goods.facade.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.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.goods.facade.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.common.entity.taobao.TaoBaoShopInfo;
import com.yeshi.common.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;
@@ -31,14 +15,20 @@
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.log.TLJLogHelper;
import com.yeshi.fanli.log.TaoKeLogHelper;
import com.yeshi.common.entity.PageEntity;
import org.yeshi.utils.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import org.yeshi.utils.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 {
@@ -359,7 +349,7 @@
     * @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;
@@ -368,7 +358,7 @@
        filter.setPage(1);
        filter.setPageSize(50);
        TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
                goods.getUserType(), null, null);
                goods.getUserType(), specialId, relationId);
        if (result != null && result.getTaoBaoGoodsBriefs() != null)
            for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                System.out.println(goods.getAuctionId() + ":" + g.getAuctionId());
@@ -384,7 +374,7 @@
        // 从转链搜索
        TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT),null,null);
                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), specialId, relationId);
        if (newGoods != null) {
            goods.setTkRate(newGoods.getTkRate());
@@ -412,6 +402,10 @@
            return goods;
        }
    }
    public static TaoBaoGoodsBrief searchGoodsDetail(Long id) throws TaobaoGoodsDownException {
        return searchGoodsDetail(id, null, null);
    }
    /**
@@ -461,10 +455,12 @@
        // 从转链搜索
        TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(),
                new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                        TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT),null,null);
                        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) {
@@ -1066,6 +1062,34 @@
        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;
    }
    /**
     * 获取券详细信息
     *
@@ -1074,7 +1098,7 @@
     * @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 + "");
@@ -1714,19 +1738,22 @@
        }
    }
    public static TaoBaoGoodsBrief specialConvertCoupon(Long auctionId,  TaoKeAppInfo app,String specialId, String relationId) {
    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) && !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", 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 {
@@ -2293,13 +2320,15 @@
        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;// 券起始金额
}