package com.fs.ad.apis;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fs.ad.iqiyi.vo.IyiqiDataVo;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
public class IqiyiApiUtil {
    private static final String URL = "http://tc.cupid.iqiyi.com/dsp_lpapi";

    public static void dataBack(IyiqiDataVo vo){
        Map<String, Object> data = new HashMap<>();
        data.put("event_type", vo.getEventType());
        data.put("impress_id", vo.getImpressId());
        String params = data.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining("&"));
        String s = URL + "?" + params;
        HttpRequest request = HttpUtil.createGet(s);
        HttpResponse execute = request.execute();
        JSONObject result = JSON.parseObject(execute.body());
        log.info("爱奇艺口地址：{}", s);
        log.info("爱奇艺返回参数：{}", result);
    }
    public static void main(String[] args) {
        dataBack(IyiqiDataVo.builder().impressId("0ddcd25cd967e4eba9b64d995ce773d8").eventType("200").build());
    }
}
