(String route,JSONObject param)
| 65 | } |
| 66 | |
| 67 | public static JSONObject postJSON(String route,JSONObject param){ |
| 68 | Map<String,Object> header = new HashMap<>(); |
| 69 | if(token != null){ |
| 70 | header.put("X-GEWE-TOKEN",token); |
| 71 | } |
| 72 | try { |
| 73 | if(baseUrl == null || "".equals(baseUrl)){ |
| 74 | throw new RuntimeException("baseUrl 未配置"); |
| 75 | } |
| 76 | String res = json(baseUrl + route, header, param.toJSONString(), okHttpClient()); |
| 77 | System.out.println(res); |
| 78 | JSONObject jsonObject = JSONObject.parse(res); |
| 79 | if(jsonObject.getInteger("ret") == 200){ |
| 80 | return jsonObject; |
| 81 | }else{ |
| 82 | throw new RuntimeException(res); |
| 83 | } |
| 84 | } catch (Exception e) { |
| 85 | System.out.println("url="+baseUrl + route); |
| 86 | throw new RuntimeException(e); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | private static String json(String url, Map<String, Object> header, String json, OkHttpClient client) throws IOException { |
| 91 | // 创建一个请求 Builder |
no test coverage detected