
package com.transfer;

import com.baidu.ai.aip.utils.HttpUtil;
import com.baidu.ai.aip.utils.GsonUtils;

import java.util.*;

/**
 * 图像识别组合API
 */
public class ImgCombination {

    /**
     * 重要提示代码中所需工具类
     * FileUtil,Base64Util,HttpUtil,GsonUtils请从
     * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
     * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
     * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
     * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
     * 下载
     */
    public String imgCombinatio(){
        return "QEEEEEE";
    }
    public  String imgCombination() {
        // 请求url
        String url = "https://aip.baidubce.com/api/v1/solution/direct/imagerecognition/combination";
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("imgUrl", "https://pic1.zhimg.com/80/v2-31242331d504e03c96015dcc09101c90_1440w.webp");
            List<Object> scenes = new ArrayList<>();

            scenes.add("ingredient");

            map.put("scenes", scenes);

            String param = GsonUtils.toJson(map);

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = "24.bb5baa6f79502180928d105dd8ea46c8.2592000.1668576873.282335-27944955";

            String result =HttpUtil.post(url, accessToken, "application/json", param);
            //System.out.println("**************************");
            //System.out.println(result);
            //System.out.println("**************************");
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Error1";
    }
//    public static void main(String[] args) {
//        ImgCombination.imgCombination();
//    }

}