diff --git a/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java b/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java index f222f55..2541405 100644 --- a/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java +++ b/app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java @@ -163,6 +163,7 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi // 新增订单查验相关变量 private int modeType = 0; // 1验证码验证 2人脸验证 3扫码验证 4扫码器验证 private String verifyCode = ""; // 验证码 + private com.ouxuan.oxface.data.LoginDataManager loginDataManager; // 新增LoginDataManager实例 @Override protected void onCreate(Bundle savedInstanceState) { @@ -173,6 +174,8 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi LogManager.logInfo(TAG, "OXFaceOnlineActivity onCreate开始"); mContext = this; + // 初始化LoginDataManager + loginDataManager = com.ouxuan.oxface.data.LoginDataManager.getInstance(this); initView(); // 初始化人脸检测状态 @@ -1353,6 +1356,10 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi * 处理验证码提交 */ private void handleVerificationCodeSubmit(String verificationCode) { + // 设置验证码验证模式 + modeType = 1; + verifyCode = verificationCode; + // 显示验证状态 if (layoutCompareStatus != null) { layoutCompareStatus.setVisibility(View.VISIBLE); @@ -1360,29 +1367,8 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi textCompareStatus.setText("正在验证验证码..."); } - // TODO: 这里添加实际的验证码验证逻辑 - // 例如:发送网络请求验证验证码 - - // 模拟验证成功 - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - if (layoutCompareStatus != null) { - textCompareStatus.setText("验证码验证成功,正在开门..."); - - // 延迟开门 - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - if (layoutCompareStatus != null) { - layoutCompareStatus.setVisibility(View.GONE); - } - Toast.makeText(OXFaceOnlineActivity.this, "门已打开", Toast.LENGTH_SHORT).show(); - } - }, 1000); - } - } - }, 2000); + // 调用订单查询方法进行验证码验证 + getCheckOrder(); } /** @@ -1443,6 +1429,14 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi } /** + * 获取认证Token(统一认证方式) + * @return Token字符串 + */ + private String getAuthToken() { + return loginDataManager.getAuthToken(); + } + + /** * 查验订单列表 * 根据modeType和verifyCode等参数获取相应的数据查询参数并发送网络请求 */ @@ -1454,7 +1448,7 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi com.ouxuan.oxface.data.DeviceSelectDataManager.getInstance(this); // 获取token和hardware_id - String token = deviceDataManager.getSessionToken(); + String token = getAuthToken(); // 修改为使用getAuthToken()方法获取token int hardwareId = deviceDataManager.getSelectedHardwareId(); // 参数校验 diff --git a/app/src/main/java/com/ouxuan/oxface/data/DeviceSelectDataManager.java b/app/src/main/java/com/ouxuan/oxface/data/DeviceSelectDataManager.java index 26fcd42..2471495 100644 --- a/app/src/main/java/com/ouxuan/oxface/data/DeviceSelectDataManager.java +++ b/app/src/main/java/com/ouxuan/oxface/data/DeviceSelectDataManager.java @@ -22,7 +22,6 @@ public class DeviceSelectDataManager { private static final String KEY_SELECTED_HARDWARE_ID = "selected_hardware_id"; private static final String KEY_SELECTED_HARDWARE_NAME = "selected_hardware_name"; private static final String KEY_SESSION_TOKEN = "session_token"; - private static final String KEY_VALID_UNTIL = "valid_until"; private static final String KEY_SELECT_TIME = "select_time"; private static final String KEY_IS_DEVICE_SELECTED = "is_device_selected"; @@ -84,6 +83,13 @@ public class DeviceSelectDataManager { } /** + * 重新加载设备选择数据(用于调试和修复数据问题) + */ + public void reloadSelectData() { + loadSelectDataFromPrefs(); + } + + /** * 保存完整的API响应数据(包括code和data) * @param apiResponse 完整的API响应 * @param selectedPadInfo 选中的设备信息 @@ -125,9 +131,12 @@ public class DeviceSelectDataManager { if (currentSelectResponse != null && currentSelectResponse.getSessionToken() != null) { editor.putString(KEY_SESSION_TOKEN, currentSelectResponse.getSessionToken()); + Log.d(TAG, "保存sessionToken到SharedPreferences: " + currentSelectResponse.getSessionToken()); + } else { + Log.w(TAG, "currentSelectResponse或sessionToken为空,无法保存"); } - editor.putLong(KEY_VALID_UNTIL, currentSelectResponse != null ? currentSelectResponse.getValidUntil() : 0); + // 移除了对KEY_VALID_UNTIL的使用,因为服务器不再返回valid_until字段 editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); editor.putBoolean(KEY_IS_DEVICE_SELECTED, isDeviceSelected); @@ -147,7 +156,9 @@ public class DeviceSelectDataManager { editor.putString(KEY_MINI_QRCODE_URL, miniQrcodeUrl); } - editor.apply(); + // 确保数据被提交 + boolean commitResult = editor.commit(); + Log.d(TAG, "SharedPreferences提交结果: " + commitResult); Log.d(TAG, "完整API响应数据保存成功"); logCompleteApiResponseInfo(); @@ -178,10 +189,39 @@ public class DeviceSelectDataManager { * @return 会话Token */ public String getSessionToken() { + // 首先尝试从内存缓存获取 if (currentSelectResponse != null) { - return currentSelectResponse.getSessionToken(); + String token = currentSelectResponse.getSessionToken(); + if (token != null && !token.isEmpty()) { + return token; + } + } + + // 如果内存缓存中没有,则尝试从SharedPreferences获取 + String token = preferences.getString(KEY_SESSION_TOKEN, ""); + if (token != null && !token.isEmpty()) { + // 同时更新内存缓存 + if (currentSelectResponse == null) { + // 尝试重建currentSelectResponse + String selectResponseJson = preferences.getString(KEY_SELECT_RESPONSE, ""); + if (!selectResponseJson.isEmpty()) { + try { + currentSelectResponse = gson.fromJson(selectResponseJson, PadApiService.PadSelectResponse.class); + } catch (Exception e) { + Log.e(TAG, "重建currentSelectResponse时发生异常: " + e.getMessage()); + } + } + } + + // 确保currentSelectResponse中的sessionToken也被更新 + if (currentSelectResponse != null) { + currentSelectResponse.setSessionToken(token); + } + + return token; } - return preferences.getString(KEY_SESSION_TOKEN, ""); + + return ""; } /** @@ -211,10 +251,8 @@ public class DeviceSelectDataManager { * @return 有效期时间戳 */ public long getValidUntil() { - if (currentSelectResponse != null) { - return currentSelectResponse.getValidUntil(); - } - return preferences.getLong(KEY_VALID_UNTIL, 0); + // 服务器不再返回valid_until字段,始终返回0 + return 0; } /** @@ -230,16 +268,9 @@ public class DeviceSelectDataManager { * @return true如果会话有效 */ public boolean isSessionValid() { - long validUntil = getValidUntil(); - if (validUntil <= 0) { - return false; - } - - long currentTime = System.currentTimeMillis(); - boolean isValid = currentTime < validUntil; - - Log.d(TAG, "会话有效性检查 - 当前时间: " + currentTime + ", 有效期至: " + validUntil + ", 有效: " + isValid); - return isValid; + // 服务器不再返回valid_until字段,无法检查会话有效性 + // 默认返回true,假设会话始终有效 + return true; } /** @@ -273,7 +304,6 @@ public class DeviceSelectDataManager { editor.remove(KEY_SELECTED_HARDWARE_ID); editor.remove(KEY_SELECTED_HARDWARE_NAME); editor.remove(KEY_SESSION_TOKEN); - editor.remove(KEY_VALID_UNTIL); editor.remove(KEY_SELECT_TIME); editor.putBoolean(KEY_IS_DEVICE_SELECTED, false); @@ -302,12 +332,18 @@ public class DeviceSelectDataManager { String selectResponseJson = preferences.getString(KEY_SELECT_RESPONSE, ""); boolean savedIsDeviceSelected = preferences.getBoolean(KEY_IS_DEVICE_SELECTED, false); + Log.d(TAG, "从SharedPreferences加载数据: selectResponseJson=" + (selectResponseJson != null ? selectResponseJson.length() : 0) + + "字符, savedIsDeviceSelected=" + savedIsDeviceSelected); + if (!selectResponseJson.isEmpty() && savedIsDeviceSelected) { currentSelectResponse = gson.fromJson(selectResponseJson, PadApiService.PadSelectResponse.class); + Log.d(TAG, "成功解析selectResponseJson"); // 重建PadInfo对象 int hardwareId = preferences.getInt(KEY_SELECTED_HARDWARE_ID, 0); String hardwareName = preferences.getString(KEY_SELECTED_HARDWARE_NAME, ""); + Log.d(TAG, "从SharedPreferences获取hardwareId=" + hardwareId + ", hardwareName=" + hardwareName); + if (hardwareId > 0) { currentSelectedPadInfo = new PadApiService.PadInfo(); currentSelectedPadInfo.setHardwareId(hardwareId); @@ -326,11 +362,31 @@ public class DeviceSelectDataManager { apiResponseMessage = preferences.getString(KEY_API_RESPONSE_MESSAGE, null); apiFullResponse = preferences.getString(KEY_API_FULL_RESPONSE, null); + Log.d(TAG, "加载API响应数据: code=" + apiResponseCode + + ", dataJson=" + (apiResponseDataJson != null ? apiResponseDataJson.length() : 0) + "字符" + + ", message=" + (apiResponseMessage != null ? apiResponseMessage : "null") + + ", fullResponse=" + (apiFullResponse != null ? apiFullResponse.length() : 0) + "字符"); + // 新增:加载人脸识别许可证 faceLicense = preferences.getString(KEY_FACE_LICENSE, null); // 新增:加载小程序码链接 miniQrcodeUrl = preferences.getString(KEY_MINI_QRCODE_URL, null); + uploadFaceMiniQrcodeUrl = preferences.getString(KEY_UPLOAD_FACE_MINI_QRCODE_URL, null); + + // 确保sessionToken也被正确加载到内存中 + String sessionToken = preferences.getString(KEY_SESSION_TOKEN, ""); + Log.d(TAG, "从SharedPreferences加载sessionToken: " + (sessionToken != null ? sessionToken.length() : 0) + "字符"); + + if (currentSelectResponse != null && (currentSelectResponse.getSessionToken() == null || currentSelectResponse.getSessionToken().isEmpty())) { + // 如果currentSelectResponse中的sessionToken为空,但SharedPreferences中有,尝试更新 + if (sessionToken != null && !sessionToken.isEmpty()) { + currentSelectResponse.setSessionToken(sessionToken); + Log.d(TAG, "通过setSessionToken更新currentSelectResponse中的sessionToken成功"); + } + } else if (currentSelectResponse != null) { + Log.d(TAG, "currentSelectResponse中已有sessionToken: " + (currentSelectResponse.getSessionToken() != null ? currentSelectResponse.getSessionToken().length() : 0) + "字符"); + } if (apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) { Log.d(TAG, "从本地存储恢复API响应数据成功"); @@ -364,7 +420,6 @@ public class DeviceSelectDataManager { Log.i(TAG, "选中设备ID: " + getSelectedHardwareId()); Log.i(TAG, "选中设备名称: " + getSelectedHardwareName()); Log.i(TAG, "会话Token: " + (getSessionToken() != null && !getSessionToken().isEmpty() ? "已设置" : "未设置")); - Log.i(TAG, "有效期至: " + getValidUntil()); Log.i(TAG, "会话是否有效: " + isSessionValid()); Log.i(TAG, "========================"); } @@ -412,7 +467,6 @@ public class DeviceSelectDataManager { editor.putString(KEY_SESSION_TOKEN, selectResponse.getSessionToken()); } - editor.putLong(KEY_VALID_UNTIL, selectResponse.getValidUntil()); editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis()); editor.putBoolean(KEY_IS_DEVICE_SELECTED, true); diff --git a/app/src/main/java/com/ouxuan/oxface/network/NetworkManager.java b/app/src/main/java/com/ouxuan/oxface/network/NetworkManager.java index ab6257a..7010f59 100644 --- a/app/src/main/java/com/ouxuan/oxface/network/NetworkManager.java +++ b/app/src/main/java/com/ouxuan/oxface/network/NetworkManager.java @@ -10,6 +10,7 @@ import com.ouxuan.oxface.network.callback.NetworkCallback; import com.ouxuan.oxface.network.interceptor.HeaderInterceptor; import com.ouxuan.oxface.network.interceptor.NetworkDebugInterceptor; import com.ouxuan.oxface.network.model.ApiResponse; +import com.ouxuan.oxface.network.model.Extension; import com.ouxuan.oxface.utils.LogManager; import java.util.concurrent.TimeUnit; @@ -213,6 +214,9 @@ public class NetworkManager { // 解析响应数据 ApiResponse apiResponse = gson.fromJson(responseBody, ApiResponse.class); + // 处理extension字段 + handleExtensionField(apiResponse, request, responseBody); + // 主线程回调结果 mainHandler.post(() -> { if (apiResponse.isSuccess()) { @@ -231,6 +235,7 @@ public class NetworkManager { } } catch (Exception e) { // 解析异常 + LogManager.logError(TAG, "网络请求解析异常: " + e.getMessage(), e); mainHandler.post(() -> { callback.onException(e); callback.onComplete(); @@ -241,6 +246,7 @@ public class NetworkManager { @Override public void onFailure(Call call, java.io.IOException e) { // 网络请求失败 + LogManager.logError(TAG, "网络请求失败: " + e.getMessage(), e); mainHandler.post(() -> { callback.onException(e); callback.onComplete(); @@ -250,6 +256,37 @@ public class NetworkManager { } /** + * 处理API响应中的extension字段 + * @param apiResponse API响应对象 + * @param request 请求对象 + * @param responseBody 响应体字符串 + */ + private void handleExtensionField(ApiResponse apiResponse, Request request, String responseBody) { + try { + if (apiResponse != null) { + Extension extension = apiResponse.getExtension(); + if (extension != null) { + // 记录extension信息到日志(简化版本,避免日志过长) + LogManager.logInfo(TAG, "API响应包含extension字段 - URL: " + request.url() + + ", Code: " + apiResponse.getCode() + + ", Message: " + apiResponse.getMessage() + + ", Extension: extension fixed"); // 将extension字段替换为固定字符串 + + // 如果响应码表示错误,且存在扩展信息,则记录基本错误信息 + if (!apiResponse.isSuccess()) { + LogManager.logError(TAG, "API错误详情 - URL: " + request.url() + + ", Code: " + apiResponse.getCode() + + ", Message: " + apiResponse.getMessage() + + ", Extension: extension fixed"); // 将extension字段替换为固定字符串 + } + } + } + } catch (Exception e) { + LogManager.logError(TAG, "处理extension字段时发生异常: " + e.getMessage(), e); + } + } + + /** * 重新初始化网络管理器(用于网络恢复后的重置) */ public void reinitialize() { diff --git a/app/src/main/java/com/ouxuan/oxface/network/model/ApiResponse.java b/app/src/main/java/com/ouxuan/oxface/network/model/ApiResponse.java index 947580a..9b974d9 100644 --- a/app/src/main/java/com/ouxuan/oxface/network/model/ApiResponse.java +++ b/app/src/main/java/com/ouxuan/oxface/network/model/ApiResponse.java @@ -1,5 +1,7 @@ package com.ouxuan.oxface.network.model; +import com.google.gson.annotations.SerializedName; + /** * 通用API响应数据模型 * @param 具体的数据类型 @@ -10,6 +12,7 @@ public class ApiResponse { private String message; // 响应消息 private T data; // 具体数据 private boolean success; // 是否成功 + private Extension extension; // 扩展信息字段 public ApiResponse() { } @@ -55,6 +58,14 @@ public class ApiResponse { this.success = success; } + public Extension getExtension() { + return extension; + } + + public void setExtension(Extension extension) { + this.extension = extension; + } + @Override public String toString() { return "ApiResponse{" + @@ -62,6 +73,7 @@ public class ApiResponse { ", message='" + message + '\'' + ", data=" + data + ", success=" + success + + ", extension=extension fixed" + // 将extension字段替换为固定字符串 '}'; } } \ No newline at end of file diff --git a/app/src/main/java/com/ouxuan/oxface/network/model/Extension.java b/app/src/main/java/com/ouxuan/oxface/network/model/Extension.java new file mode 100644 index 0000000..c5d735b --- /dev/null +++ b/app/src/main/java/com/ouxuan/oxface/network/model/Extension.java @@ -0,0 +1,50 @@ +package com.ouxuan.oxface.network.model; + +import com.google.gson.annotations.SerializedName; +import java.util.List; + +/** + * Extension字段模型类 + * 用于解析API响应中的extension字段 + */ +public class Extension { + @SerializedName("call_stack") + private List callStack; + + @SerializedName("host") + private String host; + + @SerializedName("last_run_sql") + private List lastRunSql; + + // Getters and setters + public List getCallStack() { + return callStack; + } + + public void setCallStack(List callStack) { + this.callStack = callStack; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public List getLastRunSql() { + return lastRunSql; + } + + public void setLastRunSql(List lastRunSql) { + this.lastRunSql = lastRunSql; + } + + @Override + public String toString() { + // 将extension字段替换为固定字符串,避免日志过长 + return "extension fixed"; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ouxuan/oxface/utils/LogManager.java b/app/src/main/java/com/ouxuan/oxface/utils/LogManager.java index 85ed0f9..d41a820 100644 --- a/app/src/main/java/com/ouxuan/oxface/utils/LogManager.java +++ b/app/src/main/java/com/ouxuan/oxface/utils/LogManager.java @@ -141,8 +141,9 @@ public class LogManager { */ public static void logInfo(String tag, String message) { if (instance != null) { - instance.addLogEntry("INFO", tag, message, null); +// instance.addLogEntry("INFO", tag, message, null); } + android.util.Log.d(tag,message); //切换为logcat输入日志 } /** @@ -159,8 +160,9 @@ public class LogManager { */ public static void logError(String tag, String message) { if (instance != null) { - instance.addLogEntry("ERROR", tag, message, null); +// instance.addLogEntry("ERROR", tag, message, null); } + android.util.Log.e(tag,message); //切换为logcat输入日志 } /**