diff --git a/app/src/main/java/com/example/retention/device/ArmCloudApiClient.java b/app/src/main/java/com/example/retention/device/ArmCloudApiClient.java index 7918a06..cf65943 100644 --- a/app/src/main/java/com/example/retention/device/ArmCloudApiClient.java +++ b/app/src/main/java/com/example/retention/device/ArmCloudApiClient.java @@ -149,100 +149,100 @@ public class ArmCloudApiClient { * null, // settingProps oaidProps ); */ public String updateInstanceProperties( - String[] padCodes, - List modemPersistProps, - List modemProps, - List systemPersistProps, - List systemProps, - List settingProps, - List oaidProps + String[] padCodes, + List modemPersistProps, + List modemProps, + List systemPersistProps, + List systemProps, + List settingProps, + List oaidProps ) throws IOException { - if (padCodes == null || padCodes.length == 0) { - throw new IllegalArgumentException("padCodes 不能为空"); + if (padCodes == null || padCodes.length == 0) { + throw new IllegalArgumentException("padCodes 不能为空"); + } + + // 检查 padCodes 是否有重复项 + Set padCodeSet = new HashSet<>(); + for (String code : padCodes) { + if (!padCodeSet.add(code)) { + throw new IllegalArgumentException("padCodes 包含重复项: " + code); + } + } + + JSONObject json = new JSONObject(); + try { + json.put("padCodes", new JSONArray(Arrays.asList(padCodes))); + putPropertyItems(json, "modemPersistPropertiesList", modemPersistProps); + putPropertyItems(json, "modemPropertiesList", modemProps); + putPropertyItems(json, "systemPersistPropertiesList", systemPersistProps); + putPropertyItems(json, "systemPropertiesList", systemProps); + putPropertyItems(json, "settingPropertiesList", settingProps); + putPropertyItems(json, "oaidPropertiesList", oaidProps); + + } catch (JSONException e) { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: JSON 构建失败", e); + throw new IOException("JSON 构建失败", e); + } + + String jsonBody = json.toString(); + String timestamp = String.valueOf(System.currentTimeMillis()); + String API_PATH = "/openapi/open/pad/updatePadProperties"; + + if (secretKey == null || secretKey.isEmpty()) { + throw new IllegalArgumentException("secretKey 不能为空"); + } + + String signature; + try { + signature = calculateSignature(timestamp, API_PATH, jsonBody, secretKey); + } catch (Exception e) { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 签名计算失败", e); + throw new IOException("签名计算失败", e); + } + + RequestBody body = RequestBody.create( + MediaType.get("application/json; charset=utf-8"), + jsonBody + ); + + Request request = new Request.Builder() + .url(baseUrl + API_PATH) + .addHeader("authver", "2.0") + .addHeader("x-ak", accessKey) + .addHeader("x-timestamp", timestamp) + .addHeader("x-sign", signature) + .post(body) + .build(); + + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("请求失败: " + response); } - // 检查 padCodes 是否有重复项 - Set padCodeSet = new HashSet<>(); - for (String code : padCodes) { - if (!padCodeSet.add(code)) { - throw new IllegalArgumentException("padCodes 包含重复项: " + code); - } + ResponseBody responseBody = response.body(); + if (responseBody == null) { + throw new IOException("响应体为空"); } - JSONObject json = new JSONObject(); - try { - json.put("padCodes", new JSONArray(Arrays.asList(padCodes))); - putPropertyItems(json, "modemPersistPropertiesList", modemPersistProps); - putPropertyItems(json, "modemPropertiesList", modemProps); - putPropertyItems(json, "systemPersistPropertiesList", systemPersistProps); - putPropertyItems(json, "systemPropertiesList", systemProps); - putPropertyItems(json, "settingPropertiesList", settingProps); - putPropertyItems(json, "oaidPropertiesList", oaidProps); + String responseBodyString = responseBody.string(); + JSONObject responseJson = new JSONObject(responseBodyString); - } catch (JSONException e) { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: JSON 构建失败", e); - throw new IOException("JSON 构建失败", e); + // 校验返回码 + if (responseJson.has("code")) { + int code = responseJson.getInt("code"); + if (code != 200) { + String errorMsg = responseJson.optString("msg", "未知错误"); + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 接口返回错误码 " + code + ", 错误信息: " + errorMsg, null); + } + } else { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 响应中缺少 'code' 字段", null); } - String jsonBody = json.toString(); - String timestamp = String.valueOf(System.currentTimeMillis()); - String API_PATH = "/openapi/open/pad/updatePadProperties"; - - if (secretKey == null || secretKey.isEmpty()) { - throw new IllegalArgumentException("secretKey 不能为空"); - } - - String signature; - try { - signature = calculateSignature(timestamp, API_PATH, jsonBody, secretKey); - } catch (Exception e) { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 签名计算失败", e); - throw new IOException("签名计算失败", e); - } - - RequestBody body = RequestBody.create( - MediaType.get("application/json; charset=utf-8"), - jsonBody - ); - - Request request = new Request.Builder() - .url(baseUrl + API_PATH) - .addHeader("authver", "2.0") - .addHeader("x-ak", accessKey) - .addHeader("x-timestamp", timestamp) - .addHeader("x-sign", signature) - .post(body) - .build(); - - try (Response response = client.newCall(request).execute()) { - if (!response.isSuccessful()) { - throw new IOException("请求失败: " + response); - } - - ResponseBody responseBody = response.body(); - if (responseBody == null) { - throw new IOException("响应体为空"); - } - - String responseBodyString = responseBody.string(); - JSONObject responseJson = new JSONObject(responseBodyString); - - // 校验返回码 - if (responseJson.has("code")) { - int code = responseJson.getInt("code"); - if (code != 200) { - String errorMsg = responseJson.optString("msg", "未知错误"); - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 接口返回错误码 " + code + ", 错误信息: " + errorMsg, null); - } - } else { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 响应中缺少 'code' 字段",null); - } - - return responseBodyString; - } catch (JSONException e) { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 响应解析失败", e); - throw new IOException("响应解析失败", e); - } + return responseBodyString; + } catch (JSONException e) { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "updateInstanceProperties: 响应解析失败", e); + throw new IOException("响应解析失败", e); + } } @@ -288,118 +288,124 @@ public class ArmCloudApiClient { * @return 匹配的 padCode 数组 * @throws IOException 请求失败或网络错误 */ - public String[] getInstanceListInfo( - int page, - int rows, - String armServerCode, - String deviceCode, - String[] padCodes, - Integer[] groupIds, - String idc) throws IOException { + public String[] getInstanceListInfo( + int page, + int rows, + String armServerCode, + String deviceCode, + String[] padCodes, + Integer[] groupIds, + String idc) throws IOException { - JSONObject json = new JSONObject(); - try { - json.put("page", page); - json.put("rows", rows); + JSONObject json = new JSONObject(); + try { + json.put("page", page); + json.put("rows", rows); - if (armServerCode != null) json.put("armServerCode", armServerCode); - if (deviceCode != null) json.put("deviceCode", deviceCode); - if (padCodes != null && padCodes.length > 0) { - json.put("padCodes", new JSONArray(Arrays.asList(padCodes))); - } - if (groupIds != null && groupIds.length > 0) { - json.put("groupIds", new JSONArray(Arrays.asList(groupIds))); - } - if (idc != null) json.put("idc", idc); - - } catch (JSONException e) { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: JSON 构建失败", e); - throw new IOException("JSON 构建失败", e); - } - - String jsonBody = json.toString(); - String timestamp = String.valueOf(System.currentTimeMillis()); - String API_PATH = "/openapi/open/pad/infos"; - - if (secretKey == null || secretKey.isEmpty()) { - throw new IllegalArgumentException("secretKey 不能为空"); - } - - String signature; - try { - signature = calculateSignature(timestamp, API_PATH, jsonBody, secretKey); - } catch (Exception e) { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 签名计算失败", e); - throw new IOException("签名计算失败", e); - } - - RequestBody body = RequestBody.create( - MediaType.get("application/json; charset=utf-8"), - jsonBody - ); - - Request request = new Request.Builder() - .url(baseUrl + API_PATH) - .addHeader("authver", "2.0") - .addHeader("x-ak", accessKey) - .addHeader("x-timestamp", timestamp) - .addHeader("x-sign", signature) - .post(body) - .build(); - - try (Response response = client.newCall(request).execute()) { - if (!response.isSuccessful()) { - throw new IOException("请求失败: " + response); - } - - ResponseBody responseBody = response.body(); - if (responseBody == null) { - throw new IOException("响应体为空"); - } - - String responseBodyString = responseBody.string(); - JSONObject responseJson = new JSONObject(responseBodyString); - - // 校验返回码 - if (responseJson.has("code")) { - int code = responseJson.getInt("code"); - if (code != 200) { - String errorMsg = responseJson.optString("msg", "未知错误"); - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 接口返回错误码 " + code + ", 错误信息: " + errorMsg, null); - throw new IOException("接口返回错误码: " + code + ", 错误信息: " + errorMsg); - } - } else { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 响应中缺少 'code' 字段", null); - throw new IOException("响应中缺少 'code' 字段"); - } - - // 提取 padCode 列表 - JSONArray pageDataArray = responseJson.optJSONObject("data") - .optJSONArray("pageData"); - - if (pageDataArray == null || pageDataArray.length() == 0) { - LogFileUtil.logAndWrite(Log.WARN, "ArmCloudApiClient", "getInstanceListInfo: 查询结果为空", null); - return new String[0]; - } - - int length = pageDataArray.length(); - String[] padCodesResult = new String[length]; - - for (int i = 0; i < length; i++) { - JSONObject item = pageDataArray.getJSONObject(i); - if (!item.has("padCode")) { - LogFileUtil.logAndWrite(Log.WARN, "ArmCloudApiClient", "getInstanceListInfo: 返回对象缺少 'padCode' 字段", null); - throw new IOException("返回对象缺少 'padCode' 字段"); - } - padCodesResult[i] = item.getString("padCode"); - } - - return padCodesResult; - - } catch (JSONException e) { - LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 响应解析失败", e); - throw new IOException("响应解析失败", e); - } + if (armServerCode != null) { + json.put("armServerCode", armServerCode); + } + if (deviceCode != null) { + json.put("deviceCode", deviceCode); + } + if (padCodes != null && padCodes.length > 0) { + json.put("padCodes", new JSONArray(Arrays.asList(padCodes))); + } + if (groupIds != null && groupIds.length > 0) { + json.put("groupIds", new JSONArray(Arrays.asList(groupIds))); + } + if (idc != null) { + json.put("idc", idc); } + } catch (JSONException e) { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: JSON 构建失败", e); + throw new IOException("JSON 构建失败", e); + } + + String jsonBody = json.toString(); + String timestamp = String.valueOf(System.currentTimeMillis()); + String API_PATH = "/openapi/open/pad/infos"; + + if (secretKey == null || secretKey.isEmpty()) { + throw new IllegalArgumentException("secretKey 不能为空"); + } + + String signature; + try { + signature = calculateSignature(timestamp, API_PATH, jsonBody, secretKey); + } catch (Exception e) { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 签名计算失败", e); + throw new IOException("签名计算失败", e); + } + + RequestBody body = RequestBody.create( + MediaType.get("application/json; charset=utf-8"), + jsonBody + ); + + Request request = new Request.Builder() + .url(baseUrl + API_PATH) + .addHeader("authver", "2.0") + .addHeader("x-ak", accessKey) + .addHeader("x-timestamp", timestamp) + .addHeader("x-sign", signature) + .post(body) + .build(); + + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("请求失败: " + response); + } + + ResponseBody responseBody = response.body(); + if (responseBody == null) { + throw new IOException("响应体为空"); + } + + String responseBodyString = responseBody.string(); + JSONObject responseJson = new JSONObject(responseBodyString); + + // 校验返回码 + if (responseJson.has("code")) { + int code = responseJson.getInt("code"); + if (code != 200) { + String errorMsg = responseJson.optString("msg", "未知错误"); + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 接口返回错误码 " + code + ", 错误信息: " + errorMsg, null); + throw new IOException("接口返回错误码: " + code + ", 错误信息: " + errorMsg); + } + } else { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 响应中缺少 'code' 字段", null); + throw new IOException("响应中缺少 'code' 字段"); + } + + // 提取 padCode 列表 + JSONArray pageDataArray = responseJson.optJSONObject("data") + .optJSONArray("pageData"); + + if (pageDataArray == null || pageDataArray.length() == 0) { + LogFileUtil.logAndWrite(Log.WARN, "ArmCloudApiClient", "getInstanceListInfo: 查询结果为空", null); + return new String[0]; + } + + int length = pageDataArray.length(); + String[] padCodesResult = new String[length]; + + for (int i = 0; i < length; i++) { + JSONObject item = pageDataArray.getJSONObject(i); + if (!item.has("padCode")) { + LogFileUtil.logAndWrite(Log.WARN, "ArmCloudApiClient", "getInstanceListInfo: 返回对象缺少 'padCode' 字段", null); + throw new IOException("返回对象缺少 'padCode' 字段"); + } + padCodesResult[i] = item.getString("padCode"); + } + + return padCodesResult; + + } catch (JSONException e) { + LogFileUtil.logAndWrite(Log.ERROR, "ArmCloudApiClient", "getInstanceListInfo: 响应解析失败", e); + throw new IOException("响应解析失败", e); + } + } + } diff --git a/app/src/main/jniLibs/arm64-v8a/libnative.so b/app/src/main/jniLibs/arm64-v8a/libnative.so index 0630454..967a418 100644 Binary files a/app/src/main/jniLibs/arm64-v8a/libnative.so and b/app/src/main/jniLibs/arm64-v8a/libnative.so differ