admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/util/goods/douyin/CSJCPSApiUtil.java
@@ -2,13 +2,17 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.dy.DYOrder;
import com.yeshi.fanli.util.goods.douyin.vo.*;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.TimeUtil;
import java.io.IOException;
import java.lang.reflect.Type;
@@ -22,10 +26,11 @@
 * @date 2022/8/8 15:45
 */
public class CSJCPSApiUtil {
    private static Logger debugLog = LoggerFactory.getLogger("debugLog");
    private static String post(String url, String entity) {
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setProxy("192.168.3.122", 8888);
        //client.getHostConfiguration().setProxy("192.168.3.122", 8888);
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "application/json;charset=UTF-8");
        method.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
@@ -44,6 +49,9 @@
    private static String baseRequest(String path, JSONObject data, CSJAppInfo appInfo) {
        String url = "http://ecom.pangolin-sdk-toutiao.com" + path;
        debugLog.info("抖音请求开始:链接-{}", url);
        com.alibaba.fastjson.JSONObject params = new com.alibaba.fastjson.JSONObject();
        params.put("app_id", appInfo.getAppId());
        params.put("timestamp", System.currentTimeMillis() / 1000);
@@ -190,7 +198,7 @@
        }
        if (filter.getThird_cids() != null) {
            data.put("third_cids", JSONObject.fromObject(filter.getThird_cids()));
            data.put("third_cids", new Gson().toJson(filter.getThird_cids()));
        }
        if (filter.getPrice_min() != null) {
@@ -254,7 +262,7 @@
     * @param: extra_info 媒体传递扩展参数的字段, 字符只允许字⺟⼤⼩写、数字、 下划线,⻓度不超过20
     * @param: product_ext 商品搜索接⼝返回的 product.ext 字段, 尽量填写
     **/
    public static DYConvertResult goodsConvert(String product_url, String extra_info, String product_ext) {
    public static DYConvertResult goodsConvert(String product_url, String extra_info, String product_ext) throws Exception {
        JSONObject data = new JSONObject();
        data.put("product_url", product_url);
        data.put("external_info", extra_info);
@@ -262,17 +270,18 @@
        //转链类型:1、抖⾳ deep link;2、抖
        //⾳⼆维码;3、抖⾳⼝令。
        //默认返回抖⾳deeplink
        data.put("share_type", "[1,2,3]");
        data.put("share_type", "[1,3,4]");
        String result = baseRequest("/product/link", data);
        System.out.println(result);
        JSONObject resultJson = JSONObject.fromObject(result);
        if (resultJson.optInt("code") != 0) {
            return null;
            throw new Exception(resultJson.optString("desc"));
        }
        JSONObject dataJson = resultJson.optJSONObject("data");
        DYConvertResult bean = new DYConvertResult();
        bean.setDeeplink(dataJson.optString("dy_deeplink"));
        bean.setPassword(dataJson.optString("dy_password"));
        bean.setZlink(dataJson.optString("dy_zlink"));
        if (dataJson.optJSONObject("dy_qr_code") != null) {
            bean.setQrCode(dataJson.optJSONObject("dy_qr_code").optString("url"));
@@ -303,8 +312,18 @@
    }
    public static DYGoodsDetail goodsDetail(Long goodsId) {
        List<DYGoodsDetail> list = goodsDetails(Arrays.asList(new Long[]{goodsId}));
        if (list == null || list.size() == 0) {
            return null;
        } else {
            return list.get(0);
        }
    }
    public static DYOrderResult orderList(DYOrderFilter filter) {
        JSONObject data = JSONObject.fromObject(new Gson().toJson( filter));
        JSONObject data = JSONObject.fromObject(new Gson().toJson(filter));
        String result = baseRequest("/order/search", data);
@@ -314,45 +333,45 @@
            return null;
        }
        JSONObject dataJson = resultJson.optJSONObject("data");
        return new Gson().fromJson(dataJson.toString(),DYOrderResult.class);
        return new Gson().fromJson(dataJson.toString(), DYOrderResult.class);
    }
    public static DYOrder getOrderDetail(String orderId,int orderType){
        DYOrderFilter filter=new DYOrderFilter();
    public static DYOrder getOrderDetail(String orderId, int orderType) {
        DYOrderFilter filter = new DYOrderFilter();
        filter.setOrder_type(orderType);
        filter.setOrder_ids(Arrays.asList(new String[]{orderId}));
        DYOrderResult result= orderList(filter);
        if(result==null){
        DYOrderResult result = orderList(filter);
        if (result == null) {
            return null;
        }
        if(result.getOrders()==null||result.getOrders().size()<=0){
        if (result.getOrders() == null || result.getOrders().size() <= 0) {
            return null;
        }
        return result.getOrders().get(0);
    }
    /**
     * @author hxh
     * @return com.yeshi.fanli.util.goods.douyin.vo.DYAggregateH5Result
     * @author hxh
     * @description 聚合页H5
     * @date 15:48 2022/9/30
     * @param: filter
     * @return com.yeshi.fanli.util.goods.douyin.vo.DYAggregateH5Result
     **/
    public static DYAggregateH5Result aggregateH5(DYAggregateH5Filter filter) {
        JSONObject data = new JSONObject();
        if (filter.getDevice() != null) {
            data.put("device", new Gson().toJson(filter.getDevice()));
        }
        if(filter.getExternal_info()!=null){
        if (filter.getExternal_info() != null) {
            data.put("external_info", filter.getExternal_info());
        }
        if(filter.getMaterial_id()!=null){
        if (filter.getMaterial_id() != null) {
            data.put("material_id", filter.getMaterial_id());
        }
        if(filter.getProduct_url()!=null){
        if (filter.getProduct_url() != null) {
            data.put("product_url", filter.getProduct_url());
        }
@@ -364,13 +383,37 @@
            return null;
        }
        JSONObject dataJson = resultJson.optJSONObject("data");
        return new Gson().fromJson(dataJson.toString(),DYAggregateH5Result.class);
        return new Gson().fromJson(dataJson.toString(), DYAggregateH5Result.class);
    }
    public static void main(String[] args) {
       goodsDetails(Arrays.asList(new Long[]{3549871967593209780L}));
       getOrderDetail("4984002890650177191",1);
    public static JSONObject parseCommand(String command) {
        JSONObject data = new JSONObject();
        data.put("command", command);
        String result = baseRequest("/command_parse", data);
        System.out.println(result);
        JSONObject resultJson = JSONObject.fromObject(result);
        if (resultJson.optInt("code") != 0) {
            return null;
        }
        JSONObject dataJson = resultJson.optJSONObject("data");
        return dataJson;
    }
    public static String parseProductId(String command) {
        JSONObject result = parseCommand(command);
        if (result != null) {
            if (result.optInt("command_type") == 1) {
                return result.optJSONObject("product_info").optString("product_id");
            }
        }
        return null;
    }
    public static void main(String[] args) throws Exception {
        DYConvertResult result =   goodsConvert("https://v.douyin.com/iNTutNyn/","123","132");
        System.out.printf(result.toString());
    }