package jj.tech.paolu.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.fluent.Request;
import org.apache.http.entity.ContentType;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class YMHttp {
	
	public static ObjectMapper objectMapper = new ObjectMapper();
	public static String ym_url = "http://api.jfbym.com/api/YmServer/customApi";
	
//	public static Map<String,Object> customApi(String image_base64){
//		try {
//			Map<String, Object> param = new HashMap<>();
//	        param.put("token", "Cx08lMubmQauvOOhD0rp_qdnebs--Hi7bPdy9No6Uvw");
//	        param.put("type", "10110");
//	        param.put("image", image_base64);
//	        
//			String stean = Request.Post(ym_url)
//			.connectTimeout(2500)
//			.socketTimeout(2500)
//			.bodyString(objectMapper.writeValueAsString(param), ContentType.APPLICATION_JSON)
//			.execute()
//			.returnContent()
//			.asString();
//			
//			@SuppressWarnings("unchecked")
//			HashMap<String, Object> jsonObject = objectMapper.readValue(stean, HashMap.class);
//			
//			return jsonObject;
//		
//		} catch (Exception e) {
//			e.printStackTrace();
//			return null;
//		}
//	}
	
	public static JsonNode customApi(String image_base64){
		try {
			Map<String, Object> param = new HashMap<>();
	        param.put("token", "Cx08lMubmQauvOOhD0rp_qdnebs--Hi7bPdy9No6Uvw");
	        param.put("type", "10110");
	        param.put("image", image_base64);
	        
			String stean = Request.Post(ym_url)
			.connectTimeout(2500)
			.socketTimeout(2500)
			.bodyString(objectMapper.writeValueAsString(param), ContentType.APPLICATION_JSON)
			.execute()
			.returnContent()
			.asString();
			
			return objectMapper.readTree(stean);
		
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static void main(String[] args) throws Exception{
//		
//		Map<String, Object> param = new HashMap<>();
//        param.put("token", "Cx08lMubmQauvOOhD0rp_qdnebs--Hi7bPdy9No6Uvw");
//        param.put("type", "10110");
//        param.put("image", "image");
//        
//		InputStream stean =
//				Request.Post(ym_url)
//				.connectTimeout(2500)
//				.socketTimeout(2500)
//				.bodyString(objectMapper.writeValueAsString(param), ContentType.APPLICATION_JSON)
//				.execute()
//				.returnContent()
//				.asStream();
//			JsonNode root = objectMapper.readTree(stean);
//			//JsonNode data = root.get("data");
//			//ArrayNode datasetArray = (ArrayNode)root.get("data");
//			for (final JsonNode item : root) {
//		        System.out.println(item);
//		        
//		        
//		    }
		
//		Map<String,Object> r =
//		YMHttp.customApi("ss");
//		System.out.println(r);
		
		
	}

}
