From 3f41182984d69d7fae703776edd1591f48dff93f Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 22 十一月 2023 17:13:05 +0800 Subject: [PATCH] 2023年11月22日17:12:40 --- app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java | 93 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 90 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java index 96a2d53..77ed570 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java @@ -28,13 +28,25 @@ import com.hdl.photovoltaic.internet.api.TopicApi; import com.hdl.photovoltaic.listener.CloudCallBeak; import com.hdl.photovoltaic.listener.LinkCallBack; +import com.hdl.photovoltaic.utils.AesUtils; import com.hdl.photovoltaic.utils.AppManagerUtils; +import com.hdl.photovoltaic.utils.Md5Utils; import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.ByteUtils; import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.logging.FileHandler; + +import okhttp3.ResponseBody; /** @@ -449,9 +461,24 @@ * * @param downloadUrl 浜戠鍥轰欢鍦板潃 */ - public void getDeviceDriverDownloadFile(String downloadUrl, CloudCallBeak<DownloadUrlBean> callBack) { - String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl; - JsonObject json = new JsonObject(); + public void getDeviceDriverDownloadFile(String downloadUrl, CloudCallBeak<ResponseBody> callBack) { + HttpClient.getInstance().downLoadFile(downloadUrl, new CloudCallBeak<ResponseBody>() { + @Override + public void onSuccess(ResponseBody s) { + + if (callBack != null) { + callBack.onSuccess(s); + } + } + + @Override + public void onFailure(HDLException e) { + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } @@ -525,4 +552,64 @@ } } + /** + * 澶勭悊涓嬭浇鏂囦欢鏁版嵁 + * + * @param zipData 鏂囦欢鏁版嵁娴佸璞� + * @param md5 妫�楠屾枃浠禡D5鍊� + * @return 杩斿洖瑙e瘑鐨刡yte[] + */ + public byte[] disposeDownLoadFile(ResponseBody zipData, String md5) { + if (zipData == null) { + return null; + } + if (TextUtils.isEmpty(md5)) { + return null; + } + InputStream is = null; + List<Byte> byteList = new ArrayList<>(); + byte[] decrypt = null; + try { + is = zipData.byteStream(); + int total = (int) zipData.contentLength(); + byte[] buf = new byte[1024*4]; + long sum = 0; + int len = 0; + while ((len = is.read(buf)) != -1) { + sum += len; + //todo 涓嬭浇涓紝鍙互鑷鍔犲叆杩涘害鏉�(鍙互骞挎挱鍑哄幓) + int progress = (int) (sum * 1.0f / total * 100); + for (int i = 0; i < len; i++) { + byteList.add(buf[i]); + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (is != null) { + is.close(); + } + Byte[] sourceByte = byteList.toArray(new Byte[0]); + byte[] bytes = new byte[sourceByte.length]; + for (int i = 0; i < sourceByte.length; i++) { + bytes[i] = sourceByte[i]; + } + //涓嬭浇鏂囦欢闇�瑕佽В瀵嗕箣鍚庡啀杩涜md5鍘诲仛姣斿 + decrypt = AesUtils.decrypt(bytes); + if (decrypt != null) { + String fileMD5 = Md5Utils.encodeMD5(decrypt); + if (TextUtils.isEmpty(fileMD5) || !Objects.equals(fileMD5, md5)) { + //鏍¢獙澶辫触,缃┖ + decrypt = null; + } + } + } catch (IOException ignored) { + + } + } + return decrypt; + } + + } -- Gitblit v1.8.0