From 8ce7c720e4e7a604b0ff770349b5556f39d37759 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 13 九月 2021 11:44:38 +0800 Subject: [PATCH] 好省呗应用兼容 --- fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java | 104 +++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 91 insertions(+), 13 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..a5d6576 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 @@ -28,9 +28,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"; @@ -105,7 +107,7 @@ 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); @@ -168,7 +170,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); @@ -321,16 +323,90 @@ } - 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("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", 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", 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 @@ -445,7 +521,7 @@ */ public static PDDGoodsDetail getGoodsDetail(Long goodsId) { try { - return getGoodsDetail(goodsId, PID_FANLI, "437032"); + return getGoodsDetail(goodsId, PID_DEFAULT, "437032"); } catch (PDDApiException e) { e.printStackTrace(); } @@ -513,7 +589,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"); @@ -626,9 +702,11 @@ // PDDConvertLinkResultVO vo = getAuthLink(PID_SHARE, PinDuoDuoUtil.getCustomParams(437032l)); // // System.out.println(vo); - PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(227873724698L); +// PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(227873724698L); + PDDConvertLinkResultVO vo = convertChannel("0", PID_DEFAULT, null); - PinDuoDuoApiUtil.convert(goods.getGoodsSign(), PID_FANLI + "","437032", false); + System.out.println(vo); +// PinDuoDuoApiUtil.convert(goods.getGoodsSign(), PID_DEFAULT + "", "437032", false); } } -- Gitblit v1.8.0