package com.tzld.piaoquan.api.component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class VlogApiService {

    @Autowired
    private HttpPoolClient httpPoolClient;

    private final static String SHARE_IMG_URL = "https://vlogapi.piaoquantv.com/longvideoapi/video/share/web/qrImg";
    private final static String SHARE_LINK_URL = "https://vlogapi.piaoquantv.com/longvideoapi/video/share/web/link";

    public String getSharePic(String path, String appType) {
        JSONObject requestParam = new JSONObject();
        requestParam.put("page", path);
        requestParam.put("appType", appType);
        try {
            String resultStr = httpPoolClient.post(SHARE_IMG_URL, requestParam.toJSONString());
            JSONObject result = JSON.parseObject(resultStr);
            return result.getString("data");
        } catch (Exception e) {
            log.error("获取分享图片失败", e);
        }
        return null;
    }

    public String getShareUrlLink(String path, String appType) {
        JSONObject requestParam = new JSONObject();
        requestParam.put("page", path);
        requestParam.put("appType", appType);
        try {
            String resultStr = httpPoolClient.post(SHARE_LINK_URL, requestParam.toJSONString());
            JSONObject result = JSON.parseObject(resultStr);
            return result.getString("data");
        } catch (Exception e) {
            log.error("获取分享链接失败", e);
        }
        return null;
    }
}
