From 3e904bfa8a1bb53dcf461e5c717f9b808e179245 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 08 一月 2025 16:27:48 +0800
Subject: [PATCH] 2025年01月08日16:27:46
---
app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java | 80 +++++++++++++++++++++++++++++++++------
1 files changed, 67 insertions(+), 13 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
index 4c0d8ec..9ffd9f9 100644
--- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
+++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
@@ -20,7 +20,10 @@
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak;
import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.other.HdlESLocalJsonLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
+import com.hdl.photovoltaic.other.HdlThreadLogic;
+import com.hdl.photovoltaic.utils.LocalManageUtil;
import com.hdl.photovoltaic.utils.Md5Utils;
import java.io.File;
@@ -62,6 +65,57 @@
}
/**
+ * 鑾峰彇json璧勬簮鐢ㄧ殑
+ *
+ * @param url 鍦板潃
+ * @param callBack 鍥炶皟
+ */
+ public void requestJsonHttpGet(String url, CloudCallBeak<String> callBack) {
+ if (TextUtils.isEmpty(url)) {
+ if (callBack != null) {
+ callBack.onSuccess("");
+ }
+ }
+
+ HdlThreadLogic.runSubThread(new Runnable() {
+ @Override
+ public void run() {
+ OkHttpClient client = new OkHttpClient();
+ Request request = new Request.Builder()
+ .url(url)
+ .addHeader("Accept-Language", UserConfigManage.getInstance().getCurrentAppLanguage())
+ .build();
+
+ try (Response response = client.newCall(request).execute()) {
+ if (response.isSuccessful()) {
+ if (response.body() == null) {
+ if (callBack != null) {
+ callBack.onSuccess("");
+ }
+ } else {
+ String str = response.body().string();
+ if (callBack != null) {
+ callBack.onSuccess(str);
+ }
+ }
+
+ } else {
+ if (callBack != null) {
+ callBack.onSuccess("");
+ }
+ }
+ } catch (Exception e) {
+ if (callBack != null) {
+ callBack.onFailure(new HDLException(-20002, e.getMessage()));
+ }
+ }
+ }
+ });
+
+ }
+
+
+ /**
* 璇锋眰鏈嶅姟鍣�(get)
* 搴曞眰鏂规硶,寮曠敤搴撶殑鏂规硶
*
@@ -70,7 +124,7 @@
* @return -
*/
private Disposable requestGet(String requestUrl, CloudCallBeak<String> callBack) {
- HdlLogLogic.print("http---鍙戦��---" + requestUrl + "\r\n", isAddToMemory);
+// HdlLogLogic.print("http---鍙戦��---" + requestUrl + "\r\n", isAddToMemory);
//寮�鍙戠幆澧冮渶瑕佸姞(鐢ㄦ潵鍖哄垎onpro鍜屽厜浼廰pp浠g爜):HxHttp.builder().headers("x-lbs-version", "hdl-yt")
return HxHttp.builder().url(requestUrl).build().get().subscribeWith(new HDLResponse<String>() {
@Override
@@ -78,7 +132,7 @@
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);
}
}
@@ -105,7 +159,7 @@
*/
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鍜屽厜浼廰pp浠g爜):HxHttp.builder().headers("x-lbs-version", "hdl-yt")
return HxHttp.builder().url(requestUrl).raw(body).build().post().subscribeWith(new HDLResponse<String>() {
@Override
@@ -113,7 +167,7 @@
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);
}
}
@@ -122,7 +176,7 @@
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);
}
}
});
@@ -142,14 +196,14 @@
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);
}
}
@@ -158,7 +212,7 @@
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);
}
}
});
@@ -274,7 +328,7 @@
@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)//璇锋眰鐨剈rl
@@ -284,7 +338,7 @@
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 {
@@ -297,7 +351,7 @@
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
@@ -307,7 +361,7 @@
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()));
}
@@ -316,7 +370,7 @@
}
} 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);
}
}
--
Gitblit v1.8.0