APIUtil.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.ruixuan.launch.unitls;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ruixuan.common.utils.http.HttpUtil;
  4. import lombok.extern.slf4j.Slf4j;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. @Slf4j
  8. public class APIUtil {
  9. public static final String IP_PATH = "https://ad.e.kuaishou.com";
  10. public static JSONObject getApiResult(String apiPath, String token, Map<String, Object> param) {
  11. try {
  12. String url = IP_PATH + apiPath;
  13. Map<String, String> headers = new HashMap<String, String>();
  14. headers.put("Content-Type", "application/json");
  15. headers.put("Access-Token", token);
  16. System.out.println(JSONObject.toJSON(param));//TODO
  17. String result = HttpUtil.httpPostRequest(url, param, headers);
  18. JSONObject resultJson = JSONObject.parseObject(result);
  19. System.out.println(JSONObject.toJSON(resultJson)); //TODO
  20. return resultJson;
  21. } catch (Exception e) {
  22. e.printStackTrace();
  23. log.error("调用媒体接口异常,账户:{},接口:{}", param.get("advertiser_id"), apiPath);
  24. JSONObject result = new JSONObject();
  25. result.put("code", -1);
  26. result.put("message", "调用媒体接口异常");
  27. return result;
  28. }
  29. }
  30. public static JSONObject getApiResultByGet(String apiPath, String token, JSONObject param) {
  31. try {
  32. String url = IP_PATH + apiPath;
  33. Map<String, String> headers = new HashMap<String, String>();
  34. headers.put("Content-Type", "application/json");
  35. headers.put("Access-Token", token);
  36. System.out.println(JSONObject.toJSON(param)); //TODO
  37. String result = HttpUtil.httpGetRequest(url, headers, param);
  38. JSONObject resultJson = JSONObject.parseObject(result);
  39. System.out.println(JSONObject.toJSON(resultJson)); //TODO
  40. return resultJson;
  41. } catch (Exception e) {
  42. e.printStackTrace();
  43. log.error("调用媒体接口异常,账户:{},接口:{}", param.get("advertiser_id"), apiPath);
  44. JSONObject result = new JSONObject();
  45. result.put("code", -1);
  46. result.put("message", "调用媒体接口异常");
  47. return result;
  48. }
  49. }
  50. }