From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/util/suning/SuningApiUtil.java | 684 +++++++++++++++++++++++++++++--------------------------- 1 files changed, 357 insertions(+), 327 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/suning/SuningApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/suning/SuningApiUtil.java index 50e736d..b7bafc1 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/suning/SuningApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/suning/SuningApiUtil.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; +import com.yeshi.fanli.vo.suning.SuningConvertLinkResult; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.PostMethod; @@ -29,370 +30,399 @@ public class SuningApiUtil { - public final static String APP_SECRET = "a217bc7018fd8ca112bb60f09057d996"; - public final static String APP_KEY = "6fca015e83eff7ef150bebcad418ea32"; + public final static String APP_SECRET = "a217bc7018fd8ca112bb60f09057d996"; + public final static String APP_KEY = "6fca015e83eff7ef150bebcad418ea32"; - public final static String PID_SHARE = "666527"; - public final static String PID_BUY = "666526"; - public final static String PID_COUPON = "666528"; +// public final static String PID_SHARE = "666527"; +// public final static String PID_BUY = "666526"; +// public final static String PID_COUPON = "666528"; - private static String post(String url, String entity, Map<String, String> headers) { - String charset = "utf-8"; - HttpClient client = new HttpClient(); - PostMethod method = new PostMethod(url); - method.addRequestHeader("Content-Type", "text/html;charset=" + charset); - method.setRequestHeader("Content-Type", "text/html;charset=" + charset); - method.setRequestBody(entity); - for (Iterator<String> its = headers.keySet().iterator(); its.hasNext();) { - String key = its.next(); - method.addRequestHeader(key, headers.get(key)); - } + public final static String PID_DEFAULT = "666526"; - try { - client.executeMethod(method); - return method.getResponseBodyAsString(); - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return ""; - } + private static String post(String url, String entity, Map<String, String> headers) { + String charset = "utf-8"; + HttpClient client = new HttpClient(); + PostMethod method = new PostMethod(url); + method.addRequestHeader("Content-Type", "text/html;charset=" + charset); + method.setRequestHeader("Content-Type", "text/html;charset=" + charset); + method.setRequestBody(entity); + for (Iterator<String> its = headers.keySet().iterator(); its.hasNext(); ) { + String key = its.next(); + method.addRequestHeader(key, headers.get(key)); + } - private static String getSign(Map<String, String> baseParams, String resParams) { - StringBuffer sb = new StringBuffer(); - try { - sb.append(APP_SECRET); - sb.append(baseParams.get("appMethod")); - sb.append(baseParams.get("appRequestTime")); - sb.append(baseParams.get("appKey")); - sb.append(baseParams.get("versionNo")); - } catch (Exception e) { + try { + client.executeMethod(method); + return method.getResponseBodyAsString(); + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } - } + private static String getSign(Map<String, String> baseParams, String resParams) { + StringBuffer sb = new StringBuffer(); + try { + sb.append(APP_SECRET); + sb.append(baseParams.get("appMethod")); + sb.append(baseParams.get("appRequestTime")); + sb.append(baseParams.get("appKey")); + sb.append(baseParams.get("versionNo")); + } catch (Exception e) { - try { - sb.append(StringUtil.getBase64String(resParams)); - } catch (Exception e) { - e.printStackTrace(); - } + } - return StringUtil.Md5(sb.toString()); - } + try { + sb.append(StringUtil.getBase64String(resParams)); + } catch (Exception e) { + e.printStackTrace(); + } - private static String baseRequest(String method, JSONObject params) { - Map<String, String> baseParams = new HashMap<>(); - baseParams.put("appMethod", method); - baseParams.put("appRequestTime", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); - baseParams.put("format", "json"); - baseParams.put("appKey", APP_KEY); - baseParams.put("versionNo", "v1.2"); - String sign = getSign(baseParams, params.toString()); - baseParams.put("signInfo", sign); - String result = post("https://open.suning.com/api/http/sopRequest/" + method, params.toString(), baseParams); - System.out.println(result); - return result; - } + return StringUtil.Md5(sb.toString()); + } - private static String baseRequest(String method, String key, JSONObject params) { - JSONObject keyJSON = new JSONObject(); - for (Iterator<String> its = params.keySet().iterator(); its.hasNext();) { - String k = its.next(); - keyJSON.put(k, params.get(k)); - } - JSONObject content = new JSONObject(); - content.put(key, keyJSON); - JSONObject body = new JSONObject(); - body.put("sn_body", content); - JSONObject request = new JSONObject(); - request.put("sn_request", body); - return baseRequest(method, request); - } + private static String baseRequest(String method, JSONObject params) { + Map<String, String> baseParams = new HashMap<>(); + baseParams.put("appMethod", method); + baseParams.put("appRequestTime", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); + baseParams.put("format", "json"); + baseParams.put("appKey", APP_KEY); + baseParams.put("versionNo", "v1.2"); + String sign = getSign(baseParams, params.toString()); + baseParams.put("signInfo", sign); + String result = post("https://open.suning.com/api/http/sopRequest/" + method, params.toString(), baseParams); + System.out.println(result); + return result; + } - /** - * 鏌ヨ鍟嗗搧 - * @Title: searchGoods - * @Description: - * @param model - * @return - * List<SuningGoodsInfo> 杩斿洖绫诲瀷 - * @throws - */ - public static List<SuningGoodsInfo> searchGoods(SuningQueryModel model) { - model.setPicWidth(320); - model.setPicHeight(320); - String key = "querySearchcommoditynew"; - String json = new Gson().toJson(model); - // String result = - // baseRequest("suning.netalliance.searchcommoditynew.query", key, - // JSONObject.fromObject(json)); - String result = baseRequest("suning.netalliance.searchcommoditynew.query", key, JSONObject.fromObject(json)); - JSONObject resultJSON = JSONObject.fromObject(result); - JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONObject(key) - .optJSONArray("commodityList"); - if (array != null) { - Type type = new TypeToken<ArrayList<SuningGoodsInfo>>() { - }.getType(); - List<SuningGoodsInfo> goodsList = new Gson().fromJson(array.toString(), type); - return goodsList; - } + private static String baseRequest(String method, String key, JSONObject params) { + JSONObject keyJSON = new JSONObject(); + for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) { + String k = its.next(); + keyJSON.put(k, params.get(k)); + } + JSONObject content = new JSONObject(); + content.put(key, keyJSON); + JSONObject body = new JSONObject(); + body.put("sn_body", content); + JSONObject request = new JSONObject(); + request.put("sn_request", body); + return baseRequest(method, request); + } - return null; - } + /** + * 鏌ヨ鍟嗗搧 + * + * @param model + * @return List<SuningGoodsInfo> 杩斿洖绫诲瀷 + * @throws + * @Title: searchGoods + * @Description: + */ + public static List<SuningGoodsInfo> searchGoods(SuningQueryModel model) { + model.setPicWidth(320); + model.setPicHeight(320); + String key = "querySearchcommoditynew"; + String json = new Gson().toJson(model); + // String result = + // baseRequest("suning.netalliance.searchcommoditynew.query", key, + // JSONObject.fromObject(json)); + String result = baseRequest("suning.netalliance.searchcommoditynew.query", key, JSONObject.fromObject(json)); + JSONObject resultJSON = JSONObject.fromObject(result); + JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONObject(key) + .optJSONArray("commodityList"); + if (array != null) { + Type type = new TypeToken<ArrayList<SuningGoodsInfo>>() { + }.getType(); + List<SuningGoodsInfo> goodsList = new Gson().fromJson(array.toString(), type); + return goodsList; + } - /** - * 鏌ヨ鍟嗗搧 - * @Title: searchGoods - * @Description: - * @param model - * @return - * List<SuningGoodsInfo> 杩斿洖绫诲瀷 - * @throws - */ - public static List<SuningGoodsInfo> searchGoodsOld(SuningQueryModel model) { - model.setPicWidth(320); - model.setPicHeight(320); - String key = "querySearchcommodity"; - String json = new Gson().toJson(model); - String result = baseRequest("suning.netalliance.searchcommodity.query", key, JSONObject.fromObject(json)); - JSONObject resultJSON = JSONObject.fromObject(result); - JSONObject responseContent = resultJSON.optJSONObject("sn_responseContent"); - if (responseContent != null) { - JSONObject snBody = responseContent.optJSONObject("sn_body"); - if (snBody != null) { - JSONArray array = snBody.optJSONArray(key); - if (array != null) { - Type type = new TypeToken<ArrayList<SuningGoodsInfo>>() { - }.getType(); - List<SuningGoodsInfo> goodsList = new Gson().fromJson(array.toString(), type); - return goodsList; - } - } - } - return null; - } + return null; + } - public static SuningGoodsInfo getGoodsDetail(String goodsCode, String supplierCode) { - JSONObject model = new JSONObject(); - model.put("commodityStr", goodsCode + "-" +SuningUtil.getFullSupplierCode( supplierCode)); - model.put("picWidth", 600); - model.put("picHeight", 600); - model.put("couponMark", 1); + /** + * 鏌ヨ鍟嗗搧 + * + * @param model + * @return List<SuningGoodsInfo> 杩斿洖绫诲瀷 + * @throws + * @Title: searchGoods + * @Description: + */ + public static List<SuningGoodsInfo> searchGoodsOld(SuningQueryModel model) { + model.setPicWidth(320); + model.setPicHeight(320); + String key = "querySearchcommodity"; + String json = new Gson().toJson(model); + String result = baseRequest("suning.netalliance.searchcommodity.query", key, JSONObject.fromObject(json)); + JSONObject resultJSON = JSONObject.fromObject(result); + JSONObject responseContent = resultJSON.optJSONObject("sn_responseContent"); + if (responseContent != null) { + JSONObject snBody = responseContent.optJSONObject("sn_body"); + if (snBody != null) { + JSONArray array = snBody.optJSONArray(key); + if (array != null) { + Type type = new TypeToken<ArrayList<SuningGoodsInfo>>() { + }.getType(); + List<SuningGoodsInfo> goodsList = new Gson().fromJson(array.toString(), type); + return goodsList; + } + } + } + return null; + } - String key = "queryCommoditydetail"; - String result = baseRequest("suning.netalliance.commoditydetail.query", key, model); - System.out.println(result); - JSONObject resultJSON = JSONObject.fromObject(result); - - if( resultJSON.optJSONObject("sn_responseContent")==null) - return null; - if(resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body")==null) - return null; - - JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONArray(key); - if (array != null && array.size() > 0) { - return new Gson().fromJson(array.optJSONObject(0).toString(), SuningGoodsInfo.class); - } - return null; - } + public static SuningGoodsInfo getGoodsDetail(String goodsCode, String supplierCode) { + JSONObject model = new JSONObject(); + model.put("commodityStr", goodsCode + "-" + SuningUtil.getFullSupplierCode(supplierCode)); + model.put("picWidth", 600); + model.put("picHeight", 600); + model.put("couponMark", 1); - /** - * 鏌ヨ鍏宠仈鍟嗗搧 - * @Title: searchGoods - * @Description: - * @param model - * @return - * List<SuningGoodsInfo> 杩斿洖绫诲瀷 - * @throws - */ - public static List<SuningGoodsInfoRecommend> getRecommendGoods(String goodsCode, String supplierCode) { - JSONObject model = new JSONObject(); - model.put("commodityCode", goodsCode); - model.put("supplierCode", supplierCode); - model.put("picWidth", 320); - model.put("picHeight", 320); + String key = "queryCommoditydetail"; + String result = baseRequest("suning.netalliance.commoditydetail.query", key, model); + System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); - String key = "getMorerecommend"; - String json = new Gson().toJson(model); - String result = baseRequest("suning.netalliance.morerecommend.get", key, JSONObject.fromObject(json)); - JSONObject resultJSON = JSONObject.fromObject(result); - JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONObject(key) - .optJSONArray("commodityList"); - if (array != null) { - Type type = new TypeToken<ArrayList<SuningGoodsInfoRecommend>>() { - }.getType(); - List<SuningGoodsInfoRecommend> goodsList = new Gson().fromJson(array.toString(), type); - return goodsList; - } - return null; - } + if (resultJSON.optJSONObject("sn_responseContent") == null) + return null; + if (resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body") == null) + return null; - public static List<SuningGoodsInfo> getGoodsDetailList(List<String> list) { - String sts = ""; - for (String st : list) { - sts += st + "_"; - } + JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONArray(key); + if (array != null && array.size() > 0) { + return new Gson().fromJson(array.optJSONObject(0).toString(), SuningGoodsInfo.class); + } + return null; + } - if (sts.endsWith("_")) - sts = sts.substring(0, sts.length() - 1); + /** + * 鏌ヨ鍏宠仈鍟嗗搧 + * + * @param model + * @return List<SuningGoodsInfo> 杩斿洖绫诲瀷 + * @throws + * @Title: searchGoods + * @Description: + */ + public static List<SuningGoodsInfoRecommend> getRecommendGoods(String goodsCode, String supplierCode) { + JSONObject model = new JSONObject(); + model.put("commodityCode", goodsCode); + model.put("supplierCode", supplierCode); + model.put("picWidth", 320); + model.put("picHeight", 320); - JSONObject model = new JSONObject(); - model.put("commodityStr", sts); - model.put("picWidth", 300); - model.put("picHeight", 300); - model.put("couponMark", 1); - List<SuningGoodsInfo> goodsList = new ArrayList<>(); + String key = "getMorerecommend"; + String json = new Gson().toJson(model); + String result = baseRequest("suning.netalliance.morerecommend.get", key, JSONObject.fromObject(json)); + JSONObject resultJSON = JSONObject.fromObject(result); + JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONObject(key) + .optJSONArray("commodityList"); + if (array != null) { + Type type = new TypeToken<ArrayList<SuningGoodsInfoRecommend>>() { + }.getType(); + List<SuningGoodsInfoRecommend> goodsList = new Gson().fromJson(array.toString(), type); + return goodsList; + } + return null; + } - String key = "queryCommoditydetail"; - String result = baseRequest("suning.netalliance.commoditydetail.query", key, model); - System.out.println(result); - JSONObject resultJSON = JSONObject.fromObject(result); - JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONArray(key); - if (array != null && array.size() > 0) { - for (int i = 0; i < array.size(); i++) { - goodsList.add(new Gson().fromJson(array.optJSONObject(i).toString(), SuningGoodsInfo.class)); - } - } - return goodsList; - } + public static List<SuningGoodsInfo> getGoodsDetailList(List<String> list) { + String sts = ""; + for (String st : list) { + sts += st + "_"; + } - public static String convertLink(String productUrl, String quanUrl, String pid, String subUser) { - JSONObject model = new JSONObject(); - if (productUrl != null) - model.put("productUrl", productUrl); + if (sts.endsWith("_")) + sts = sts.substring(0, sts.length() - 1); - if (!StringUtil.isNullOrEmpty(quanUrl)) - model.put("quanUrl", quanUrl); + JSONObject model = new JSONObject(); + model.put("commodityStr", sts); + model.put("picWidth", 300); + model.put("picHeight", 300); + model.put("couponMark", 1); + List<SuningGoodsInfo> goodsList = new ArrayList<>(); - if (pid != null) - model.put("promotionId", pid); + String key = "queryCommoditydetail"; + String result = baseRequest("suning.netalliance.commoditydetail.query", key, model); + System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); + JSONArray array = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONArray(key); + if (array != null && array.size() > 0) { + for (int i = 0; i < array.size(); i++) { + goodsList.add(new Gson().fromJson(array.optJSONObject(i).toString(), SuningGoodsInfo.class)); + } + } + return goodsList; + } - if (subUser != null) - model.put("subUser", subUser); + public static String convertLink(String productUrl, String quanUrl, String pid, String subUser) { + JSONObject model = new JSONObject(); + if (productUrl != null) + model.put("productUrl", productUrl); - String key = "getExtensionlink"; - String result = baseRequest("suning.netalliance.extensionlink.get", key, model); - System.out.println(result); - JSONObject resultJSON = JSONObject.fromObject(result); - JSONObject json = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONObject(key); - String link = json.optString("shortLink"); - return link; - } + if (!StringUtil.isNullOrEmpty(quanUrl)) + model.put("quanUrl", quanUrl); - /** - * 0 - * @Title: getOrderList - * @Description: - * @param startTime - * @param endTime - * @param page - * @param orderLineStatus 锛�0锛氬叏閮ㄧ姸鎬侊紱1锛氱瓑寰呬粯娆撅紱2锛氭敮浠樺畬鎴愶紱3锛氶��娆撅紱4锛氳鍗曞凡鍙栨秷锛�5锛氱‘璁ゆ敹璐э級 - * @return - * SuningOrderQueryResultDTO 杩斿洖绫诲瀷 - * @throws - */ - public static SuningOrderQueryResultDTO getOrderList(Date startTime, Date endTime, int page, int orderLineStatus) { - JSONObject model = new JSONObject(); - model.put("startTime", TimeUtil.getGernalTime(startTime.getTime(), "yyyy-MM-dd HH:mm:ss")); - model.put("endTime", TimeUtil.getGernalTime(endTime.getTime(), "yyyy-MM-dd HH:mm:ss")); - model.put("pageSize", 20); - model.put("pageNo", page); - model.put("orderLineStatus", orderLineStatus); + if (pid != null) + model.put("promotionId", pid); - String key = "queryOrder"; - String result = baseRequest("suning.netalliance.order.query", key, model); - JSONObject resultJSON = JSONObject.fromObject(result); - resultJSON = resultJSON.optJSONObject("sn_responseContent"); - JSONObject snBody = resultJSON.optJSONObject("sn_body"); - if (snBody == null) - return null; + if (subUser != null) + model.put("subUser", subUser); - JSONArray array = snBody.optJSONArray(key); + String key = "getExtensionlink"; + String result = baseRequest("suning.netalliance.extensionlink.get", key, model); + System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); + JSONObject json = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONObject(key); + String link = json.optString("shortLink"); + return link; + } - if (array == null) - return null; - Gson gson = new Gson(); + public static SuningConvertLinkResult convertLinkNew(String commCode, String mertCode, String pid, String subUser) { + JSONObject model = new JSONObject(); + if (commCode != null) + model.put("commCode", commCode); - Type type = new TypeToken<ArrayList<SuningOrderInfo>>() { - }.getType(); + if (!StringUtil.isNullOrEmpty(mertCode)) + model.put("mertCode", mertCode); - if (array != null) { - List<SuningOrderInfo> orderList = new ArrayList<>(); - for (int i = 0; i < array.size(); i++) { - JSONObject data = array.optJSONObject(i); - JSONArray itemArray = data.optJSONArray("orderDetail"); - List<SuningOrderInfo> tempList = gson.fromJson(itemArray.toString(), type); - for (SuningOrderInfo info : tempList) { - info.setOrderCode(data.optString("orderCode")); - orderList.add(info); - } - } + if (pid != null) + model.put("adBookId", pid); - return new SuningOrderQueryResultDTO(resultJSON.optJSONObject("sn_head").optInt("totalSize"), orderList); - } + if (subUser != null) + model.put("subUser", subUser); - return null; - } + String key = "queryStorepromotionurl"; + String result = baseRequest("suning.netalliance.storepromotionurl.query", key, model); + System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); + JSONObject json = resultJSON.optJSONObject("sn_responseContent").optJSONObject("sn_body").optJSONObject(key); - /** - * 甯歌杞摼 - * @Title: convertCommonLink - * @Description: - * @param url - * @param pid - * @param subUser - * @return - * String 杩斿洖绫诲瀷 - * @throws - */ - public static String convertCommonLink(String url, String pid, String subUser) { - JSONObject model = new JSONObject(); - model.put("adBookId", pid); - model.put("visitUrl", url); - model.put("subUser", subUser); + return new Gson().fromJson(json.toString(), SuningConvertLinkResult.class); + } - String key = "queryCustompromotionurl"; - String result = baseRequest("suning.netalliance.custompromotionurl.query", key, model); - JSONObject resultJSON = JSONObject.fromObject(result); - resultJSON = resultJSON.optJSONObject("sn_responseContent"); - String shortUrl = resultJSON.optJSONObject("sn_body").optJSONObject("queryCustompromotionurl") - .optString("shortUrl"); - return URLDecoder.decode(shortUrl); - } - /** - * 鍟嗗搧绮鹃�夋帴鍙� - * @Title: getSelectRecommendGoods - * @Description: - * @param eliteId - * @param page - * @return - * List<SuningGoodsInfo> 杩斿洖绫诲瀷 - * @throws - */ - public static List<SuningGoodsInfo> getSelectRecommendGoods(int eliteId, int page) { - JSONObject model = new JSONObject(); - model.put("eliteId", eliteId); - model.put("pageIndex", page); - // model.put("picWidth", 320); - // model.put("picHeight", 320); - model.put("size", 10); - model.put("couponMark", 1); + /** + * 0 + * + * @param startTime + * @param endTime + * @param page + * @param orderLineStatus 锛�0锛氬叏閮ㄧ姸鎬侊紱1锛氱瓑寰呬粯娆撅紱2锛氭敮浠樺畬鎴愶紱3锛氶��娆撅紱4锛氳鍗曞凡鍙栨秷锛�5锛氱‘璁ゆ敹璐э級 + * @return SuningOrderQueryResultDTO 杩斿洖绫诲瀷 + * @throws + * @Title: getOrderList + * @Description: + */ + public static SuningOrderQueryResultDTO getOrderList(Date startTime, Date endTime, int page, int orderLineStatus) { + JSONObject model = new JSONObject(); + model.put("startTime", TimeUtil.getGernalTime(startTime.getTime(), "yyyy-MM-dd HH:mm:ss")); + model.put("endTime", TimeUtil.getGernalTime(endTime.getTime(), "yyyy-MM-dd HH:mm:ss")); + model.put("pageSize", 20); + model.put("pageNo", page); + model.put("orderLineStatus", orderLineStatus); - String key = "querySelectrecommendcommodity"; - String result = baseRequest("suning.netalliance.selectrecommendcommodity.query", key, model); - System.out.println(result); - JSONObject resultJSON = JSONObject.fromObject(result); - resultJSON = resultJSON.optJSONObject("sn_responseContent"); - JSONArray array = resultJSON.optJSONObject("sn_body").optJSONObject(key).optJSONArray("commodityList"); - if (array != null) { - Type type = new TypeToken<ArrayList<SuningGoodsInfo>>() { - }.getType(); - List<SuningGoodsInfo> goodsList = new Gson().fromJson(array.toString(), type); - return goodsList; - } - return null; - } + String key = "queryOrder"; + String result = baseRequest("suning.netalliance.order.query", key, model); + JSONObject resultJSON = JSONObject.fromObject(result); + resultJSON = resultJSON.optJSONObject("sn_responseContent"); + JSONObject snBody = resultJSON.optJSONObject("sn_body"); + if (snBody == null) + return null; + + JSONArray array = snBody.optJSONArray(key); + + if (array == null) + return null; + + Gson gson = new Gson(); + + Type type = new TypeToken<ArrayList<SuningOrderInfo>>() { + }.getType(); + + if (array != null) { + List<SuningOrderInfo> orderList = new ArrayList<>(); + for (int i = 0; i < array.size(); i++) { + JSONObject data = array.optJSONObject(i); + JSONArray itemArray = data.optJSONArray("orderDetail"); + List<SuningOrderInfo> tempList = gson.fromJson(itemArray.toString(), type); + for (SuningOrderInfo info : tempList) { + info.setOrderCode(data.optString("orderCode")); + orderList.add(info); + } + } + + return new SuningOrderQueryResultDTO(resultJSON.optJSONObject("sn_head").optInt("totalSize"), orderList); + } + + return null; + } + + /** + * 甯歌杞摼 + * + * @param url + * @param pid + * @param subUser + * @return String 杩斿洖绫诲瀷 + * @throws + * @Title: convertCommonLink + * @Description: + */ + public static String convertCommonLink(String url, String pid, String subUser) { + JSONObject model = new JSONObject(); + model.put("adBookId", pid); + model.put("visitUrl", url); + model.put("subUser", subUser); + + String key = "queryCustompromotionurl"; + String result = baseRequest("suning.netalliance.custompromotionurl.query", key, model); + System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); + resultJSON = resultJSON.optJSONObject("sn_responseContent"); + String shortUrl = resultJSON.optJSONObject("sn_body").optJSONObject("queryCustompromotionurl") + .optString("shortUrl"); + return URLDecoder.decode(shortUrl); + } + + /** + * 鍟嗗搧绮鹃�夋帴鍙� + * + * @param eliteId + * @param page + * @return List<SuningGoodsInfo> 杩斿洖绫诲瀷 + * @throws + * @Title: getSelectRecommendGoods + * @Description: + */ + public static List<SuningGoodsInfo> getSelectRecommendGoods(int eliteId, int page) { + JSONObject model = new JSONObject(); + model.put("eliteId", eliteId); + model.put("pageIndex", page); + // model.put("picWidth", 320); + // model.put("picHeight", 320); + model.put("size", 10); + model.put("couponMark", 1); + + String key = "querySelectrecommendcommodity"; + String result = baseRequest("suning.netalliance.selectrecommendcommodity.query", key, model); + System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); + resultJSON = resultJSON.optJSONObject("sn_responseContent"); + JSONArray array = resultJSON.optJSONObject("sn_body").optJSONObject(key).optJSONArray("commodityList"); + if (array != null) { + Type type = new TypeToken<ArrayList<SuningGoodsInfo>>() { + }.getType(); + List<SuningGoodsInfo> goodsList = new Gson().fromJson(array.toString(), type); + return goodsList; + } + return null; + } + } -- Gitblit v1.8.0