| | |
| | | package com.yeshi.fanli.util.pinduoduo;
|
| | |
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.lang.reflect.Type;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | |
| | |
|
| | | import org.yeshi.utils.HttpUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
|
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
|
| | | import com.yeshi.fanli.dto.pdd.PDDOrderResult;
|
| | | import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
|
| | | import com.yeshi.fanli.entity.pdd.PDDOrder;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | public class PinDuoDuoApiUtil {
|
| | | public final static String PID_FANLI = "8590899_72067894";
|
| | | public final static String PID_SHARE = "8590899_72067895";
|
| | |
|
| | | private final static String CLIENT_ID = "9f6ee5ebd3b94c2080c4d51c2427e9fa";
|
| | | private final static String CLIENT_SECRET = "95e1f1904385664bf4b87d4b34de12f9f31c505d";
|
| | |
|
| | |
| | | return result;
|
| | | }
|
| | |
|
| | | public static void searchGoods(String key) {
|
| | | public static PDDGoodsResult searchGoods(PDDSearchFilter sf) {
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("type", "pdd.ddk.goods.search");
|
| | | map.put("keyword", key);
|
| | | if (sf.getOptId() != null)
|
| | | map.put("opt_id", sf.getOptId() + "");
|
| | | if (sf.getPage() != null)
|
| | | map.put("page", sf.getPage() + "");
|
| | | if (sf.getPageSize() != null)
|
| | | map.put("page_size", sf.getPageSize() + "");
|
| | | if (sf.getSortType() != null)
|
| | | map.put("sort_type", sf.getSortType() + "");
|
| | | if (sf.getHasCoupon() != null)
|
| | | map.put("with_coupon", sf.getHasCoupon() + "");
|
| | | if (sf.getCatId() != null)
|
| | | map.put("cat_id", sf.getCatId() + "");
|
| | | if (sf.getKw() != null)
|
| | | map.put("keyword", sf.getKw());
|
| | | map.put("pid", PID_FANLI);
|
| | | String result = baseRequest(map);
|
| | | System.out.println(result);
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | JSONObject root = json.optJSONObject("goods_search_response");
|
| | | JSONArray array = root.optJSONArray("goods_list");
|
| | | Type type = new TypeToken<List<PDDGoodsDetail>>() {
|
| | | }.getType();
|
| | | List<PDDGoodsDetail> goodsList = new Gson().fromJson(array.toString(), type);
|
| | | int totalCount = json.optInt("total_count");
|
| | | return new PDDGoodsResult(totalCount, goodsList);
|
| | | }
|
| | |
|
| | | public static void convert(Long goodsId) {
|
| | | /**
|
| | | * 商品转链
|
| | | * |
| | | * @param goodsId
|
| | | * @param pid
|
| | | * @param customParams
|
| | | * @return
|
| | | */
|
| | | public static String convert(Long goodsId, String pid, String customParams) {
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("type", "pdd.ddk.goods.promotion.url.generate");
|
| | | map.put("p_id", "8590899_61877633");
|
| | | map.put("p_id", pid);
|
| | | map.put("multi_group", "true");
|
| | | map.put("generate_weapp_webview", "true");
|
| | | map.put("generate_weiboapp_webview", "true");
|
| | | JSONArray array = new JSONArray();
|
| | | array.add(goodsId);
|
| | | map.put("goods_id_list", array.toString());
|
| | | map.put("custom_parameters", "437032");
|
| | | map.put("custom_parameters", customParams);
|
| | |
|
| | | String result = baseRequest(map);
|
| | | System.out.println(result);
|
| | | JSONObject root = JSONObject.fromObject(result);
|
| | | JSONObject json = root.optJSONObject("goods_promotion_url_generate_response");
|
| | | array = json.optJSONArray("goods_promotion_url_list");
|
| | | if (array != null && array.size() > 0)
|
| | | return array.optJSONObject(0).optString("short_url");
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static void createPid() {
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("type", "pdd.ddk.goods.pid.generate");
|
| | | map.put("number", "1");
|
| | | map.put("number", "2");
|
| | | JSONArray array = new JSONArray();
|
| | | array.add("返利PID");
|
| | | array.add("分享PID");
|
| | | map.put("p_id_name_list", array.toString());
|
| | |
|
| | | String result = baseRequest(map);
|
| | | System.out.println(result);
|
| | | }
|
| | |
|
| | | public static void getOrders() {
|
| | | /**
|
| | | * 获取订单
|
| | | * |
| | | * @param page
|
| | | * -页码
|
| | | * @param pageSize-每页数量
|
| | | * @param startTime-开始时间
|
| | | * @param endTime-结束时间
|
| | | * 与开始时间不得大于24小时
|
| | | * @return
|
| | | */
|
| | | public static PDDOrderResult getOrders(int page, int pageSize, long startTime, long endTime) {
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("type", "pdd.ddk.order.list.increment.get");
|
| | | map.put("start_update_time", System.currentTimeMillis() / 1000 - 60 * 60 + "");
|
| | | map.put("end_update_time", System.currentTimeMillis() / 1000 + "");
|
| | | map.put("start_update_time", startTime / 1000 + "");
|
| | | map.put("end_update_time", endTime / 1000 + "");
|
| | | map.put("page", page + "");
|
| | | 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");
|
| | | 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);
|
| | | return new PDDOrderResult(totalCount, orderList);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | *
|
| | | * @param goodsId
|
| | | */
|
| | | public static void getGoodsDetail(Long goodsId) {
|
| | | public static PDDGoodsDetail getGoodsDetail(Long goodsId) {
|
| | | JSONArray array = new JSONArray();
|
| | | array.add(goodsId);
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("type", "pdd.ddk.goods.detail");
|
| | | map.put("goods_id_list", array.toString());
|
| | | String result = baseRequest(map);
|
| | | System.out.println(result);
|
| | | JSONObject resultJson = JSONObject.fromObject(result);
|
| | | JSONObject root = resultJson.optJSONObject("goods_detail_response");
|
| | | array = root.optJSONArray("goods_details");
|
| | | Type type = new TypeToken<List<PDDGoodsDetail>>() {
|
| | | }.getType();
|
| | | List<PDDGoodsDetail> goodsList = new Gson().fromJson(array.toString(), type);
|
| | | if (goodsList != null && goodsList.size() > 0)
|
| | | return goodsList.get(0);
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|