admin
2024-04-26 5e7b0ed4a154ad067cbcf4aa1a1c7cce32f9864c
fanli/src/main/java/com/yeshi/fanli/util/vipshop/VipShopApiUtil.java
@@ -4,14 +4,9 @@
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import com.yeshi.fanli.util.Constant;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -32,7 +27,7 @@
/**
 * TODO 未完成 唯品会接口
 *
 * 商品接口链接:https://vop.vip.com/home#/api/method/detail/com.vip.adp.api.open.service.UnionGoodsService-1.3.0/getByGoodsIds
 * @author Administrator
 */
public class VipShopApiUtil {
@@ -40,10 +35,14 @@
    private final static String appKey = "f9e7f22f";
    private final static String appSecret = "9B2291352497FAF42B2DF44BFCF62316";
    //是否采用订单侠转链
    private final static boolean CONVERT_DINGDANXIA = true;
    /**
     * 获取签名
     *
     * @param params
     * @param systemParams
     * @param taskParams
     * @return
     */
    private static String getSign(Map<String, String> systemParams, JSONObject taskParams) {
@@ -144,6 +143,14 @@
        if (searchFilter.getFieldName() != null)
            taskParams.put("fieldName", searchFilter.getFieldName() + "");
        //新增参数
        taskParams.put("chanTag", "default_pid");
        taskParams.put("openId", "default_open_id");
        taskParams.put("realCall", "true");
        JSONObject root = new JSONObject();
        root.put("request", JSONObject.fromObject(taskParams));
        String result = baseRequest("com.vip.adp.api.open.service.UnionGoodsService", "query", root);
@@ -181,6 +188,11 @@
        taskParams.put("pageSize", 20 + "");
        taskParams.put("requestId", System.currentTimeMillis() + "_" + UUID.randomUUID());
        //新增参数
        taskParams.put("chanTag", "default_pid");
        taskParams.put("openId", "default_open_id");
        taskParams.put("realCall", "true");
        JSONObject root = new JSONObject();
        root.put("request", JSONObject.fromObject(taskParams));
@@ -209,6 +221,11 @@
     * @param goodsId
     */
    public static VIPConvertResultDTO convertLink(String goodsId, String tag) {
        if (CONVERT_DINGDANXIA) {
            return DingDanXiaApiUtil.convertLink(goodsId, tag);
        }
        JSONObject taskParams = new JSONObject();
        JSONArray goodsIdArray = new JSONArray();
        goodsIdArray.add(goodsId);
@@ -216,6 +233,31 @@
        taskParams.put("chanTag", tag);
        taskParams.put("requestId", System.currentTimeMillis() + "_" + UUID.randomUUID());
        String result = baseRequest("com.vip.adp.api.open.service.UnionUrlService", "genByGoodsId",
                JSONObject.fromObject(taskParams));
        System.out.println(result);
        JSONObject resultJSON = JSONObject.fromObject(result);
        if (resultJSON.optInt("returnCode") == 0) {
            String re = resultJSON.optJSONObject("result").optJSONArray("urlInfoList").optJSONObject(0).toString();
            return new Gson().fromJson(re, VIPConvertResultDTO.class);
        }
        return null;
    }
    public static VIPConvertResultDTO convertLinkByUrl(String url, String tag) {
        if (CONVERT_DINGDANXIA) {
            return DingDanXiaApiUtil.convertLinkByUrl(url, tag);
        }
        JSONObject taskParams = new JSONObject();
        JSONArray urlArray = new JSONArray();
        urlArray.add(url);
        taskParams.put("urlList", urlArray);
        if (tag != null) {
            taskParams.put("chanTag", tag);
        }
        taskParams.put("requestId", System.currentTimeMillis() + "_" + UUID.randomUUID());
        String result = baseRequest("com.vip.adp.api.open.service.UnionUrlService", "genByVIPUrl",
                JSONObject.fromObject(taskParams));
        System.out.println(result);
        JSONObject resultJSON = JSONObject.fromObject(result);
@@ -236,6 +278,13 @@
        JSONObject params = new JSONObject();
        params.put("goodsIdList", goodsIdList);
        params.put("requestId", UUID.randomUUID());
        //新增参数
        params.put("chanTag", "default_pid");
        JSONObject request = new JSONObject();
        request.put("openId", "default_open_id");
        request.put("realCall", "true");
        params.put("request", request);
        String result = baseRequest("com.vip.adp.api.open.service.UnionGoodsService", "getByGoodsIds",
                JSONObject.fromObject(params));
        System.out.println(result);
@@ -292,9 +341,17 @@
    }
    public static void main(String[] args) {
//        VIPSearchFilter sf=new VIPSearchFilter();
//        sf.setKeyword("花卉");
//        sf.setPage(1);
//        sf.setPageSize(Constant.PAGE_SIZE);
//        search(sf);
        convertLink("6919237495414585303","437032");
        getGoodsDetail("6920553939593155215");
//        convertLinkByUrl("https://t.vip.com/T7RyKKCJLj9", "437032");
//        convertLink("560392904","437032");
//        getOrderList(VipShopOrderQueryModel.createOrderSn(Arrays.asList(new String[]{"23090254293903"}),1));
    }
}