| | |
| | | |
| | | public static String APP_ID = "1864778416"; |
| | | public static String APP_KEY = "388f5133d13a5ea290aa5c44f3ebcc00"; |
| | | public static String SECRET_KEY = "e22367fc866746d98b50d47b4c521781"; |
| | | public static String SECRET_KEY = "270eefea04d44e33b5c21511aa857458"; |
| | | private static String SERVER_URL = "https://router.jd.com/api"; |
| | | |
| | | // public static long POSITION_FANLI = 1869704794L; |
| | | // public static long POSITION_SHARE = 1869542990L; |
| | | // public static long POSITION_COUPON = 1869704796L; |
| | | |
| | | // 订单查询类型 |
| | | public static int ORDER_TYPE_CREATETIME = 1;// 下单时间 |
| | |
| | | return resultJson.optJSONObject("data").optString("shortURL"); |
| | | } |
| | | |
| | | public static JDGoods queryGoodsDetail(Long skuId) { |
| | | List<Long> skuIdList = new ArrayList<>(); |
| | | skuIdList.add(skuId); |
| | | public static JDGoods queryGoodsDetail(String itemId) { |
| | | List<String> itemIdList = new ArrayList<>(); |
| | | itemIdList.add(itemId); |
| | | JDFilter filter = new JDFilter(); |
| | | filter.setPageIndex(1); |
| | | filter.setPageSize(20); |
| | | filter.setListId(skuIdList); |
| | | filter.setListItemId(itemIdList); |
| | | JDSearchResult searchResult = queryByKey(filter); |
| | | if (searchResult != null) { |
| | | List<JDGoods> list = searchResult.getGoodsList(); |
| | |
| | | return null; |
| | | } |
| | | |
| | | public static List<JDGoods> queryGoodsDetail(List<Long> skuIdList) { |
| | | public static List<JDGoods> queryGoodsDetail(List<String> itemIdList) { |
| | | JDFilter filter = new JDFilter(); |
| | | filter.setPageIndex(1); |
| | | filter.setPageSize(20); |
| | | filter.setListId(skuIdList); |
| | | filter.setListItemId(itemIdList); |
| | | JDSearchResult searchResult = queryByKey(filter); |
| | | if (searchResult != null) { |
| | | List<JDGoods> list = searchResult.getGoodsList(); |
| | |
| | | /** |
| | | * 通过商品搜索接口批量获取详情 |
| | | * |
| | | * @param skuIds |
| | | * @param itemIds |
| | | * @return |
| | | */ |
| | | public static List<JDGoods> listGoodsDetail(List<Long> skuIds) { |
| | | public static List<JDGoods> listGoodsDetail(List<String> itemIds) { |
| | | JDFilter filter = new JDFilter(); |
| | | filter.setListId(skuIds); |
| | | filter.setListItemId(itemIds); |
| | | JDSearchResult result = queryByKey(filter); |
| | | return result.getGoodsList(); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public static JDSearchResult queryByKey(JDFilter filter) { |
| | | logger.info(String.format("queryByKey:%s %s", filter.getKeyword(), StringUtil.concat(filter.getListId(), ","))); |
| | | logger.info(String.format("queryByKey:%s %s", filter.getKeyword(), StringUtil.concat(filter.getListItemId(), ","))); |
| | | |
| | | JDSearchResult searchResult = new JDSearchResult(); |
| | | |
| | |
| | | JSONObject json = new JSONObject(); |
| | | json.put("pageIndex", filter.getPageIndex()); |
| | | json.put("pageSize", filter.getPageSize()); |
| | | // json.put("sceneId", 1); |
| | | |
| | | |
| | | if (filter.getCid1() != null) |
| | | json.put("cid1", filter.getCid1()); |
| | |
| | | if (filter.getIsCoupon() != null) |
| | | json.put("isCoupon", filter.getIsCoupon()); |
| | | |
| | | if (filter.getListId() != null) |
| | | json.put("skuIds", "[" + StringUtil.concat(filter.getListId(), ",") + "]"); |
| | | if (filter.getListItemId() != null) |
| | | json.put("itemIds", new Gson().toJson(filter.getListItemId())); |
| | | |
| | | if (filter.getIsPG() != null) |
| | | json.put("isPG", filter.getIsPG()); |
| | |
| | | String message = resultJson.optString("message"); |
| | | if ("SUCCESS".equalsIgnoreCase(message)) { |
| | | JSONArray array = resultJson.optJSONArray("data"); |
| | | System.out.println(array.toString()); |
| | | if (array != null) { |
| | | for (int i = 0; i < array.size(); i++) { |
| | | JDGoods goods = parseJDGoods(array.optJSONObject(i)); |
| | |
| | | } else { |
| | | return null; |
| | | } |
| | | |
| | | goods.setItemId(json.optString("itemId")); |
| | | goods.setComments(json.optLong("comments")); |
| | | goods.setBrandCode(json.optString("brandCode")); |
| | | goods.setBrandName(json.optString("brandName")); |
| | |
| | | goods.setOwner(json.optString("owner")); |
| | | goods.setMaterialUrl(json.optString("materialUrl")); |
| | | goods.setSkuId(json.optLong("skuId")); |
| | | goods.setSpuid(json.optLong("spuid")); |
| | | goods.setSkuName(json.optString("skuName")); |
| | | goods.setIsHot(json.optInt("isHot")); |
| | | |
| | |
| | | /** |
| | | * 获取推广商品信息接口 |
| | | * |
| | | * @param skuIdList |
| | | * @param itemIdList |
| | | * @return |
| | | */ |
| | | public static List<JDGoods> getGoodsDetail(List<Long> skuIdList) { |
| | | public static List<JDGoods> getGoodsDetail(List<String> itemIdList) { |
| | | List<JDGoods> list = new ArrayList<>(); |
| | | JSONObject json = new JSONObject(); |
| | | json.put("skuIds", StringUtil.concat(skuIdList, ",")); |
| | | json.put("itemIds", StringUtil.concat(itemIdList, ",")); |
| | | String result = baseRequest2("jd.union.open.goods.promotiongoodsinfo.query", null, json); |
| | | System.out.println(result); |
| | | JSONObject resultJson = JSONObject.fromObject(result); |
| | |
| | | return list; |
| | | } |
| | | |
| | | public static JDGoods getGoodsDetail(Long skuId) { |
| | | List<Long> skuIdList = new ArrayList<>(); |
| | | skuIdList.add(skuId); |
| | | public static JDGoods getGoodsDetail(String itemId) { |
| | | List<String> skuIdList = new ArrayList<>(); |
| | | skuIdList.add(itemId); |
| | | List<JDGoods> list = getGoodsDetail(skuIdList); |
| | | if (list != null && list.size() > 0) |
| | | return list.get(0); |
| | |
| | | List<JDOrder> orderList = new Gson().fromJson(data.toString(), typeToken); |
| | | if (orderList != null) |
| | | for (JDOrder order : orderList) { |
| | | Map<Long, List<JDOrderItem>> map = new HashMap<>(); |
| | | Map<String, List<JDOrderItem>> map = new HashMap<>(); |
| | | for (int i = 0; i < order.getOrderItemList().size(); i++) { |
| | | JDOrderItem orderItem = order.getOrderItemList().get(i); |
| | | if (map.get(orderItem.getSkuId()) == null) |
| | | map.put(orderItem.getSkuId(), new ArrayList<>()); |
| | | map.get(orderItem.getSkuId()).add(orderItem); |
| | | String goodsId = getGoodsId(orderItem, order.getOrderItemList().size()); |
| | | if (map.get(goodsId) == null) |
| | | map.put(goodsId, new ArrayList<>()); |
| | | map.get(goodsId).add(orderItem); |
| | | |
| | | order.getOrderItemList().get(i) |
| | | .setTradeId(order.getOrderId() + "-" + order.getOrderItemList().get(i).getSkuId()); |
| | | .setTradeId(order.getOrderId() + "-" + getGoodsId(order.getOrderItemList().get(i),order.getOrderItemList().size())); |
| | | order.getOrderItemList().get(i).setOrderId(order.getOrderId()); |
| | | order.getOrderItemList().get(i).setOrderBy(i + 1); |
| | | } |
| | | // 查询商品ID相同的子订单 |
| | | for (Iterator<Long> its = map.keySet().iterator(); its.hasNext(); ) { |
| | | Long skuId = its.next(); |
| | | if (map.get(skuId).size() > 1) { |
| | | for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { |
| | | String goodsId = its.next(); |
| | | if (map.get(goodsId).size() > 1) { |
| | | int skuOrderBy = 1; |
| | | for (int i = 0; i < order.getOrderItemList().size(); i++) { |
| | | JDOrderItem orderItem = order.getOrderItemList().get(i); |
| | | if (orderItem.getSkuId().longValue() == skuId) { |
| | | if (getGoodsId(orderItem,order.getOrderItemList().size()).equalsIgnoreCase(goodsId)) { |
| | | order.getOrderItemList().get(i).setTradeId(order.getOrderId() + "-" |
| | | + order.getOrderItemList().get(i).getSkuId() + "-" + skuOrderBy++); |
| | | + getGoodsId(order.getOrderItemList().get(i), order.getOrderItemList().size()) + "-" + skuOrderBy++); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private static String getGoodsId(JDOrderItem item, int itemCount) { |
| | | if (itemCount <= 1) { |
| | | return item.getSkuId() + ""; |
| | | } |
| | | if (item.getSkuId() != null) { |
| | | return item.getSkuId() + ""; |
| | | } |
| | | return item.getItemId().split("_")[1]; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | List<Long> ids=new ArrayList<>(); |
| | | ids.add(100067115976L); |
| | | Date startTime = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24L); |
| | | // 一个小时为一个步长 |
| | | List<JDOrder> tempOrderList = new ArrayList<>(); |
| | | for (int i = 0; i < 24; i++) { |
| | | Date da = new Date(startTime.getTime() + 1000 * 60 * 60L * i); |
| | | if (da.getTime() >System.currentTimeMillis()) |
| | | break; |
| | | |
| | | |
| | | int pageSize = 200; |
| | | int page = 1; |
| | | JDOrderResult result = JDApiUtil.getOrderList(page++, pageSize, da, JDApiUtil.ORDER_TYPE_UPDATETIME); |
| | | if (result != null) { |
| | | tempOrderList.addAll(result.getOrderList()); |
| | | while (result != null && result.isHasMore()) { |
| | | result = JDApiUtil.getOrderList(page++, pageSize, da, JDApiUtil.ORDER_TYPE_UPDATETIME); |
| | | if (result != null) |
| | | tempOrderList.addAll(result.getOrderList()); |
| | | } |
| | | } |
| | | } |
| | | System.out.println(tempOrderList.size()); |
| | | } |
| | | |
| | | } |