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/pinduoduo/PinDuoDuoApiUtil.java | 205 +++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 157 insertions(+), 48 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java index 9276fd0..2a38815 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java @@ -5,6 +5,7 @@ import java.net.URLEncoder; import java.util.*; +import com.google.gson.JsonObject; import com.yeshi.fanli.exception.pdd.PDDApiException; import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO; import org.yeshi.utils.HttpUtil; @@ -28,9 +29,11 @@ import net.sf.json.JSONObject; public class PinDuoDuoApiUtil { - public final static String PID_FANLI = "8590899_72067894"; - public final static String PID_SHARE = "8590899_72067895"; - public final static String PID_COUPON = "8590899_102657575"; +// public final static String PID_FANLI = "8590899_72067894"; +// public final static String PID_SHARE = "8590899_72067895"; +// public final static String PID_COUPON = "8590899_102657575"; + + public final static String PID_DEFAULT = "8590899_72067894"; private final static String CLIENT_ID = "9f6ee5ebd3b94c2080c4d51c2427e9fa"; private final static String CLIENT_SECRET = "95e1f1904385664bf4b87d4b34de12f9f31c505d"; @@ -48,6 +51,15 @@ org += key + map.get(key); } return StringUtil.Md5(CLIENT_SECRET + org + CLIENT_SECRET).toUpperCase(); + } + + private static String getFormatCustomParameters(String customParameters){ + customParameters=customParameters.replace("_",""); + JSONObject data=new JSONObject(); + data.put("uid",customParameters); + String custom = data.toString(); + System.out.println("鑷畾涔夊弬鏁帮細"+custom); + return custom; } private static String baseRequest(Map<String, String> map) { @@ -79,7 +91,7 @@ Gson gson = new GsonBuilder().disableHtmlEscaping().create(); Map<String, String> map = new HashMap<>(); map.put("type", "pdd.ddk.goods.search"); - map.put("custom_parameters", customerParamters); + map.put("custom_parameters", getFormatCustomParameters(customerParamters)); if (sf.getOptId() != null) map.put("opt_id", sf.getOptId() + ""); if (sf.getPage() != null) @@ -105,13 +117,13 @@ map.put("range_list", gson.toJson(sf.getRangeList()).toString()); } - map.put("pid", PID_FANLI); + map.put("pid", PID_DEFAULT); String result = baseRequest(map); System.out.println(result); JSONObject json = JSONObject.fromObject(result); if (json.optJSONObject("error_response") != null) { int errorCode = json.optJSONObject("error_response").optInt("sub_code"); - throw new PDDApiException(errorCode, json.optJSONObject("error_response").optString("sub_msg")); + throw new PDDApiException(errorCode, json.optJSONObject("error_response").optString("sub_msg")); } JSONObject root = json.optJSONObject("goods_search_response"); @@ -168,7 +180,7 @@ map.put("activity_tags", JSONArray.fromObject(Arrays.asList(activityTags)).toString()); } - map.put("pid", PID_FANLI); + map.put("pid", PID_DEFAULT); String result = baseRequest(map); JSONObject json = JSONObject.fromObject(result); @@ -288,6 +300,7 @@ map.put("type", "pdd.ddk.goods.promotion.url.generate"); map.put("p_id", pid); map.put("multi_group", "true"); + map.put("generate_schema_url","true"); map.put("generate_weapp_webview", "true"); map.put("generate_we_app", "true"); @@ -296,7 +309,7 @@ array.add(goodsSign); map.put("goods_sign_list", array.toString()); if (!StringUtil.isNullOrEmpty(customParams)) { - map.put("custom_parameters", customParams); + map.put("custom_parameters", getFormatCustomParameters(customParams)); } //鏄惁鐢熸垚甯︽巿鏉冪殑鍗曞搧閾炬帴 @@ -321,22 +334,97 @@ } - public static PDDPromotionUrl convertResourceUrl(String pid) { + /** + * 娲诲姩杞摼 https://open.pinduoduo.com/application/document/api?id=pdd.ddk.resource.url.gen + * + * @param resourceType + * @param url + * @param pid + * @param customParams + * @return + */ + public static PDDConvertLinkResultVO convertActivity(String resourceType, String url, String pid, String customParams) { Map<String, String> map = new HashMap<>(); map.put("type", "pdd.ddk.resource.url.gen"); + map.put("generate_schema_url","true"); map.put("pid", pid); - map.put("resource_type", "39998"); - map.put("url", "https://mobile.yangkeduo.com/attendance.html?_pdd_fs=1&_pdd_tc=ffffff&_pdd_sbs=1&type=1&id=155075"); + if (customParams != null) { + map.put("custom_parameters", getFormatCustomParameters(customParams)); + } + map.put("resource_type", resourceType); + if (url != null) { + map.put("url", url); + } + + String result = baseRequest(map); + JSONObject root = JSONObject.fromObject(result); + JSONObject json = root.optJSONObject("resource_url_response"); + if (json == null) { + return null; + } + JSONObject urlJSON = json.optJSONObject("single_url_list"); + PDDConvertLinkResultVO vo = null; + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + if (urlJSON != null) { + + vo = gson.fromJson(urlJSON.toString(), PDDConvertLinkResultVO.class); + } + JSONObject weAppInfo = json.optJSONObject("we_app_info"); + if (weAppInfo != null && vo != null) { + PDDConvertLinkResultVO.WeAppInfoBean weAppInfoBean = gson.fromJson(weAppInfo.toString(), PDDConvertLinkResultVO.WeAppInfoBean.class); + vo.setWe_app_info(weAppInfoBean); + } + + return vo; + } + + + /** + * 棰戦亾鎺ㄥ箍锛坔ttps://open.pinduoduo.com/application/document/api?id=pdd.ddk.cms.prom.url.generate锛� + * + * @param channelType + * @param pid + * @param customParams + * @return + */ + + public static PDDConvertLinkResultVO convertChannel(String channelType, String pid, String customParams) { + Map<String, String> map = new HashMap<>(); + map.put("type", "pdd.ddk.cms.prom.url.generate"); + map.put("p_id_list", "[\"" + pid + "\"]"); + if (customParams != null) { + map.put("custom_parameters", getFormatCustomParameters(customParams)); + } + map.put("channel_type", channelType); + map.put("generate_mobile", true+""); + map.put("generate_short_url", true+""); + map.put("generate_we_app", true+""); + + + String result = baseRequest(map); System.out.println(result); - return null; + JSONObject root = JSONObject.fromObject(result); + JSONObject json = root.optJSONObject("cms_promotion_url_generate_response"); + if (json == null) { + return null; + } + JSONObject urlJSON = json.optJSONArray("url_list").optJSONObject(0); + PDDConvertLinkResultVO vo = null; + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + if (urlJSON != null) { + vo = gson.fromJson(urlJSON.toString(), PDDConvertLinkResultVO.class); + } + + return vo; } + /** * 寰俊灏忕▼搴忚浆閾� @Title: convertWXMP @Description: @param goodsId @param * pid @param customParams @return PDDPromotionUrl 杩斿洖绫诲瀷 @throws */ - public static String convertWXMP(Long goodsId, String pid, String customParams) { + public static String convertWXMP(String goodsId, String pid, String customParams) { Map<String, String> map = new HashMap<>(); map.put("type", "pdd.ddk.goods.promotion.url.generate"); map.put("p_id", pid); @@ -347,7 +435,7 @@ array.add(goodsId); map.put("goods_id_list", array.toString()); if (!StringUtil.isNullOrEmpty(customParams)) { - map.put("custom_parameters", customParams); + map.put("custom_parameters", getFormatCustomParameters(customParams)); } String result = baseRequest(map); @@ -412,14 +500,21 @@ map.put("page_size", pageSize + ""); String result = baseRequest(map); System.out.println(result); - JSONObject json = JSONObject.fromObject(result); - JSONObject root = json.optJSONObject("order_list_get_response"); + com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(result); + com.alibaba.fastjson.JSONObject root = json.getJSONObject("order_list_get_response"); if (root != null) { - int totalCount = root.optInt("total_count"); - JSONArray array = root.optJSONArray("order_list"); - Type type = new TypeToken<List<PDDOrder>>() { - }.getType(); - List<PDDOrder> orderList = new Gson().fromJson(array.toString(), type); + int totalCount = root.getInteger("total_count"); + com.alibaba.fastjson.JSONArray array = root.getJSONArray("order_list"); + Type type=new TypeToken<List<PDDOrder>>(){}.getType(); + List<PDDOrder> orderList = new Gson().fromJson( array.toJSONString(), type); + // 澶勭悊custom_params + for(PDDOrder order:orderList){ + String params=order.getCustomParameters(); + if(params.contains("{")) { + JSONObject jsonp = JSONObject.fromObject(params); + order.setCustomParameters(jsonp.optString("uid")); + } + } return new PDDOrderResult(totalCount, orderList); } return null; @@ -430,10 +525,16 @@ map.put("type", "pdd.ddk.order.detail.get"); map.put("order_sn", orderSn); String result = baseRequest(map); - JSONObject json = JSONObject.fromObject(result); - JSONObject root = json.optJSONObject("order_detail_response"); + com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(result); + com.alibaba.fastjson.JSONObject root = json.getJSONObject("order_detail_response"); if (root != null) { - return new Gson().fromJson(root.toString(), PDDOrder.class); + PDDOrder order = new Gson().fromJson(root.toString(), PDDOrder.class); + String params=order.getCustomParameters(); + if(params.contains("{")) { + JSONObject jsonp = JSONObject.fromObject(params); + order.setCustomParameters(jsonp.optString("uid")); + } + return order; } return null; } @@ -441,11 +542,11 @@ /** * 鑾峰彇鍟嗗搧璇︽儏 * - * @param goodsId + * @param goodsSign */ - public static PDDGoodsDetail getGoodsDetail(Long goodsId) { + public static PDDGoodsDetail getGoodsDetail(String goodsSign) { try { - return getGoodsDetail(goodsId, PID_FANLI, "437032"); + return getGoodsDetail(goodsSign, PID_DEFAULT, "437031"); } catch (PDDApiException e) { e.printStackTrace(); } @@ -453,19 +554,9 @@ return null; } - public static PDDGoodsDetail getGoodsDetail(Long goodsId, String pid, String customParameters) throws PDDApiException { + public static PDDGoodsDetail getGoodsDetail(String goodsSign, String pid, String customParameters) throws PDDApiException { - PDDSearchFilter sf = new PDDSearchFilter(); - sf.setKw(goodsId + ""); - PDDGoodsResult goodsResult = searchGoods(sf, customParameters); - if (goodsResult == null) - return null; - - if (goodsResult.getGoodsList() == null || goodsResult.getGoodsList().size() <= 0) { - return null; - } - - String goodsSign = goodsResult.getGoodsList().get(0).getGoodsSign(); +// String goodsSign = goodsResult.getGoodsList().get(0).getGoodsSign(); JSONArray array = new JSONArray(); @@ -478,7 +569,7 @@ } if (!StringUtil.isNullOrEmpty(customParameters)) { - map.put("custom_parameters", customParameters); + map.put("custom_parameters", getFormatCustomParameters(customParameters)); } String result = baseRequest(map); @@ -513,7 +604,7 @@ Map<String, String> map = new HashMap<>(); map.put("type", "pdd.ddk.phrase.generate"); map.put("goods_id_list", array.toString()); - map.put("p_id", PID_FANLI); + map.put("p_id", PID_DEFAULT); String result = baseRequest(map); JSONObject resultJson = JSONObject.fromObject(result); JSONObject root = resultJson.optJSONObject("ddk_phrase_generate_response"); @@ -582,10 +673,13 @@ * @return */ public static boolean isAuth(String pid, String customParameters) { +// customParameters=customParameters.replace("_",""); + + System.out.println("鏄惁鎺堟潈锛�"+pid+"-"+customParameters); Map<String, String> map = new HashMap<>(); map.put("type", "pdd.ddk.member.authority.query"); map.put("pid", pid); - map.put("custom_parameters", customParameters); + map.put("custom_parameters", getFormatCustomParameters(customParameters)); String result = baseRequest(map); JSONObject resultJson = JSONObject.fromObject(result); if (resultJson.optJSONObject("authority_query_response").optInt("bind") == 0) { @@ -603,11 +697,14 @@ * @return */ public static PDDConvertLinkResultVO getAuthLink(String pid, String customParameters) { +// customParameters=customParameters.replace("_",""); + + System.out.println("鑾峰彇鎺堟潈閾炬帴锛�"+pid+"-"+customParameters); Map<String, String> map = new HashMap<>(); map.put("type", "pdd.ddk.rp.prom.url.generate"); map.put("channel_type", 10 + ""); map.put("generate_we_app", true + ""); - map.put("custom_parameters", customParameters); + map.put("custom_parameters",getFormatCustomParameters(customParameters)); map.put("p_id_list", "[\"" + pid + "\"]"); String result = baseRequest(map); System.out.println(result); @@ -622,13 +719,25 @@ return null; } - public static void main(String[] args) { -// PDDConvertLinkResultVO vo = getAuthLink(PID_SHARE, PinDuoDuoUtil.getCustomParams(437032l)); + public static void main(String[] args) throws Exception{ + +// PDDConvertLinkResultVO vo = getAuthLink("8590899_72067894", 437031+""); +// boolean isAuthed = isAuth(PID_DEFAULT, 437031+""); +// System.out.println("鏄惁鎺堟潈锛�"+isAuthed); // -// System.out.println(vo); - PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(227873724698L); +// System.out.println(vo); + PDDSearchFilter searchFilter=new PDDSearchFilter(); + searchFilter.setKw("闉�"); + searchFilter.setPage(1); + searchFilter.setPageSize(20); + PinDuoDuoApiUtil.searchGoods(searchFilter,Constant.PDD_SEARCH_CUSTOMER_PARAMS); +// PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(364476396740L); + // PDDConvertLinkResultVO vo = convertChannel("0", PID_DEFAULT, null); - PinDuoDuoApiUtil.convert(goods.getGoodsSign(), PID_FANLI + "","437032", false); + // System.out.println(vo); +// PDDConvertLinkResultVO goodsc = PinDuoDuoApiUtil.convert(goods.getGoodsSign(), PID_DEFAULT + "", "437031", false); + +// System.out.println(""); } } -- Gitblit v1.8.0