| | |
| | | package com.yeshi.fanli.util.taobao;
|
| | |
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.lang.reflect.Field;
|
| | | import java.lang.reflect.Type;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | |
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.common.ImageInfo;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.taobao.ScanHistory;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoQuanInfo;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoShop;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | |
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoHttpUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
| | | tg.setBiz30day(tb.getBiz30day());
|
| | | tg.setSalesCount(TaoBaoUtil.getSaleCount(tb.getBiz30day()));
|
| | | tg.setTitle(tb.getTitle());
|
| | | tg.setPictUrl(TbImgUtil.getTBSize320Img(tb.getPictUrl()));
|
| | | if (!StringUtil.isNullOrEmpty(tb.getPictUrlWhite()))
|
| | | tg.setPictUrl(TbImgUtil.getTBSize320Img(tb.getPictUrlWhite()));
|
| | | else
|
| | | tg.setPictUrl(TbImgUtil.getTBSize320Img(tb.getPictUrl()));
|
| | | tg.setZkPrice(tb.getZkPrice());
|
| | | tg.setAuctionUrl(tb.getAuctionUrl());
|
| | | tg.setReservePrice(tb.getReservePrice());
|
| | |
| | | }
|
| | |
|
| | | tg.setTaoBaoHongBaoInfo(hongBaoInfo);
|
| | |
|
| | | // 测试使用
|
| | | tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
|
| | | tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
|
| | | tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
|
| | | List<ClientTextStyleVO> labels = new ArrayList<>();
|
| | | labels.add(new ClientTextStyleVO("标签测试内容1", "#FF0000"));
|
| | | labels.add(new ClientTextStyleVO("标签测试内容2", "#00FF00"));
|
| | | tg.setLabels(labels);
|
| | |
|
| | | return tg;
|
| | | }
|
| | |
| | | }
|
| | | tg.setTaoBaoHongBaoInfo(hongBaoInfo);
|
| | |
|
| | | // 测试使用
|
| | | tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
|
| | | tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
|
| | | tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
|
| | | List<ClientTextStyleVO> labels = new ArrayList<>();
|
| | | labels.add(new ClientTextStyleVO("标签测试内容1", "#FF0000"));
|
| | | labels.add(new ClientTextStyleVO("标签测试内容2", "#00FF00"));
|
| | | tg.setLabels(labels);
|
| | |
|
| | | return tg;
|
| | | }
|
| | |
|
| | |
| | | return presult.getTaoBaoGoodsBriefs().get(0);
|
| | | } else
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief getTaoBaoGoodsBrief(ScanHistory sh) {
|
| | | TaoBaoGoodsBrief tb = new TaoBaoGoodsBrief();
|
| | | Field[] fields = tb.getClass().getDeclaredFields();
|
| | | Field[] shFields = sh.getClass().getDeclaredFields();
|
| | | for (int i = 0; i < fields.length; i++) {
|
| | | Field field = fields[i];
|
| | | field.setAccessible(true);
|
| | | try {
|
| | | for (Field target : shFields) {
|
| | | target.setAccessible(true);
|
| | | if (target.getName().equalsIgnoreCase(field.getName())) {
|
| | | field.set(tb, target.get(sh));
|
| | | break;
|
| | | }
|
| | | }
|
| | | } catch (IllegalArgumentException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IllegalAccessException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | return tb;
|
| | | }
|
| | |
|
| | | public static ScanHistory getScanHistory(TaoBaoGoodsBrief tb) {
|
| | | ScanHistory sh = new ScanHistory();
|
| | | Field[] fields = tb.getClass().getDeclaredFields();
|
| | | Field[] shFields = sh.getClass().getDeclaredFields();
|
| | | for (int i = 0; i < fields.length; i++) {
|
| | | Field field = fields[i];
|
| | | field.setAccessible(true);
|
| | | try {
|
| | | for (Field target : shFields) {
|
| | | target.setAccessible(true);
|
| | | if (target.getName().equalsIgnoreCase(field.getName())) {
|
| | | target.set(sh, field.get(tb));
|
| | | break;
|
| | | }
|
| | | }
|
| | | } catch (IllegalArgumentException e) {
|
| | | } catch (IllegalAccessException e) {
|
| | | }
|
| | | }
|
| | |
|
| | | return sh;
|
| | | }
|
| | |
|
| | | public static List<String> getSuguestSearch(String key) {
|
| | |
| | | * @return
|
| | | */
|
| | | public static String getGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | return "¥" + getGoodsHongBaoMoney(goodsBrief, rate).toString();
|
| | | if (goodsBrief != null && goodsBrief.getMaterialLibType() != null && goodsBrief.getMaterialLibType() == 0)
|
| | | return "¥0.00";
|
| | | else
|
| | | return "¥" + getGoodsHongBaoMoney(goodsBrief, rate).toString();
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
|
| | | if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
|
| | | || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
| | | return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
|
| | | .setScale(2, BigDecimal.ROUND_DOWN);
|
| | | return MoneyBigDecimalUtil.mul(
|
| | | MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
|
| | | new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | } else// 有券
|
| | | {
|
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
|
| | |
| | | if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
|
| | | && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
|
| | | BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
|
| | | return finalPrice.multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
|
| | | .setScale(2, BigDecimal.ROUND_DOWN);
|
| | | return MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
| | | .mul(MoneyBigDecimalUtil.mul(finalPrice, goodsBrief.getTkRate()), new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | |
|
| | | } else {// 不能用券
|
| | | return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000))
|
| | | .multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | return MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
|
| | | MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
|
| | | new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | taoBaoGoods.setCouponStartFee(commonGoods.getCouponStartPrice());
|
| | | taoBaoGoods.setCouponTotalCount(commonGoods.getCouponTotalCount());
|
| | | taoBaoGoods.setPictUrl(commonGoods.getPicture());
|
| | | taoBaoGoods.setPictUrlWhite(commonGoods.getPictureWhite());
|
| | | taoBaoGoods.setSellerId(commonGoods.getSellerId());
|
| | | taoBaoGoods.setShopTitle(commonGoods.getSellerName());
|
| | | taoBaoGoods.setTitle(commonGoods.getTitle());
|
| | |
| | | * @param uid-用户ID
|
| | | * @return
|
| | | */
|
| | | public static String getTaoBaoUnionAuthUrl(String appKey, String callBackUrl, Long uid) {
|
| | | public static String getTaoBaoUnionAuthUrl(String appKey, String callBackUrl, Long uid, String source) {
|
| | | if (uid == null)
|
| | | return null;
|
| | | long timestamp = System.currentTimeMillis();
|
| | | JSONObject json = new JSONObject();
|
| | | json.put("u", uid);
|
| | | json.put("t", timestamp);
|
| | | json.put("s", source);
|
| | | String url = null;
|
| | | try {
|
| | | url = String.format(
|
| | |
| | | return url;
|
| | | }
|
| | |
|
| | | public static TaoBaoGoodsBrief getSimpleGoodsBrief(Long actionId) {
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("itemNumId", actionId + "");
|
| | |
|
| | | String url = "";
|
| | | try {
|
| | | url = String.format("https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s",
|
| | | URLEncoder.encode(data.toString(), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | String result = HttpUtil.get(url);
|
| | | JSONObject resultOBJ = JSONObject.fromObject(result);
|
| | | if (resultOBJ.optJSONObject("data") != null) {
|
| | | data = resultOBJ.optJSONObject("data");
|
| | | JSONObject item = data.optJSONObject("item");
|
| | | JSONObject seller = data.optJSONObject("seller");
|
| | | TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
|
| | | goods.setAuctionId(item.optLong("itemId"));
|
| | | goods.setTitle(item.optString("title"));
|
| | | if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) {
|
| | | String picture = item.optJSONArray("images").optString(0);
|
| | | goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture);
|
| | | }
|
| | | goods.setSellerId(seller.optLong("shopId"));
|
| | | String shopType = seller.optString("shopType");
|
| | | if ("B".equalsIgnoreCase(shopType)) {
|
| | | goods.setUserType(1);
|
| | | } else
|
| | | goods.setUserType(0);
|
| | |
|
| | | goods.setShopTitle(seller.optString("shopName"));
|
| | | return goods;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据商品ID获取店铺详情
|
| | | * |
| | | * @param auctionId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoShop getTaoBaoShopDetailByAuctionId(Long auctionId) {
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("itemNumId", auctionId + "");
|
| | |
|
| | | String url = "";
|
| | | try {
|
| | | url = String.format("https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s",
|
| | | URLEncoder.encode(data.toString(), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | String result = HttpUtil.get(url);
|
| | | JSONObject resultJson = JSONObject.fromObject(result);
|
| | | JSONObject dataJson = resultJson.optJSONObject("data");
|
| | | JSONObject sellerJson = dataJson.optJSONObject("seller");
|
| | | TaoBaoShop shop = new TaoBaoShop();
|
| | | shop.setGoodRatePercentage(new BigDecimal(sellerJson.optString("goodRatePercentage").replace("%", "")));
|
| | | shop.setId(sellerJson.optLong("userId"));
|
| | |
|
| | | JSONArray array = sellerJson.optJSONArray("evaluates");
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | JSONObject item = array.optJSONObject(i);
|
| | | if ("宝贝描述".equalsIgnoreCase(item.optString("title").trim())) {
|
| | | shop.setScoreGoods(new BigDecimal(item.optString("score").trim()));
|
| | | shop.setScoreGoodsD(new BigDecimal(item.optString("level").trim()));
|
| | | } else if ("卖家服务".equalsIgnoreCase(item.optString("title").trim())) {
|
| | | shop.setScoreSeller(new BigDecimal(item.optString("score").trim()));
|
| | | shop.setScoreSellerD(new BigDecimal(item.optString("level").trim()));
|
| | | } else if ("物流服务".equalsIgnoreCase(item.optString("title").trim())) {
|
| | | shop.setScoreLogistics(new BigDecimal(item.optString("score").trim()));
|
| | | shop.setScoreLogisticsD(new BigDecimal(item.optString("level").trim()));
|
| | | }
|
| | | }
|
| | |
|
| | | shop.setSellerNick(sellerJson.optString("sellerNick"));
|
| | | shop.setShopIcon("https:" + sellerJson.optString("shopIcon"));
|
| | | shop.setShopId(sellerJson.optLong("shopId"));
|
| | | shop.setShopName(sellerJson.optString("shopName"));
|
| | | if ("B".equalsIgnoreCase(sellerJson.optString("sellerType")))
|
| | | shop.setUserType(1);
|
| | | else
|
| | | shop.setUserType(0);
|
| | |
|
| | | shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
|
| | | |
| | | return shop;
|
| | | }
|
| | | |
| | | /**
|
| | | * 根据卖家id获取店铺链接
|
| | | * @param sellerId
|
| | | * @return
|
| | | */
|
| | | public static String getShopLink(Long sellerId) {
|
| | | return "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
|
| | | }
|
| | | |
| | |
|
| | | public static void main(String[] args) {
|
| | | String s = channelMap.get("3");
|
| | | System.out.println(s);
|