| | |
| | | import java.util.*; |
| | | |
| | | import com.yeshi.fanli.exception.pdd.PDDApiException; |
| | | import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO; |
| | | import org.yeshi.utils.HttpUtil; |
| | | |
| | | import com.google.gson.Gson; |
| | |
| | | * @param customParams |
| | | * @return |
| | | */ |
| | | public static PDDPromotionUrl convert(String goodsSign, String pid, String customParams, boolean withAuthLink) { |
| | | public static PDDConvertLinkResultVO convert(String goodsSign, String pid, String customParams, boolean withAuthLink) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("type", "pdd.ddk.goods.promotion.url.generate"); |
| | | map.put("p_id", pid); |
| | |
| | | } |
| | | JSONArray resultArray = json.optJSONArray("goods_promotion_url_list"); |
| | | if (resultArray != null && resultArray.size() > 0) { |
| | | Type type = new TypeToken<PDDPromotionUrl>() { |
| | | Type type = new TypeToken<PDDConvertLinkResultVO>() { |
| | | }.getType(); |
| | | Gson gson = new GsonBuilder().disableHtmlEscaping().create(); |
| | | return gson.fromJson(resultArray.optJSONObject(0).toString(), type); |
| | |
| | | * @return |
| | | */ |
| | | public static String getPromotionUrl(String goodsSign, String pid, String customParams) { |
| | | PDDPromotionUrl promotion = convert(goodsSign, pid, customParams, false); |
| | | PDDConvertLinkResultVO promotion = convert(goodsSign, pid, customParams, false); |
| | | if (promotion != null) { |
| | | return promotion.getShortUrl(); |
| | | return promotion.getShort_url(); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public static String getAuthLink(String pid, String customParameters) { |
| | | /** |
| | | * 生成授权链接 |
| | | * |
| | | * @param pid |
| | | * @param customParameters |
| | | * @return |
| | | */ |
| | | public static PDDConvertLinkResultVO getAuthLink(String pid, String 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("p_id_list", "[\"" + pid + "\"]"); |
| | | String result = baseRequest(map); |
| | | System.out.println(result); |
| | | JSONObject resultJson = JSONObject.fromObject(result); |
| | | JSONArray array = resultJson.optJSONObject("rp_promotion_url_generate_response").optJSONArray("url_list"); |
| | | if (array != null && array.size() > 0) { |
| | | JSONObject item = array.optJSONObject(0); |
| | | String url = item.optString("url"); |
| | | if (StringUtil.isNullOrEmpty(url)) { |
| | | url = item.optString("mobile_url"); |
| | | } |
| | | return url; |
| | | Type type = new TypeToken<List<PDDConvertLinkResultVO>>() { |
| | | }.getType(); |
| | | List<PDDConvertLinkResultVO> list = new Gson().fromJson(array.toString(), type); |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | // PDDConvertLinkResultVO vo = getAuthLink(PID_SHARE, PinDuoDuoUtil.getCustomParams(437032l)); |
| | | // |
| | | // System.out.println(vo); |
| | | PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(227873724698L); |
| | | |
| | | |
| | | PinDuoDuoApiUtil.convert(goods.getGoodsSign(), PID_FANLI + "","437032", false); |
| | | } |
| | | } |