From 81da61b828e29b7745e1382dfbbaeb685dc083ef Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 23 一月 2024 17:17:55 +0800 Subject: [PATCH] 抖音转链修改 --- fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java | 110 +++++++++++++++++++++++++++++++++--------------------- 1 files changed, 67 insertions(+), 43 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java index da556b0..c3ced2e 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java @@ -13,26 +13,21 @@ import java.util.List; import java.util.Map; -import com.sun.istack.internal.NotNull; +import com.yeshi.fanli.dto.jd.*; +import com.yeshi.fanli.entity.jd.JDBackUpOrder; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import com.yeshi.fanli.dto.jd.JDCategoryInfo; -import com.yeshi.fanli.dto.jd.JDCommissionInfo; -import com.yeshi.fanli.dto.jd.JDCouponInfo; -import com.yeshi.fanli.dto.jd.JDFilter; -import com.yeshi.fanli.dto.jd.JDOrderResult; -import com.yeshi.fanli.dto.jd.JDPingouInfo; -import com.yeshi.fanli.dto.jd.JDSearchResult; -import com.yeshi.fanli.dto.jd.JDShopInfo; import com.yeshi.fanli.entity.bus.clazz.GoodsClass; import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.jd.JDOrder; import com.yeshi.fanli.entity.jd.JDOrderItem; import com.yeshi.fanli.log.LogHelper; import com.yeshi.common.entity.PageEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.yeshi.utils.MoneyBigDecimalUtil; import com.yeshi.fanli.util.StringUtil; import org.yeshi.utils.TimeUtil; @@ -146,47 +141,41 @@ return resultJson.optJSONObject("data").optString("clickURL"); } - public static String convertLinkWithSubUnionId(@NotNull String materialId, String couponUrl, String giftCouponKey, @NotNull String positionId, - String subUnionId) { + public static String convertLinkWithSubUnionId(String materialId, String couponUrl, String giftCouponKey, String positionId, + String subUnionId) throws Exception { String log = "浜笢杞摼鍑洪敊:"; - try { - JSONObject json = new JSONObject(); + JSONObject json = new JSONObject(); - json.put("siteId", APP_ID); - json.put("positionId", positionId); - json.put("materialId", materialId); + json.put("siteId", APP_ID); + json.put("positionId", positionId); + json.put("materialId", materialId); - if (!StringUtil.isNullOrEmpty(giftCouponKey)) { - json.put("giftCouponKey", giftCouponKey); - } - if (!StringUtil.isNullOrEmpty(couponUrl)) - json.put("couponUrl", couponUrl); + if (!StringUtil.isNullOrEmpty(giftCouponKey)) { + json.put("giftCouponKey", giftCouponKey); + } + if (!StringUtil.isNullOrEmpty(couponUrl)) + json.put("couponUrl", couponUrl); - if (!StringUtil.isNullOrEmpty(subUnionId)) - json.put("subUnionId", subUnionId); + if (!StringUtil.isNullOrEmpty(subUnionId)) + json.put("subUnionId", subUnionId); - // 1锛氶暱閾撅紝 2 锛氱煭閾� 锛�3锛� 闀块摼+鐭摼 - json.put("chainType", 3); - JSONObject root = new JSONObject(); - root.put("promotionCodeReq", json); + // 1锛氶暱閾撅紝 2 锛氱煭閾� 锛�3锛� 闀块摼+鐭摼 + json.put("chainType", 3); + JSONObject root = new JSONObject(); + root.put("promotionCodeReq", json); - String result = baseRequest2("jd.union.open.promotion.bysubunionid.get", null, root); + String result = baseRequest2("jd.union.open.promotion.bysubunionid.get", null, root); - log += json.toString() + "####" + result; - JSONObject resultJson = JSONObject.fromObject(result); - result = resultJson.optJSONObject("jd_union_open_promotion_bysubunionid_get_response").optString("result"); - System.out.println(result); - if (result == null) { - return null; - } - - resultJson = JSONObject.fromObject(result); - return resultJson.optJSONObject("data").optString("shortURL"); - } catch (Exception e) { - LogHelper.error(log); + log += json.toString() + "####" + result; + JSONObject resultJson = JSONObject.fromObject(result); + result = resultJson.optJSONObject("jd_union_open_promotion_bysubunionid_get_response").optString("result"); + System.out.println(result); + if (result == null) { + return null; } - return null; + resultJson = JSONObject.fromObject(result); + return resultJson.optJSONObject("data").optString("shortURL"); } public static JDGoods queryGoodsDetail(Long skuId) { @@ -684,10 +673,10 @@ root = JSONObject.fromObject(root.optString("result")); if (root.optInt("code") == 200 && root.optJSONArray("data") != null) { - String date = root.optJSONArray("data").toString(); + JSONArray data = root.optJSONArray("data"); Type typeToken = new TypeToken<List<JDOrder>>() { }.getType(); - List<JDOrder> orderList = new Gson().fromJson(date, typeToken); + List<JDOrder> orderList = new Gson().fromJson(data.toString(), typeToken); if (orderList != null) for (JDOrder order : orderList) { Map<Long, List<JDOrderItem>> map = new HashMap<>(); @@ -725,6 +714,41 @@ } + public static JDOrderForBackUpResult getOrderListForBackUp(int page, int pageSize, Date time, int type) { + JSONObject json = new JSONObject(); + JSONObject orderReq = new JSONObject(); + orderReq.put("pageNo", page); + orderReq.put("pageSize", pageSize); + orderReq.put("type", type); + orderReq.put("time", TimeUtil.getGernalTime(time.getTime(), "yyyyMMddHH")); + + json.put("orderReq", orderReq); + String result = baseRequest2("jd.union.open.order.query", null, json); + System.out.println(result); + JSONObject root = JSONObject.fromObject(result).optJSONObject("jd_union_open_order_query_response"); + if (root.optInt("code") == 0) { + boolean hasMore = root.optBoolean("hasMore"); + root = JSONObject.fromObject(root.optString("result")); + if (root.optInt("code") == 200 && root.optJSONArray("data") != null) { + List<JDBackUpOrder> orderList = new ArrayList<>(); + JSONArray data = root.optJSONArray("data"); + for (int i = 0; i < data.size(); i++) { + JSONObject item = data.optJSONObject(i); + String orderId = item.optString("orderId"); + Long orderTime = item.optLong("orderTime"); + JDBackUpOrder order = new JDBackUpOrder(); + order.setId(orderId); + order.setContent(item.toString()); + order.setOrderTime(new Date(orderTime)); + orderList.add(order); + } + return new JDOrderForBackUpResult(hasMore, orderList); + } + } + return null; + } + + public static String createLiJin(String sku) { JSONObject json = new JSONObject(); JSONObject couponReq = new JSONObject(); -- Gitblit v1.8.0