From f253c6f0ce5e708850f8e3c84a6a9008fc37df5f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 31 七月 2019 19:15:13 +0800
Subject: [PATCH] 添加拼多多/京东的订单

---
 fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java |  141 +++++++++++++++++++++++-----------------------
 1 files changed, 71 insertions(+), 70 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 14aae75..a1042a3 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
@@ -6,6 +6,7 @@
 import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -41,9 +42,9 @@
 	public static String SECRET_KEY = "fb49bc6ecac5458ba5394fc2969d7c56";
 	private static String SERVER_URL = "https://router.jd.com/api";
 
-	public static Long POSITION_FANLI = 1834339426L;
-	public static Long POSITION_SHARE = 1834289924L;
-	public static Long POSITION_COUPON = 1859510742L;
+	public static long POSITION_FANLI = 1834339426L;
+	public static long POSITION_SHARE = 1834289924L;
+	public static long POSITION_COUPON = 1859510742L;
 
 	// 璁㈠崟鏌ヨ绫诲瀷
 	public static int ORDER_TYPE_CREATETIME = 1;// 涓嬪崟鏃堕棿
@@ -74,7 +75,7 @@
 		}
 		return null;
 	}
-	
+
 	private static String post2(String url, Map<String, String> params) {
 		String baseUrl = url;
 		List<String> paramsList = new ArrayList<>();
@@ -131,7 +132,6 @@
 		return result;
 	}
 
-	
 	private static String baseRequest2(String method, String accessToken, JSONObject params) {
 		Map<String, String> baseMap = new HashMap<String, String>();
 		baseMap.put("param_json", params.toString());
@@ -147,7 +147,7 @@
 		String result = post2(SERVER_URL, baseMap);
 		return result;
 	}
-	
+
 	/**
 	 * 杞摼
 	 * 
@@ -158,30 +158,31 @@
 		json.put("materialId", materialId);
 		json.put("siteId", APP_ID);
 		json.put("positionId", positionId);
-		
+
 		if (!StringUtil.isNullOrEmpty(couponUrl))
 			json.put("couponUrl", couponUrl);
-		
+
 		if (!StringUtil.isNullOrEmpty(ext1))
-			 json.put("ext1", ext1);
+			json.put("ext1", ext1);
 
 		JSONObject root = new JSONObject();
 		root.put("promotionCodeReq", json);
 
 		String result = baseRequest("jd.union.open.promotion.common.get", null, root);
-		
+
 		JSONObject resultJson = JSONObject.fromObject(result);
 		result = resultJson.optJSONObject("jd_union_open_promotion_common_get_response").optString("result");
 		if (result == null) {
 			return null;
 		}
-		
+
 		resultJson = JSONObject.fromObject(result);
 		return resultJson.optJSONObject("data").optString("clickURL");
 	}
-	
+
 	/**
 	 * 杞摼鎺�-鐭繛鎺�
+	 * 
 	 * @param materialId
 	 * @param couponUrl
 	 * @param positionId
@@ -195,8 +196,7 @@
 		}
 		return url;
 	}
-	
-	
+
 	public static JDGoods queryGoodsDetail(Long skuId) {
 		List<Long> skuIdList = new ArrayList<>();
 		skuIdList.add(skuId);
@@ -212,15 +212,16 @@
 		}
 		return null;
 	}
-	
+
 	/**
 	 * 鍏抽敭璇嶅晢鍝佹煡璇㈡帴鍙c�愮敵璇枫��
+	 * 
 	 * @param skuIdList
 	 * @return
 	 */
 	public static JDSearchResult queryByKey(JDFilter filter) {
 		JDSearchResult searchResult = new JDSearchResult();
-		
+
 		List<JDGoods> list = new ArrayList<>();
 		JSONObject json = new JSONObject();
 		json.put("pageIndex", filter.getPageIndex());
@@ -279,16 +280,15 @@
 
 		if (filter.getShopId() != null)
 			json.put("shopId", filter.getShopId());
-		
+
 		if (filter.getOwner() != null)
 			json.put("owner", filter.getOwner());
-		
+
 		System.out.println(json.toString());
-		
+
 		JSONObject jsonDTO = new JSONObject();
 		jsonDTO.put("goodsReqDTO", json);
-		
-		
+
 		String result = baseRequest2("jd.union.open.goods.query", null, jsonDTO);
 		System.out.println(result);
 		JSONObject resultJson = JSONObject.fromObject(result);
@@ -307,23 +307,20 @@
 					}
 				}
 			}
-			
+
 			long totalCount = resultJson.optLong("totalCount");
 			PageEntity pageEntity = new PageEntity();
 			pageEntity.setTotalCount(totalCount);
-			
+
 			searchResult.setPageEntity(pageEntity);
 		}
 		searchResult.setGoodsList(list);
 		return searchResult;
 	}
-	
-	
-	
-	
+
 	private static JDGoods parseJDGoods(JSONObject json) {
 		JDGoods goods = new JDGoods();
-		
+
 		// 浣i噾淇℃伅
 		Object commission = json.get("commissionInfo");
 		JSONObject commissionJson = JSONObject.fromObject(commission);
@@ -336,7 +333,7 @@
 		} else {
 			return null;
 		}
-		
+
 		goods.setComments(json.optLong("comments"));
 		goods.setBrandCode(json.optString("brandCode"));
 		goods.setBrandName(json.optString("brandName"));
@@ -347,13 +344,12 @@
 		goods.setSkuId(json.optLong("skuId"));
 		goods.setSkuName(json.optString("skuName"));
 		goods.setIsHot(json.optInt("isHot"));
-		
-		
+
 		// 浠锋牸淇℃伅
 		Object priceInfo = json.get("priceInfo");
 		JSONObject priceInfoJson = JSONObject.fromObject(priceInfo);
 		goods.setPrice(new BigDecimal(priceInfoJson.optString("price")));
-		
+
 		// 搴楅摵淇℃伅
 		Object shopInfo = json.get("shopInfo");
 		JSONObject shopInfoJson = JSONObject.fromObject(shopInfo);
@@ -361,8 +357,7 @@
 		jdshopInfo.setShopId(shopInfoJson.optInt("shopId"));
 		jdshopInfo.setShopName(shopInfoJson.optString("shopName"));
 		goods.setShopInfo(jdshopInfo);
-		
-		
+
 		// 鍒嗙被淇℃伅
 		Object category = json.get("categoryInfo");
 		JSONObject categoryJson = JSONObject.fromObject(category);
@@ -374,8 +369,7 @@
 		categoryInfo.setCid3(categoryJson.optLong("cid3"));
 		categoryInfo.setCid3Name(categoryJson.optString("cid3Name"));
 		goods.setCategoryInfo(categoryInfo);
-		
-		
+
 		// 鍥剧墖淇℃伅
 		List<String> imageList = new ArrayList<String>();
 		Object images = json.get("imageInfo");
@@ -385,11 +379,11 @@
 			imageList.add(imagesArray.optJSONObject(i).optString("url"));
 		}
 		goods.setImageList(imageList);
-		
+
 		if (imageList.size() > 0) {
 			goods.setPicUrl(imageList.get(0));
 		}
-		
+
 		BigDecimal price = new BigDecimal(priceInfoJson.optString("price"));
 		// 鎷艰喘淇℃伅
 		Object pinGouInfo = json.get("pinGouInfo");
@@ -407,9 +401,7 @@
 				goods.setPinGouInfo(jdPinGouInfo);
 			}
 		}
-		
-		
-		
+
 		// 鍒镐俊鎭�
 		Object coupon = json.get("couponInfo");
 		if (coupon != null) {
@@ -421,13 +413,13 @@
 				for (int i = 0; i < couponArray.size(); i++) {
 					boolean add = false;
 					JSONObject jdcoupon = couponArray.optJSONObject(i);
-					
+
 					BigDecimal quota = new BigDecimal(jdcoupon.optString("quota"));
 					BigDecimal sub = MoneyBigDecimalUtil.sub(price, quota);
 					if (sub.compareTo(new BigDecimal(0)) < 0) {
 						continue; // 鍟嗗搧浠锋牸灏忎簬浼樻儬鍒镐环鏍奸檺鍒�
 					}
-					
+
 					// 鍒搁潰棰�
 					BigDecimal discount = new BigDecimal(jdcoupon.optString("discount"));
 					if (discount_temp == null) {
@@ -436,12 +428,12 @@
 					} else if (discount_temp.compareTo(discount) > 0) { // 鍒搁潰棰濆ぇ
 						add = true;
 					}
-					
+
 					if (add) {
 						if (couponInfo == null) {
 							couponInfo = new JDCouponInfo();
 						}
-						
+
 						couponInfo.setBindType(jdcoupon.optInt("bindType"));
 						couponInfo.setDiscount(new BigDecimal(jdcoupon.optString("discount")));
 						couponInfo.setQuota(new BigDecimal(jdcoupon.optString("quota")));
@@ -453,19 +445,17 @@
 						couponInfo.setLink(jdcoupon.optString("link"));
 					}
 				}
-				
+
 				goods.setCouponInfo(couponInfo);
 			}
 		}
 
-		
-		
 		return goods;
 	}
 
-
 	/**
 	 * 鑾峰彇鎺ㄥ箍鍟嗗搧淇℃伅鎺ュ彛
+	 * 
 	 * @param skuIdList
 	 * @return
 	 */
@@ -495,7 +485,6 @@
 		goods.setPrice(StringUtil.isNullOrEmpty(json.optString("wlUnitPrice"))
 				? new BigDecimal(json.optString("unitPrice")) : new BigDecimal(json.optString("wlUnitPrice")));
 
-		
 		BigDecimal commisionRatioWl = new BigDecimal(json.optString("commisionRatioWl"));
 		if (commisionRatioWl.compareTo(new BigDecimal(0)) > 0) {
 			JDCommissionInfo commissionInfo = new JDCommissionInfo();
@@ -506,7 +495,7 @@
 		} else {
 			return null;
 		}
-		
+
 		JDCategoryInfo categoryInfo = new JDCategoryInfo();
 		categoryInfo.setCid1(json.optLong("cid1"));
 		categoryInfo.setCid1Name(json.optString("cid1Name"));
@@ -522,7 +511,7 @@
 		if (!StringUtil.isNullOrEmpty(isFreeShipping)) {
 			goods.setIsFreeShipping(Integer.parseInt(isFreeShipping));
 		}
-		
+
 		goods.setCouponInfo(null);
 		goods.setGoodCommentsShare(null);
 		List<String> imageList = new ArrayList<>();
@@ -545,8 +534,7 @@
 
 		return goods;
 	}
-	
-	
+
 	public static JDSearchResult getJingFenGoods(int pageIndex, int eliteId) {
 		JDSearchResult searchResult = new JDSearchResult();
 		List<JDGoods> list = new ArrayList<>();
@@ -556,11 +544,10 @@
 		json.put("sortName", "inOrderCount30DaysSku");
 		json.put("sort", "desc");
 		json.put("eliteId", eliteId);
-		
+
 		JSONObject jsonDTO = new JSONObject();
 		jsonDTO.put("goodsReq", json);
-		
-		
+
 		String result = baseRequest2("jd.union.open.goods.jingfen.query", null, jsonDTO);
 		System.out.println(result);
 		JSONObject resultJson = JSONObject.fromObject(result);
@@ -579,29 +566,27 @@
 					}
 				}
 			}
-			
+
 			long totalCount = resultJson.optLong("totalCount");
 			PageEntity pageEntity = new PageEntity();
 			pageEntity.setTotalCount(totalCount);
-			
+
 			searchResult.setPageEntity(pageEntity);
 		}
 		searchResult.setGoodsList(list);
 		return searchResult;
 	}
-	
-	
+
 	public static JDSearchResult getGoodsClass() {
 		JDSearchResult searchResult = new JDSearchResult();
 		List<JDGoods> list = new ArrayList<>();
 		JSONObject json = new JSONObject();
 		json.put("parentId", 0);
 		json.put("grade", 0);
-		
+
 		JSONObject jsonDTO = new JSONObject();
 		jsonDTO.put("req", json);
-		
-		
+
 		String result = baseRequest2("jd.union.open.category.goods.get", null, jsonDTO);
 		System.out.println(result);
 		JSONObject resultJson = JSONObject.fromObject(result);
@@ -620,17 +605,16 @@
 					}
 				}
 			}
-			
+
 			long totalCount = resultJson.optLong("totalCount");
 			PageEntity pageEntity = new PageEntity();
 			pageEntity.setTotalCount(totalCount);
-			
+
 			searchResult.setPageEntity(pageEntity);
 		}
 		searchResult.setGoodsList(list);
 		return searchResult;
 	}
-	
 
 	public static JDGoods getGoodsDetail(Long skuId) {
 		List<Long> skuIdList = new ArrayList<>();
@@ -641,16 +625,33 @@
 		return null;
 	}
 
-	public static JDOrderResult getOrder(int page, int pageSize, String time, int type) {
+	/**
+	 * 鑾峰彇璁㈠崟鍒楄〃
+	 * 
+	 * @param page
+	 * @param pageSize
+	 * @param time
+	 * @param type
+	 *            鏃堕棿绫诲瀷 1-涓嬪崟鏃堕棿 2-瀹屾垚鏃堕棿 3-鏇存柊鏃堕棿
+	 * @return
+	 */
+	public static JDOrderResult getOrderList(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", time);
+		orderReq.put("time", TimeUtil.getGernalTime(time.getTime(), "yyyyMMddHH"));
 
 		json.put("orderReq", orderReq);
-		String result = baseRequest("jd.union.open.order.query", null, json);
+		String result = baseRequest2("jd.union.open.order.query", null, json);
+		try {
+			System.out.println(new String(result.getBytes("GBK"), "UTF-8"));
+			System.out.println(new String(result.getBytes("ISO-8859-1"), "UTF-8"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+
 		JSONObject root = JSONObject.fromObject(result).optJSONObject("jd_union_open_order_query_response");
 		if (root.optInt("code") == 0) {
 			boolean hasMore = root.optBoolean("hasMore");

--
Gitblit v1.8.0