| | |
| | | * @return - |
| | | */ |
| | | private Disposable requestGet(String requestUrl, CloudCallBeak<String> callBack) { |
| | | HdlLogLogic.print("http---发送---" + requestUrl + "\r\n", isAddToMemory); |
| | | // HdlLogLogic.print("http---发送---" + requestUrl + "\r\n", isAddToMemory); |
| | | //开发环境需要加(用来区分onpro和光伏app代码):HxHttp.builder().headers("x-lbs-version", "hdl-yt") |
| | | return HxHttp.builder().url(requestUrl).build().get().subscribeWith(new HDLResponse<String>() { |
| | | @Override |
| | |
| | | if (callBack != null) { |
| | | callBack.onSuccess(str); |
| | | // System.out.println("http---回复---" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString()); |
| | | HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + str, isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + str, isAddToMemory); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private Disposable requestPost(String api, String body, CloudCallBeak<String> callBack) { |
| | | String requestUrl = HDLCloudUserApi.getRequestUrl(api); |
| | | HdlLogLogic.print("http---发送---" + requestUrl + "\r\n" + body, isAddToMemory); |
| | | // HdlLogLogic.print("http---发送---" + requestUrl + "\r\n" + body, isAddToMemory); |
| | | //开发环境需要加(用来区分onpro和光伏app代码):HxHttp.builder().headers("x-lbs-version", "hdl-yt") |
| | | return HxHttp.builder().url(requestUrl).raw(body).build().post().subscribeWith(new HDLResponse<String>() { |
| | | @Override |
| | |
| | | if (callBack != null) { |
| | | callBack.onSuccess(str); |
| | | // System.out.println("http---回复---" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString()); |
| | | HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + str, isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + str, isAddToMemory); |
| | | } |
| | | } |
| | | |
| | |
| | | HDLExceptionSubmitUtils.submit(requestUrl, body, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory); |
| | | } |
| | | } |
| | | }); |
| | |
| | | |
| | | |
| | | String requestUrl = HDLCloudUserApi.getRequestUrl(api); |
| | | HdlLogLogic.print("http---发送---" + requestUrl + "\r\n" + body, isAddToMemory); |
| | | // HdlLogLogic.print("http---发送---" + requestUrl + "\r\n" + body, isAddToMemory); |
| | | return HxHttp.builder().url(requestUrl).file(body).build().post().subscribeWith(new HDLResponse<String>() { |
| | | @Override |
| | | public void onResponse(String str) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(str); |
| | | // System.out.println("http---回复---" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString()); |
| | | HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + str, isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + str, isAddToMemory); |
| | | } |
| | | } |
| | | |
| | |
| | | HDLExceptionSubmitUtils.submit(requestUrl, body, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory); |
| | | } |
| | | } |
| | | }); |
| | |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | HdlLogLogic.print("http---发送---" + fullUrl + "\r\n" + json, isAddToMemory); |
| | | // HdlLogLogic.print("http---发送---" + fullUrl + "\r\n" + json, isAddToMemory); |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), getJson(json)); |
| | | final Request request = new Request.Builder().url(fullUrl)//请求的url |
| | |
| | | if (response.isSuccessful()) { |
| | | String s = Objects.requireNonNull(response.body()).string(); |
| | | HttpResponsePack httpResponsePack = new Gson().fromJson(s, HttpResponsePack.class); |
| | | HdlLogLogic.print("http---回复---" + response.request().url() + "\r\n" + s, isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + response.request().url() + "\r\n" + s, isAddToMemory); |
| | | baseSuccessCallBeak.onSuccess(httpResponsePack); |
| | | |
| | | } else { |
| | |
| | | call.enqueue(new Callback() {//异步 |
| | | @Override |
| | | public void onFailure(@NonNull Call call, @NonNull IOException e) { |
| | | HdlLogLogic.print("http---回复---" + "\r\n" + e.getMessage(), isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + "\r\n" + e.getMessage(), isAddToMemory); |
| | | } |
| | | |
| | | @Override |
| | |
| | | String s = Objects.requireNonNull(response.body()).string(); |
| | | HttpResponsePack httpResponsePack = new Gson().fromJson(s, HttpResponsePack.class); |
| | | baseSuccessCallBeak.onSuccess(httpResponsePack); |
| | | HdlLogLogic.print("http---回复---" + "\r\n" + s, isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + "\r\n" + s, isAddToMemory); |
| | | } else { |
| | | baseSuccessCallBeak.onFailure(new HDLException(response.code(), response.message())); |
| | | } |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | baseSuccessCallBeak.onFailure(new HDLException(-100, e.getMessage())); |
| | | HdlLogLogic.print("http---回复---" + "\r\n" + e.getMessage(), isAddToMemory); |
| | | // HdlLogLogic.print("http---回复---" + "\r\n" + e.getMessage(), isAddToMemory); |
| | | } |
| | | |
| | | } |