| | |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | import com.sun.istack.NotNull; |
| | | import com.yeshi.fanli.dto.jd.*; |
| | | import com.yeshi.fanli.entity.jd.JDBackUpOrder; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.taobao.SearchFilterUtil; |
| | | import com.yeshi.goods.facade.utils.taobao.DaTaoKeApiUtil; |
| | | 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; |
| | |
| | | import net.sf.json.JSONObject; |
| | | |
| | | public class JDApiUtil { |
| | | |
| | | final static Logger logger = LoggerFactory.getLogger("jdApiLogger"); |
| | | |
| | | 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("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) { |
| | | 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.getListItemId(), ","))); |
| | | |
| | | JDSearchResult searchResult = new JDSearchResult(); |
| | | |
| | | List<JDGoods> list = new ArrayList<>(); |
| | | 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()); |
| | |
| | | json.put("owner", filter.getOwner()); |
| | | |
| | | System.out.println(json.toString()); |
| | | String result = ""; |
| | | |
| | | |
| | | JSONObject jsonDTO = new JSONObject(); |
| | | jsonDTO.put("goodsReqDTO", json); |
| | | |
| | | String result = baseRequest2("jd.union.open.goods.query", null, jsonDTO); |
| | | result = baseRequest2("jd.union.open.goods.query", null, jsonDTO); |
| | | System.out.println(result); |
| | | JSONObject resultJson = JSONObject.fromObject(result); |
| | | resultJson = resultJson.optJSONObject("jd_union_open_goods_query_response"); |
| | | if (resultJson.optInt("code") == 0) { |
| | | if (resultJson != null && resultJson.optInt("code") == 0) { |
| | | result = resultJson.optString("result"); |
| | | resultJson = JSONObject.fromObject(result); |
| | | 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)); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | long totalCount = resultJson.optLong("totalCount"); |
| | | PageEntity pageEntity = new PageEntity(); |
| | | pageEntity.setTotalCount(totalCount); |
| | | |
| | | searchResult.setPageEntity(pageEntity); |
| | | } else { |
| | | result = DaTaoKeApiUtil.searchJDGoods(json); |
| | | resultJson = JSONObject.fromObject(result); |
| | | if (resultJson.optInt("code") == 0) { |
| | | JSONObject data = resultJson.optJSONObject("data"); |
| | | JSONArray array = data.optJSONArray("list"); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | JSONObject item = array.optJSONObject(i); |
| | | JDGoods goods = parseDaTaoKeJDGoods(item); |
| | | if (goods != null) |
| | | list.add(goods); |
| | | } |
| | | |
| | | long totalCount = data.optLong("totalNum"); |
| | | PageEntity pageEntity = new PageEntity(); |
| | | pageEntity.setTotalCount(totalCount); |
| | | searchResult.setPageEntity(pageEntity); |
| | | } |
| | | System.out.printf(result); |
| | | |
| | | } |
| | | |
| | | |
| | | searchResult.setGoodsList(list); |
| | | return searchResult; |
| | | } |
| | |
| | | } 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")); |
| | | |
| | |
| | | return goods; |
| | | } |
| | | |
| | | |
| | | private static JDGoods parseDaTaoKeJDGoods(JSONObject json) { |
| | | JDGoods goods = new JDGoods(); |
| | | |
| | | // 佣金信息 |
| | | BigDecimal commissionShare = new BigDecimal(json.optString("commissionShare")); |
| | | if (commissionShare.compareTo(new BigDecimal(0)) > 0) { |
| | | JDCommissionInfo commissionInfo = new JDCommissionInfo(); |
| | | commissionInfo.setCommission(new BigDecimal(json.optString("commission"))); |
| | | commissionInfo.setCommissionShare(commissionShare); |
| | | goods.setCommissionInfo(commissionInfo); |
| | | } else { |
| | | return null; |
| | | } |
| | | |
| | | goods.setComments(json.optLong("comments")); |
| | | goods.setBrandCode(json.optString("brandCode")); |
| | | goods.setBrandName(json.optString("brandName")); |
| | | goods.setGoodCommentsShare(new BigDecimal(json.optString("goodCommentsShare"))); |
| | | goods.setInOrderCount30Days(json.optLong("inOrderCount30Days")); |
| | | goods.setOwner(json.optString("owner")); |
| | | goods.setMaterialUrl(json.optString("materialUrl")); |
| | | goods.setSkuId(json.optLong("skuId")); |
| | | goods.setSkuName(json.optString("skuName")); |
| | | goods.setIsHot(json.optInt("isHot")); |
| | | |
| | | // 价格信息 |
| | | goods.setPrice(new BigDecimal(json.optString("price"))); |
| | | |
| | | // 店铺信息 |
| | | JDShopInfo jdshopInfo = new JDShopInfo(); |
| | | jdshopInfo.setShopId(json.optInt("shopId")); |
| | | jdshopInfo.setShopName(json.optString("shopName")); |
| | | goods.setShopInfo(jdshopInfo); |
| | | |
| | | // 分类信息 |
| | | JDCategoryInfo categoryInfo = new JDCategoryInfo(); |
| | | categoryInfo.setCid1(json.optLong("cid1")); |
| | | categoryInfo.setCid1Name(json.optString("cid1Name")); |
| | | categoryInfo.setCid2(json.optLong("cid2")); |
| | | categoryInfo.setCid2Name(json.optString("cid2Name")); |
| | | categoryInfo.setCid3(json.optLong("cid3")); |
| | | categoryInfo.setCid3Name(json.optString("cid3Name")); |
| | | goods.setCategoryInfo(categoryInfo); |
| | | |
| | | // 图片信息 |
| | | List<String> imageList = new ArrayList<>(); |
| | | JSONArray imagesArray = json.optJSONArray("imageUrlList"); |
| | | for (int i = 0; i < imagesArray.size(); i++) { |
| | | imageList.add(imagesArray.optString(i)); |
| | | } |
| | | goods.setImageList(imageList); |
| | | |
| | | if (imageList.size() > 0) { |
| | | goods.setPicUrl(imageList.get(0)); |
| | | } |
| | | |
| | | BigDecimal price = new BigDecimal(json.optString("price")); |
| | | // 拼购信息 |
| | | Object pinGouInfo = json.get("pinGouInfo"); |
| | | if (pinGouInfo != null) { |
| | | JSONObject pinGouInfoJson = JSONObject.fromObject(pinGouInfo); |
| | | if (!pinGouInfoJson.isEmpty()) { |
| | | JDPingouInfo jdPinGouInfo = new JDPingouInfo(); |
| | | price = new BigDecimal(pinGouInfoJson.optString("pingouPrice")); |
| | | jdPinGouInfo.setPingouPrice(price); |
| | | jdPinGouInfo.setPingouTmCount(pinGouInfoJson.optLong("pingouTmCount")); |
| | | jdPinGouInfo.setPingouUrl(pinGouInfoJson.optString("pingouUrl")); |
| | | jdPinGouInfo.setTotalCount(pinGouInfoJson.optLong("totalCount")); |
| | | jdPinGouInfo.setPingouEndTime(pinGouInfoJson.optLong("pingouEndTime")); |
| | | jdPinGouInfo.setPingouStartTime(pinGouInfoJson.optLong("pingouStartTime")); |
| | | goods.setPinGouInfo(jdPinGouInfo); |
| | | } |
| | | } |
| | | |
| | | // 券信息 |
| | | Object coupon = json.get("couponInfo"); |
| | | if (coupon != null) { |
| | | JSONArray couponArray = json.optJSONArray("couponList"); |
| | | if (couponArray != null) { |
| | | List<JDCouponInfo> couponInfoList = new ArrayList<>(); |
| | | for (int i = 0; i < couponArray.size(); i++) { |
| | | JDCouponInfo couponInfo = parseJDCouponInfo(couponArray.optJSONObject(i)); |
| | | if (couponInfo != null) |
| | | couponInfoList.add(couponInfo); |
| | | } |
| | | |
| | | // 根据消费条件排序 |
| | | Comparator<JDCouponInfo> cm = new Comparator<JDCouponInfo>() { |
| | | @Override |
| | | public int compare(JDCouponInfo o1, JDCouponInfo o2) { |
| | | return o1.getQuota().compareTo(o2.getQuota()); |
| | | } |
| | | }; |
| | | Collections.sort(couponInfoList, cm); |
| | | // if (couponInfoList.size() > 0) { |
| | | // // 设置券信息为最接近的一个 |
| | | // for (int i = couponInfoList.size() - 1; i >= 0; i--) { |
| | | // if |
| | | // (couponInfoList.get(i).getQuota().compareTo(goods.getPrice()) |
| | | // <= 0) { |
| | | // goods.setCouponInfo(couponInfoList.get(i)); |
| | | // break; |
| | | // } |
| | | // } |
| | | // if (goods.getCouponInfo() == null) |
| | | // goods.setCouponInfo(couponInfoList.get(0)); |
| | | // } |
| | | // |
| | | goods.setCouponInfoList(couponInfoList); |
| | | |
| | | } |
| | | } |
| | | |
| | | return goods; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取推广商品信息接口 |
| | | * |
| | | * @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); |
| | | resultJson = resultJson.optJSONObject("jd_union_open_goods_promotiongoodsinfo_query_response"); |
| | | if (resultJson.optInt("code") == 0) { |
| | |
| | | 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); |
| | |
| | | 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<>(); |
| | | 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 new JDOrderResult(hasMore, orderList); |
| | | } |
| | | } |
| | | 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 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; |
| | |
| | | System.out.println(result); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | 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()); |
| | | } |
| | | |
| | | } |