Browse Source

finish device select

main
MTing 2 weeks ago
parent
commit
a6874004ec
  1. 2
      app/build.gradle
  2. 108
      app/src/main/java/com/ouxuan/oxface/MainActivity.java
  3. 4
      app/src/main/java/com/ouxuan/oxface/OxFaceApplication.java
  4. 491
      app/src/main/java/com/ouxuan/oxface/data/DeviceSelectDataManager.java
  5. 1
      app/src/main/java/com/ouxuan/oxface/device/DeviceUtils.java
  6. 112
      app/src/main/java/com/ouxuan/oxface/example/ApiResponseDataExample.java
  7. 323
      app/src/main/java/com/ouxuan/oxface/network/api/PadApiService.java
  8. 47
      app/src/main/java/com/ouxuan/oxface/network/callback/CompleteApiResponseCallback.java
  9. 97
      app/src/main/java/com/ouxuan/oxface/network/utils/NetworkUtils.java

2
app/build.gradle

@ -38,7 +38,7 @@ android {
minifyEnabled false
debuggable true
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
// versionNameSuffix "-debug"
//
crunchPngs false

108
app/src/main/java/com/ouxuan/oxface/MainActivity.java

@ -23,16 +23,23 @@ import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.ouxuan.oxface.data.DeviceSelectDataManager;
import com.ouxuan.oxface.data.LoginDataManager;
import com.ouxuan.oxface.device.DeviceUtils;
import com.ouxuan.oxface.network.api.PadApiService;
import com.ouxuan.oxface.network.api.UserApiService;
import com.ouxuan.oxface.network.callback.CompleteApiResponseCallback;
import com.ouxuan.oxface.network.callback.NetworkCallback;
import com.ouxuan.oxface.network.model.ApiResponse;
import com.ouxuan.oxface.network.utils.NetworkUtils;
import com.ouxuan.oxface.utils.KeepAliveManager;
import com.ouxuan.oxface.utils.LogManager;
import com.ouxuan.oxface.utils.UtilCodeHelper;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
private EditText editTextUsername;
@ -42,6 +49,7 @@ public class MainActivity extends AppCompatActivity {
private Toast currentToast; // 用于管理Toast显示状态
private boolean isPasswordVisible = false; // 密码显示状态
private LoginDataManager loginDataManager; // 登录数据管理器
private DeviceSelectDataManager deviceSelectDataManager; // 设备选择数据管理器
private KeepAliveManager keepAliveManager; // 保持活跃管理器
@Override
@ -63,6 +71,9 @@ public class MainActivity extends AppCompatActivity {
// 初始化登录数据管理器
loginDataManager = LoginDataManager.getInstance(this);
// 初始化设备选择数据管理器
deviceSelectDataManager = DeviceSelectDataManager.getInstance(this);
// 初始化保持活跃管理器并启动用于24小时无人值守
keepAliveManager = KeepAliveManager.getInstance(this);
keepAliveManager.startKeepAlive(this);
@ -596,18 +607,46 @@ public class MainActivity extends AppCompatActivity {
// 显示loading文字
buttonText.setText("正在进入...");
// 调用Pad选择API使用token而不是sessionId
NetworkUtils.selectPad(selectedPad.getPadId(), getUserId(), getAuthToken(),
new NetworkCallback<PadApiService.PadSelectResponse>() {
// 获取所需参数
int hardwareId = selectedPad.getHardwareId();
String deviceId = DeviceUtils.getFormattedDeviceId(this);
String token = getAuthToken();
// 输出调试日志
android.util.Log.d("MainActivity", "=== 设备选择参数 ===");
android.util.Log.d("MainActivity", "Hardware ID: " + hardwareId);
android.util.Log.d("MainActivity", "Device ID: " + deviceId);
android.util.Log.d("MainActivity", "Token: " + (token != null && !token.isEmpty() ? "present" : "null"));
android.util.Log.d("MainActivity", "Selected Pad Name: " + selectedPad.getHardwareName());
android.util.Log.d("MainActivity", "==========================");
// 调用Pad选择API使用新的API格式支持完整API响应
NetworkUtils.selectPadWithFullResponse(hardwareId, deviceId, token,
new CompleteApiResponseCallback<PadApiService.PadSelectResponse>() {
@Override
public void onSuccess(PadApiService.PadSelectResponse data) {
// 选择成功
showToast("进入 " + selectedPad.getPadName() + " 成功!");
public void onSuccessWithFullResponse(ApiResponse<PadApiService.PadSelectResponse> apiResponse) {
// 选择成功保存完整的API响应数据code和data
showToast("进入 " + selectedPad.getHardwareName() + " 成功!");
// 保存完整的API响应数据到本地进行持久化保存
deviceSelectDataManager.saveCompleteApiResponse(apiResponse, selectedPad);
// 记录操作日志
LogManager.logOperation("MainActivity", "设备选择成功: " + selectedPad.getHardwareName() +
", Hardware ID: " + hardwareId +
", API Code: " + apiResponse.getCode() +
", Data Size: " + (apiResponse.getData() != null ? "present" : "null"));
// 输出保存的数据信息用于调试
android.util.Log.d("MainActivity", "=== 保存的API响应数据 ===");
android.util.Log.d("MainActivity", "API Code: " + deviceSelectDataManager.getApiResponseCode());
android.util.Log.d("MainActivity", "API Data JSON长度: " + deviceSelectDataManager.getApiResponseDataJson().length());
android.util.Log.d("MainActivity", "API Message: " + deviceSelectDataManager.getApiResponseMessage());
android.util.Log.d("MainActivity", "===============================");
dialog.dismiss();
// 这里可以添加跳转到主界面的逻辑
// 保存选中的Pad信息
saveSelectedPadInfo(selectedPad, data);
}
@Override
@ -616,11 +655,13 @@ public class MainActivity extends AppCompatActivity {
android.util.Log.e("MainActivity", "=== 设备选择接口请求异常 ===");
android.util.Log.e("MainActivity", "Error Code: " + errorCode);
android.util.Log.e("MainActivity", "Error Message: " + errorMessage);
android.util.Log.e("MainActivity", "Selected Pad: " + (selectedPad != null ? selectedPad.getPadName() : "null"));
android.util.Log.e("MainActivity", "Hardware ID: " + hardwareId);
android.util.Log.e("MainActivity", "Device ID: " + deviceId);
android.util.Log.e("MainActivity", "Selected Pad: " + (selectedPad != null ? selectedPad.getHardwareName() : "null"));
android.util.Log.e("MainActivity", "==============================");
// 显示错误信息
showToast("选择设备失败: " + errorMessage);
showToast("选择设备失败: 当前设备ID: " + deviceId + errorMessage);
// 恢复按钮状态
buttonEnter.setEnabled(true);
@ -634,23 +675,6 @@ public class MainActivity extends AppCompatActivity {
});
}
/**
* 保存选中的Pad信息
* @param padInfo Pad信息
* @param selectResponse 选择响应
*/
private void saveSelectedPadInfo(PadApiService.PadInfo padInfo, PadApiService.PadSelectResponse selectResponse) {
getSharedPreferences("app_prefs", MODE_PRIVATE)
.edit()
.putString("selected_pad_id", padInfo.getPadId())
.putString("selected_pad_name", padInfo.getPadName())
.putString("session_token", selectResponse.getSessionToken())
.putLong("valid_until", selectResponse.getValidUntil())
.apply();
LogManager.logOperation("MainActivity", "已保存选中的设备信息: " + padInfo.getPadName());
}
@Override
protected void onResume() {
super.onResume();
@ -690,7 +714,8 @@ public class MainActivity extends AppCompatActivity {
buttonLogin.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showLogPathInfo();
// showLogPathInfo();
showToastU_api_response_data();
return true;
}
});
@ -741,4 +766,31 @@ public class MainActivity extends AppCompatActivity {
});
builder.show();
}
/**
* 显示api_response_data_json
*/
private void showToastU_api_response_data()
{
UtilCodeHelper.Toast.cancel();
// device_select_prefs.xml 中的<string name="select_response"> 使用gson转为json并用toast显示其中的hardware_name
DeviceSelectDataManager deviceSelectDataManager = DeviceSelectDataManager.getInstance(this);
String json = deviceSelectDataManager.getApiResponseDataJson();
try {
JSONObject jsonObject = new JSONObject(json);
String hardware_name = jsonObject.getString("hardware_name");
// Toast.showShort(hardware_name);
UtilCodeHelper.Toast.showLong(hardware_name);
} catch (JSONException e) {
e.printStackTrace();
}
// Gson gson = new Gson();
// String apiResponseDataJson = deviceSelectDataManager.getApiResponseDataJson();
// PadApiService.PadSelectResponse apiResponse = gson.fromJson(apiResponseDataJson, PadApiService.PadSelectResponse.class);
// LogManager.logDebug("api_response_data_json", apiResponseDataJson);
// UtilCodeHelper.Toast.showShort(apiResponseDataJson);
}
}

4
app/src/main/java/com/ouxuan/oxface/OxFaceApplication.java

@ -5,6 +5,7 @@ import android.app.Application;
import com.ouxuan.oxface.network.NetworkManager;
import com.ouxuan.oxface.network.NetworkStabilityManager;
import com.ouxuan.oxface.network.utils.NetworkUtils;
import com.ouxuan.oxface.data.DeviceSelectDataManager;
import com.ouxuan.oxface.utils.GlobalExceptionHandler;
import com.ouxuan.oxface.utils.HealthMonitor;
import com.ouxuan.oxface.utils.LogManager;
@ -74,6 +75,9 @@ public class OxFaceApplication extends Application implements
// 7. 初始化原有的网络工具
NetworkUtils.init(this);
// 8. 初始化设备选择数据管理器
DeviceSelectDataManager.getInstance(this);
LogManager.logOperation(TAG, "所有管理器初始化完成,应用已准备好24小时无人值守运行");
} catch (Exception e) {

491
app/src/main/java/com/ouxuan/oxface/data/DeviceSelectDataManager.java

@ -0,0 +1,491 @@
package com.ouxuan.oxface.data;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ouxuan.oxface.network.api.PadApiService;
import com.ouxuan.oxface.network.model.ApiResponse;
/**
* 设备选择数据管理器
* 单例模式用于持久化保存和管理设备选择相关数据
*/
public class DeviceSelectDataManager {
private static final String TAG = "DeviceSelectDataManager";
private static final String PREFS_NAME = "device_select_prefs";
private static final String KEY_SELECT_RESPONSE = "select_response";
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";
// API响应存储相关常量
private static final String KEY_API_RESPONSE_CODE = "api_response_code";
private static final String KEY_API_RESPONSE_DATA_JSON = "api_response_data_json";
private static final String KEY_API_RESPONSE_MESSAGE = "api_response_message";
private static final String KEY_API_FULL_RESPONSE = "api_full_response";
private SharedPreferences preferences;
private Gson gson;
// 单例实例
private static volatile DeviceSelectDataManager instance;
// 内存缓存
private PadApiService.PadSelectResponse currentSelectResponse;
private PadApiService.PadInfo currentSelectedPadInfo;
private boolean isDeviceSelected = false;
// API响应存储
private int apiResponseCode;
private String apiResponseDataJson;
private String apiResponseMessage;
private String apiFullResponse;
private DeviceSelectDataManager(Context context) {
preferences = context.getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
gson = new Gson();
loadSelectDataFromPrefs();
}
/**
* 获取DeviceSelectDataManager单例实例
* @param context 上下文
* @return DeviceSelectDataManager实例
*/
public static DeviceSelectDataManager getInstance(Context context) {
if (instance == null) {
synchronized (DeviceSelectDataManager.class) {
if (instance == null) {
instance = new DeviceSelectDataManager(context);
}
}
}
return instance;
}
/**
* 保存完整的API响应数据包括code和data
* @param apiResponse 完整的API响应
* @param selectedPadInfo 选中的设备信息
*/
public void saveCompleteApiResponse(ApiResponse<PadApiService.PadSelectResponse> apiResponse, PadApiService.PadInfo selectedPadInfo) {
if (apiResponse == null) {
Log.w(TAG, "API响应数据为空,无法保存");
return;
}
try {
// 保存到内存缓存
this.currentSelectResponse = apiResponse.getData();
this.currentSelectedPadInfo = selectedPadInfo;
this.isDeviceSelected = apiResponse.isSuccess();
this.apiResponseCode = apiResponse.getCode();
this.apiResponseMessage = apiResponse.getMessage();
// 将data对象转换为JSON字符串
if (apiResponse.getData() != null) {
this.apiResponseDataJson = gson.toJson(apiResponse.getData());
}
// 将完整响应转换为JSON字符串
this.apiFullResponse = gson.toJson(apiResponse);
// 保存到持久化存储
SharedPreferences.Editor editor = preferences.edit();
// 保存原有的设备选择数据
editor.putString(KEY_SELECT_RESPONSE, gson.toJson(currentSelectResponse));
if (selectedPadInfo != null) {
editor.putInt(KEY_SELECTED_HARDWARE_ID, selectedPadInfo.getHardwareId());
editor.putString(KEY_SELECTED_HARDWARE_NAME, selectedPadInfo.getHardwareName());
}
if (currentSelectResponse != null && currentSelectResponse.getSessionToken() != null) {
editor.putString(KEY_SESSION_TOKEN, currentSelectResponse.getSessionToken());
}
editor.putLong(KEY_VALID_UNTIL, currentSelectResponse != null ? currentSelectResponse.getValidUntil() : 0);
editor.putLong(KEY_SELECT_TIME, System.currentTimeMillis());
editor.putBoolean(KEY_IS_DEVICE_SELECTED, isDeviceSelected);
// 保存API响应数据
editor.putInt(KEY_API_RESPONSE_CODE, apiResponseCode);
editor.putString(KEY_API_RESPONSE_DATA_JSON, apiResponseDataJson);
editor.putString(KEY_API_RESPONSE_MESSAGE, apiResponseMessage);
editor.putString(KEY_API_FULL_RESPONSE, apiFullResponse);
editor.apply();
Log.d(TAG, "完整API响应数据保存成功");
logCompleteApiResponseInfo();
} catch (Exception e) {
Log.e(TAG, "保存API响应数据失败: " + e.getMessage(), e);
}
}
/**
* 获取当前选择响应数据
* @return 选择响应数据如果未选择返回null
*/
public PadApiService.PadSelectResponse getSelectResponse() {
return currentSelectResponse;
}
/**
* 获取当前选中的设备信息
* @return 选中的设备信息如果未选择返回null
*/
public PadApiService.PadInfo getSelectedPadInfo() {
return currentSelectedPadInfo;
}
/**
* 获取会话Token
* @return 会话Token
*/
public String getSessionToken() {
if (currentSelectResponse != null) {
return currentSelectResponse.getSessionToken();
}
return preferences.getString(KEY_SESSION_TOKEN, "");
}
/**
* 获取选中的硬件ID
* @return 硬件ID
*/
public int getSelectedHardwareId() {
if (currentSelectedPadInfo != null) {
return currentSelectedPadInfo.getHardwareId();
}
return preferences.getInt(KEY_SELECTED_HARDWARE_ID, 0);
}
/**
* 获取选中的硬件名称
* @return 硬件名称
*/
public String getSelectedHardwareName() {
if (currentSelectedPadInfo != null) {
return currentSelectedPadInfo.getHardwareName();
}
return preferences.getString(KEY_SELECTED_HARDWARE_NAME, "");
}
/**
* 获取有效期至
* @return 有效期时间戳
*/
public long getValidUntil() {
if (currentSelectResponse != null) {
return currentSelectResponse.getValidUntil();
}
return preferences.getLong(KEY_VALID_UNTIL, 0);
}
/**
* 检查是否已选择设备
* @return true如果已选择设备
*/
public boolean isDeviceSelected() {
return isDeviceSelected && currentSelectResponse != null;
}
/**
* 检查会话是否有效
* @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;
}
/**
* 检查是否可以继续使用当前设备
* @return true如果可以继续使用
*/
public boolean canContinueUsingDevice() {
return isDeviceSelected() && isSessionValid();
}
/**
* 清除设备选择数据
*/
public void clearDeviceSelectData() {
// 清除内存缓存
this.currentSelectResponse = null;
this.currentSelectedPadInfo = null;
this.isDeviceSelected = false;
this.apiResponseCode = 0;
this.apiResponseDataJson = null;
this.apiResponseMessage = null;
this.apiFullResponse = null;
// 清除持久化存储
SharedPreferences.Editor editor = preferences.edit();
editor.remove(KEY_SELECT_RESPONSE);
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);
// 清除API响应数据
editor.remove(KEY_API_RESPONSE_CODE);
editor.remove(KEY_API_RESPONSE_DATA_JSON);
editor.remove(KEY_API_RESPONSE_MESSAGE);
editor.remove(KEY_API_FULL_RESPONSE);
editor.apply();
Log.d(TAG, "设备选择数据已清除");
}
/**
* 从SharedPreferences加载设备选择数据
*/
private void loadSelectDataFromPrefs() {
try {
String selectResponseJson = preferences.getString(KEY_SELECT_RESPONSE, "");
boolean savedIsDeviceSelected = preferences.getBoolean(KEY_IS_DEVICE_SELECTED, false);
if (!selectResponseJson.isEmpty() && savedIsDeviceSelected) {
currentSelectResponse = gson.fromJson(selectResponseJson, PadApiService.PadSelectResponse.class);
// 重建PadInfo对象
int hardwareId = preferences.getInt(KEY_SELECTED_HARDWARE_ID, 0);
String hardwareName = preferences.getString(KEY_SELECTED_HARDWARE_NAME, "");
if (hardwareId > 0) {
currentSelectedPadInfo = new PadApiService.PadInfo();
currentSelectedPadInfo.setHardwareId(hardwareId);
currentSelectedPadInfo.setHardwareName(hardwareName);
}
isDeviceSelected = true;
Log.d(TAG, "从本地存储恢复设备选择数据成功");
} else {
Log.d(TAG, "本地无有效设备选择数据");
}
// 加载API响应数据
apiResponseCode = preferences.getInt(KEY_API_RESPONSE_CODE, 0);
apiResponseDataJson = preferences.getString(KEY_API_RESPONSE_DATA_JSON, null);
apiResponseMessage = preferences.getString(KEY_API_RESPONSE_MESSAGE, null);
apiFullResponse = preferences.getString(KEY_API_FULL_RESPONSE, null);
if (apiResponseCode > 0 || (apiResponseDataJson != null && !apiResponseDataJson.isEmpty())) {
Log.d(TAG, "从本地存储恢复API响应数据成功");
}
} catch (Exception e) {
Log.e(TAG, "加载设备选择数据失败: " + e.getMessage());
// 清除可能损坏的数据
clearDeviceSelectData();
}
}
/**
* 打印选择信息到日志
*/
private void logSelectInfo() {
if (currentSelectResponse != null) {
Log.i(TAG, "=== 当前设备选择信息 ===");
Log.i(TAG, "选择结果: " + currentSelectResponse.getResult());
Log.i(TAG, "响应消息: " + currentSelectResponse.getMessage());
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, "========================");
}
}
/**
* 获取选择时间
* @return 选择时间戳
*/
public long getSelectTime() {
return preferences.getLong(KEY_SELECT_TIME, 0);
}
// ========== API响应数据相关方法 ==========
/**
* 保存设备选择响应数据兼容旧代码
* @param selectResponse 选择响应数据
* @param selectedPadInfo 选中的设备信息
*/
public void saveDeviceSelectData(PadApiService.PadSelectResponse selectResponse, PadApiService.PadInfo selectedPadInfo) {
if (selectResponse == null) {
Log.w(TAG, "选择响应数据为空,无法保存");
return;
}
// 保存到内存缓存
this.currentSelectResponse = selectResponse;
this.currentSelectedPadInfo = selectedPadInfo;
this.isDeviceSelected = true;
// 保存到持久化存储
SharedPreferences.Editor editor = preferences.edit();
editor.putString(KEY_SELECT_RESPONSE, gson.toJson(selectResponse));
if (selectedPadInfo != null) {
editor.putInt(KEY_SELECTED_HARDWARE_ID, selectedPadInfo.getHardwareId());
editor.putString(KEY_SELECTED_HARDWARE_NAME, selectedPadInfo.getHardwareName());
}
if (selectResponse.getSessionToken() != null) {
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);
editor.apply();
Log.d(TAG, "设备选择数据保存成功");
logSelectInfo();
}
/**
* 获取API响应的Code
* @return API响应的Code
*/
public int getApiResponseCode() {
return apiResponseCode != 0 ? apiResponseCode : preferences.getInt(KEY_API_RESPONSE_CODE, -1);
}
/**
* 获取API响应的DataJSON形式
* @return API响应的Data以JSON字符串形式返回
*/
public String getApiResponseDataJson() {
return apiResponseDataJson != null ? apiResponseDataJson : preferences.getString(KEY_API_RESPONSE_DATA_JSON, "");
}
/**
* 获取API响应的Message
* @return API响应的Message
*/
public String getApiResponseMessage() {
return apiResponseMessage != null ? apiResponseMessage : preferences.getString(KEY_API_RESPONSE_MESSAGE, "");
}
/**
* 获取完整的API响应JSON形式
* @return 完整的API响应以JSON字符串形式返回
*/
public String getApiFullResponse() {
return apiFullResponse != null ? apiFullResponse : preferences.getString(KEY_API_FULL_RESPONSE, "");
}
/**
* 解析API响应的Data为PadConfig对象
* @return PadConfig对象如果解析失败返回null
*/
public PadApiService.PadConfig getPadConfig() {
try {
String dataJson = getApiResponseDataJson();
if (!dataJson.isEmpty()) {
PadApiService.PadSelectResponse response = gson.fromJson(dataJson, PadApiService.PadSelectResponse.class);
return response != null ? response.getPadConfig() : null;
}
} catch (Exception e) {
Log.e(TAG, "解析PadConfig失败: " + e.getMessage());
}
return null;
}
/**
* 获取店铺信息
* @return 包含店铺名称和Logo的数组[name, logo]
*/
public String[] getStoreInfo() {
try {
String dataJson = getApiResponseDataJson();
if (!dataJson.isEmpty()) {
PadApiService.PadSelectResponse response = gson.fromJson(dataJson, PadApiService.PadSelectResponse.class);
if (response != null) {
return new String[]{response.getName(), response.getLogo()};
}
}
} catch (Exception e) {
Log.e(TAG, "获取店铺信息失败: " + e.getMessage());
}
return new String[]{"", ""};
}
/**
* 检查是否有完整的API响应数据
* @return true如果有完整的API响应数据
*/
public boolean hasCompleteApiResponse() {
return getApiResponseCode() >= 0 && !getApiResponseDataJson().isEmpty();
}
/**
* 清除API响应数据
*/
public void clearApiResponseData() {
// 清除内存缓存
this.apiResponseCode = 0;
this.apiResponseDataJson = null;
this.apiResponseMessage = null;
this.apiFullResponse = null;
// 清除持久化存储
SharedPreferences.Editor editor = preferences.edit();
editor.remove(KEY_API_RESPONSE_CODE);
editor.remove(KEY_API_RESPONSE_DATA_JSON);
editor.remove(KEY_API_RESPONSE_MESSAGE);
editor.remove(KEY_API_FULL_RESPONSE);
editor.apply();
Log.d(TAG, "API响应数据已清除");
}
/**
* 打印完整API响应信息到日志
*/
private void logCompleteApiResponseInfo() {
Log.i(TAG, "=== 完整API响应信息 ===");
Log.i(TAG, "API响应Code: " + getApiResponseCode());
Log.i(TAG, "API响应Message: " + getApiResponseMessage());
Log.i(TAG, "API响应Data长度: " + getApiResponseDataJson().length() + " 字符");
Log.i(TAG, "API完整响应长度: " + getApiFullResponse().length() + " 字符");
// 打印设备配置信息
PadApiService.PadConfig padConfig = getPadConfig();
if (padConfig != null) {
Log.i(TAG, "设备配置 - ID: " + padConfig.getId() + ", 用户名: " + padConfig.getUsername());
Log.i(TAG, "设备配置 - 人脸识别: " + (padConfig.getIsCheckFace() == 1 ? "开启" : "关闭"));
Log.i(TAG, "设备配置 - 使用场景: " + padConfig.getPadUseScene());
}
// 打印店铺信息
String[] storeInfo = getStoreInfo();
Log.i(TAG, "店铺信息 - 名称: " + storeInfo[0] + ", Logo: " + (storeInfo[1].length() > 0 ? "已设置" : "未设置"));
Log.i(TAG, "==============================");
}
}

1
app/src/main/java/com/ouxuan/oxface/device/DeviceUtils.java

@ -22,6 +22,7 @@ public class DeviceUtils {
String android_id = "";
try {
android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
// android_id = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
Log.d(TAG, "Android ID: " + android_id);
} catch (Exception e) {
Log.e(TAG, "获取Android ID失败: " + e.getMessage());

112
app/src/main/java/com/ouxuan/oxface/example/ApiResponseDataExample.java

@ -0,0 +1,112 @@
package com.ouxuan.oxface.example;
import android.content.Context;
import android.util.Log;
import com.ouxuan.oxface.data.DeviceSelectDataManager;
import com.ouxuan.oxface.network.api.PadApiService;
/**
* API响应数据使用示例
* 展示如何使用DeviceSelectDataManager获取保存的API响应数据
*/
public class ApiResponseDataExample {
private static final String TAG = "ApiResponseExample";
/**
* 展示如何获取和使用保存的API响应数据
* @param context 上下文
*/
public static void demonstrateApiResponseData(Context context) {
DeviceSelectDataManager dataManager = DeviceSelectDataManager.getInstance(context);
// 检查是否有完整的API响应数据
if (dataManager.hasCompleteApiResponse()) {
Log.d(TAG, "=== API响应数据使用示例 ===");
// 获取API响应的Code和Message
int apiCode = dataManager.getApiResponseCode();
String apiMessage = dataManager.getApiResponseMessage();
Log.d(TAG, "API Code: " + apiCode);
Log.d(TAG, "API Message: " + apiMessage);
// 获取API响应的DataJSON形式
String dataJson = dataManager.getApiResponseDataJson();
Log.d(TAG, "API Data (JSON): " + dataJson.substring(0, Math.min(100, dataJson.length())) + "...");
// 获取设备配置信息
PadApiService.PadConfig padConfig = dataManager.getPadConfig();
if (padConfig != null) {
Log.d(TAG, "设备配置 - ID: " + padConfig.getId());
Log.d(TAG, "设备配置 - 用户名: " + padConfig.getUsername());
Log.d(TAG, "设备配置 - 人脸识别: " + (padConfig.getIsCheckFace() == 1 ? "开启" : "关闭"));
Log.d(TAG, "设备配置 - 使用场景: " + padConfig.getPadUseScene());
Log.d(TAG, "设备配置 - 设备ID: " + padConfig.getDeviceId());
}
// 获取店铺信息
String[] storeInfo = dataManager.getStoreInfo();
Log.d(TAG, "店铺名称: " + storeInfo[0]);
Log.d(TAG, "店铺Logo: " + storeInfo[1]);
// 获取选中的设备信息
Log.d(TAG, "选中设备 - Hardware ID: " + dataManager.getSelectedHardwareId());
Log.d(TAG, "选中设备 - 设备名称: " + dataManager.getSelectedHardwareName());
// 获取会话信息
Log.d(TAG, "会话Token: " + (dataManager.getSessionToken().isEmpty() ? "未设置" : "已设置"));
Log.d(TAG, "会话有效期: " + dataManager.getValidUntil());
Log.d(TAG, "会话是否有效: " + dataManager.isSessionValid());
Log.d(TAG, "========================");
} else {
Log.d(TAG, "暂无完整的API响应数据");
}
}
/**
* 展示API响应数据的具体使用场景
* @param context 上下文
*/
public static void useCaseExample(Context context) {
DeviceSelectDataManager dataManager = DeviceSelectDataManager.getInstance(context);
// 使用场景1检查人脸识别是否开启
PadApiService.PadConfig padConfig = dataManager.getPadConfig();
if (padConfig != null && padConfig.getIsCheckFace() == 1) {
Log.d(TAG, "人脸识别功能已开启,可以启动人脸识别模块");
}
// 使用场景2根据使用场景调整UI
if (padConfig != null) {
String useScene = padConfig.getPadUseScene();
switch (useScene) {
case "venue":
Log.d(TAG, "场馆模式:显示场馆相关功能");
break;
case "store":
Log.d(TAG, "店铺模式:显示店铺相关功能");
break;
default:
Log.d(TAG, "默认模式:显示通用功能");
break;
}
}
// 使用场景3获取店铺Logo用于界面显示
String[] storeInfo = dataManager.getStoreInfo();
String logoUrl = storeInfo[1];
if (!logoUrl.isEmpty()) {
Log.d(TAG, "可以使用Glide加载店铺Logo: " + logoUrl);
// 示例Glide.with(context).load(logoUrl).into(imageView);
}
// 使用场景4检查会话有效性
if (dataManager.canContinueUsingDevice()) {
Log.d(TAG, "可以继续使用当前设备");
} else {
Log.d(TAG, "需要重新选择设备或重新登录");
}
}
}

323
app/src/main/java/com/ouxuan/oxface/network/api/PadApiService.java

@ -297,32 +297,57 @@ public interface PadApiService {
/**
* Pad选择请求模型
* 期望格式{"hardware_id":593,"device_id":"c9cb00145a2ac56f","token":"pad_63_0d4d6091-dd7c-11ec-9f35-5254005df464"}
*/
public static class PadSelectRequest {
private String padId; // 选择的Pad ID
private String userId; // 用户ID
@SerializedName("hardware_id")
private int hardwareId; // 硬件ID设备ID
@SerializedName("device_id")
private String deviceId; // 设备唯一标识
@SerializedName("token")
private String token; // 访问令牌统一认证方式
private String selectReason; // 选择原因可选
public PadSelectRequest(String padId, String userId, String token) {
this.padId = padId;
this.userId = userId;
private String selectReason; // 选择原因可选不发送到服务器
public PadSelectRequest(int hardwareId, String deviceId, String token) {
this.hardwareId = hardwareId;
this.deviceId = deviceId;
this.token = token;
}
// Getters and Setters
public String getPadId() { return padId; }
public void setPadId(String padId) { this.padId = padId; }
public int getHardwareId() { return hardwareId; }
public void setHardwareId(int hardwareId) { this.hardwareId = hardwareId; }
public String getUserId() { return userId; }
public void setUserId(String userId) { this.userId = userId; }
public String getDeviceId() { return deviceId; }
public void setDeviceId(String deviceId) { this.deviceId = deviceId; }
public String getToken() { return token; }
public void setToken(String token) { this.token = token; }
public String getSelectReason() { return selectReason; }
public void setSelectReason(String selectReason) { this.selectReason = selectReason; }
// 兼容旧代码的方法
@Deprecated
public String getPadId() { return String.valueOf(hardwareId); }
@Deprecated
public void setPadId(String padId) {
try {
this.hardwareId = Integer.parseInt(padId);
} catch (NumberFormatException e) {
this.hardwareId = 0;
}
}
@Deprecated
public String getUserId() { return deviceId; }
@Deprecated
public void setUserId(String userId) { this.deviceId = userId; }
@Deprecated
public String getSessionId() {
android.util.Log.w("PadSelectRequest", "getSessionId()方法已废弃,请使用getToken()");
return token;
@ -333,15 +358,32 @@ public interface PadApiService {
android.util.Log.w("PadSelectRequest", "setSessionId()方法已废弃,请使用setToken()");
this.token = sessionId;
}
public String getSelectReason() { return selectReason; }
public void setSelectReason(String selectReason) { this.selectReason = selectReason; }
}
/**
* Pad选择响应模型
* 匹配实际API响应格式
*/
public static class PadSelectResponse {
@SerializedName("advert_list")
private java.util.List<Object> advertList; // 广告列表
@SerializedName("hardware_id")
private int hardwareId; // 硬件ID
@SerializedName("hardware_name")
private String hardwareName; // 硬件名称
@SerializedName("logo")
private String logo; // 店铺Logo
@SerializedName("name")
private String name; // 店铺名称
@SerializedName("pad_config")
private PadConfig padConfig; // 设备配置信息
// 兼容旧代码的字段保持向后兼容
private String result; // 选择结果success/failed
private String message; // 响应消息
private String selectedPadId; // 已选择的Pad ID
@ -350,16 +392,35 @@ public interface PadApiService {
private long validUntil; // 有效期至
// Getters and Setters
public String getResult() { return result; }
public java.util.List<Object> getAdvertList() { return advertList; }
public void setAdvertList(java.util.List<Object> advertList) { this.advertList = advertList; }
public int getHardwareId() { return hardwareId; }
public void setHardwareId(int hardwareId) { this.hardwareId = hardwareId; }
public String getHardwareName() { return hardwareName; }
public void setHardwareName(String hardwareName) { this.hardwareName = hardwareName; }
public String getLogo() { return logo; }
public void setLogo(String logo) { this.logo = logo; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public PadConfig getPadConfig() { return padConfig; }
public void setPadConfig(PadConfig padConfig) { this.padConfig = padConfig; }
// 兼容旧代码的方法
public String getResult() { return result != null ? result : "success"; }
public void setResult(String result) { this.result = result; }
public String getMessage() { return message; }
public String getMessage() { return message != null ? message : ""; }
public void setMessage(String message) { this.message = message; }
public String getSelectedPadId() { return selectedPadId; }
public String getSelectedPadId() { return selectedPadId != null ? selectedPadId : String.valueOf(hardwareId); }
public void setSelectedPadId(String selectedPadId) { this.selectedPadId = selectedPadId; }
public String getSelectedPadName() { return selectedPadName; }
public String getSelectedPadName() { return selectedPadName != null ? selectedPadName : hardwareName; }
public void setSelectedPadName(String selectedPadName) { this.selectedPadName = selectedPadName; }
public String getSessionToken() { return sessionToken; }
@ -368,4 +429,232 @@ public interface PadApiService {
public long getValidUntil() { return validUntil; }
public void setValidUntil(long validUntil) { this.validUntil = validUntil; }
}
/**
* 设备配置信息模型
*/
public static class PadConfig {
@SerializedName("id")
private int id;
@SerializedName("created_at")
private String createdAt;
@SerializedName("updated_at")
private String updatedAt;
@SerializedName("brand_id")
private int brandId;
@SerializedName("stadium_id")
private int stadiumId;
@SerializedName("stadium_hardware_id")
private int stadiumHardwareId;
@SerializedName("id_ouxuanac")
private String idOuxuanac;
@SerializedName("is_check_face")
private int isCheckFace;
@SerializedName("face_license")
private String faceLicense;
@SerializedName("device_id")
private String deviceId;
@SerializedName("is_show_advert")
private int isShowAdvert;
@SerializedName("is_show_gate_btn")
private int isShowGateBtn;
@SerializedName("gate_id")
private int gateId;
@SerializedName("is_auto_on_off")
private int isAutoOnOff;
@SerializedName("auto_on_time")
private String autoOnTime;
@SerializedName("auto_off_time")
private String autoOffTime;
@SerializedName("is_code_verify")
private int isCodeVerify;
@SerializedName("is_scan_verify")
private int isScanVerify;
@SerializedName("is_scan_code_verify")
private int isScanCodeVerify;
@SerializedName("is_pvface_many_leave")
private int isPvfaceManyLeave;
@SerializedName("support_verify_modules")
private String supportVerifyModules;
@SerializedName("mark")
private String mark;
@SerializedName("extension")
private String extension;
@SerializedName("username")
private String username;
@SerializedName("is_temperature_measurement")
private int isTemperatureMeasurement;
@SerializedName("is_pay_card_verify")
private int isPayCardVerify;
@SerializedName("show_tips")
private String showTips;
@SerializedName("locker_id")
private int lockerId;
@SerializedName("dev_name")
private String devName;
@SerializedName("dev_ip")
private String devIp;
@SerializedName("leave_code_type")
private int leaveCodeType;
@SerializedName("pad_use_scene")
private String padUseScene;
@SerializedName("rent_permissions")
private String rentPermissions;
@SerializedName("credit_card_verification")
private String creditCardVerification;
@SerializedName("qr_code_verification")
private String qrCodeVerification;
@SerializedName("wristband_type")
private String wristbandType;
@SerializedName("gate_name")
private String gateName;
// Getters and Setters
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getCreatedAt() { return createdAt; }
public void setCreatedAt(String createdAt) { this.createdAt = createdAt; }
public String getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; }
public int getBrandId() { return brandId; }
public void setBrandId(int brandId) { this.brandId = brandId; }
public int getStadiumId() { return stadiumId; }
public void setStadiumId(int stadiumId) { this.stadiumId = stadiumId; }
public int getStadiumHardwareId() { return stadiumHardwareId; }
public void setStadiumHardwareId(int stadiumHardwareId) { this.stadiumHardwareId = stadiumHardwareId; }
public String getIdOuxuanac() { return idOuxuanac; }
public void setIdOuxuanac(String idOuxuanac) { this.idOuxuanac = idOuxuanac; }
public int getIsCheckFace() { return isCheckFace; }
public void setIsCheckFace(int isCheckFace) { this.isCheckFace = isCheckFace; }
public String getFaceLicense() { return faceLicense; }
public void setFaceLicense(String faceLicense) { this.faceLicense = faceLicense; }
public String getDeviceId() { return deviceId; }
public void setDeviceId(String deviceId) { this.deviceId = deviceId; }
public int getIsShowAdvert() { return isShowAdvert; }
public void setIsShowAdvert(int isShowAdvert) { this.isShowAdvert = isShowAdvert; }
public int getIsShowGateBtn() { return isShowGateBtn; }
public void setIsShowGateBtn(int isShowGateBtn) { this.isShowGateBtn = isShowGateBtn; }
public int getGateId() { return gateId; }
public void setGateId(int gateId) { this.gateId = gateId; }
public int getIsAutoOnOff() { return isAutoOnOff; }
public void setIsAutoOnOff(int isAutoOnOff) { this.isAutoOnOff = isAutoOnOff; }
public String getAutoOnTime() { return autoOnTime; }
public void setAutoOnTime(String autoOnTime) { this.autoOnTime = autoOnTime; }
public String getAutoOffTime() { return autoOffTime; }
public void setAutoOffTime(String autoOffTime) { this.autoOffTime = autoOffTime; }
public int getIsCodeVerify() { return isCodeVerify; }
public void setIsCodeVerify(int isCodeVerify) { this.isCodeVerify = isCodeVerify; }
public int getIsScanVerify() { return isScanVerify; }
public void setIsScanVerify(int isScanVerify) { this.isScanVerify = isScanVerify; }
public int getIsScanCodeVerify() { return isScanCodeVerify; }
public void setIsScanCodeVerify(int isScanCodeVerify) { this.isScanCodeVerify = isScanCodeVerify; }
public int getIsPvfaceManyLeave() { return isPvfaceManyLeave; }
public void setIsPvfaceManyLeave(int isPvfaceManyLeave) { this.isPvfaceManyLeave = isPvfaceManyLeave; }
public String getSupportVerifyModules() { return supportVerifyModules; }
public void setSupportVerifyModules(String supportVerifyModules) { this.supportVerifyModules = supportVerifyModules; }
public String getMark() { return mark; }
public void setMark(String mark) { this.mark = mark; }
public String getExtension() { return extension; }
public void setExtension(String extension) { this.extension = extension; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public int getIsTemperatureMeasurement() { return isTemperatureMeasurement; }
public void setIsTemperatureMeasurement(int isTemperatureMeasurement) { this.isTemperatureMeasurement = isTemperatureMeasurement; }
public int getIsPayCardVerify() { return isPayCardVerify; }
public void setIsPayCardVerify(int isPayCardVerify) { this.isPayCardVerify = isPayCardVerify; }
public String getShowTips() { return showTips; }
public void setShowTips(String showTips) { this.showTips = showTips; }
public int getLockerId() { return lockerId; }
public void setLockerId(int lockerId) { this.lockerId = lockerId; }
public String getDevName() { return devName; }
public void setDevName(String devName) { this.devName = devName; }
public String getDevIp() { return devIp; }
public void setDevIp(String devIp) { this.devIp = devIp; }
public int getLeaveCodeType() { return leaveCodeType; }
public void setLeaveCodeType(int leaveCodeType) { this.leaveCodeType = leaveCodeType; }
public String getPadUseScene() { return padUseScene; }
public void setPadUseScene(String padUseScene) { this.padUseScene = padUseScene; }
public String getRentPermissions() { return rentPermissions; }
public void setRentPermissions(String rentPermissions) { this.rentPermissions = rentPermissions; }
public String getCreditCardVerification() { return creditCardVerification; }
public void setCreditCardVerification(String creditCardVerification) { this.creditCardVerification = creditCardVerification; }
public String getQrCodeVerification() { return qrCodeVerification; }
public void setQrCodeVerification(String qrCodeVerification) { this.qrCodeVerification = qrCodeVerification; }
public String getWristbandType() { return wristbandType; }
public void setWristbandType(String wristbandType) { this.wristbandType = wristbandType; }
public String getGateName() { return gateName; }
public void setGateName(String gateName) { this.gateName = gateName; }
}
}

47
app/src/main/java/com/ouxuan/oxface/network/callback/CompleteApiResponseCallback.java

@ -0,0 +1,47 @@
package com.ouxuan.oxface.network.callback;
import com.ouxuan.oxface.network.model.ApiResponse;
/**
* 完整API响应回调接口
* 扩展NetworkCallback支持获取完整的API响应对象包含code和data
*/
public abstract class CompleteApiResponseCallback<T> {
/**
* 成功回调传递完整的API响应对象
* @param apiResponse 完整的API响应对象包含codedatamessage等
*/
public abstract void onSuccessWithFullResponse(ApiResponse<T> apiResponse);
/**
* 请求开始回调
*/
public void onStart() {
// 默认空实现子类可以重写
}
/**
* 错误回调
* @param errorCode 错误代码
* @param errorMessage 错误消息
*/
public void onError(int errorCode, String errorMessage) {
// 默认空实现子类可以重写
}
/**
* 异常回调
* @param throwable 异常对象
*/
public void onException(Throwable throwable) {
// 默认空实现子类可以重写
}
/**
* 请求完成回调无论成功还是失败
*/
public void onComplete() {
// 默认空实现子类可以重写
}
}

97
app/src/main/java/com/ouxuan/oxface/network/utils/NetworkUtils.java

@ -5,6 +5,7 @@ import android.content.Context;
import com.ouxuan.oxface.network.NetworkManager;
import com.ouxuan.oxface.network.api.PadApiService;
import com.ouxuan.oxface.network.api.UserApiService;
import com.ouxuan.oxface.network.callback.CompleteApiResponseCallback;
import com.ouxuan.oxface.network.callback.NetworkCallback;
import com.ouxuan.oxface.network.model.ApiResponse;
@ -401,19 +402,102 @@ public class NetworkUtils {
/**
* Pad选择确认
* @param hardwareId 硬件ID设备ID
* @param deviceId 设备唯一标识
* @param token 访问令牌统一认证方式
* @param callback 回调接口
*/
public static void selectPad(int hardwareId, String deviceId, String token,
NetworkCallback<PadApiService.PadSelectResponse> callback) {
if (padApiService == null) {
callback.onError(-1, "NetworkUtils未初始化,请先调用init()方法");
return;
}
// 输出详细的调试日志
android.util.Log.d("NetworkUtils", "selectPad - hardware_id: " + hardwareId +
", device_id: " + deviceId + ", token: " + (token != null ? "present" : "null"));
PadApiService.PadSelectRequest request = new PadApiService.PadSelectRequest(hardwareId, deviceId, token);
callback.onStart();
padApiService.padSelect(request).enqueue(new Callback<ApiResponse<PadApiService.PadSelectResponse>>() {
@Override
public void onResponse(Call<ApiResponse<PadApiService.PadSelectResponse>> call,
Response<ApiResponse<PadApiService.PadSelectResponse>> response) {
try {
if (response.isSuccessful() && response.body() != null) {
ApiResponse<PadApiService.PadSelectResponse> apiResponse = response.body();
// 添加详细的调试日志
android.util.Log.d("NetworkUtils", "selectPad Response - Code: " + apiResponse.getCode() +
", Message: '" + apiResponse.getMessage() + "'" +
", Success: " + apiResponse.isSuccess() +
", Data: " + (apiResponse.getData() != null ? "not null" : "null"));
if (apiResponse.isSuccess()) {
callback.onSuccess(apiResponse.getData());
} else {
// 打印详细的错误日志
logApiError("selectPad", apiResponse.getCode(), apiResponse.getMessage());
callback.onError(apiResponse.getCode(), apiResponse.getMessage());
}
} else {
callback.onError(response.code(), "请求失败: " + response.message());
}
} catch (Exception e) {
callback.onException(e);
} finally {
callback.onComplete();
}
}
@Override
public void onFailure(Call<ApiResponse<PadApiService.PadSelectResponse>> call, Throwable t) {
callback.onException(t);
callback.onComplete();
}
});
}
/**
* Pad选择确认兼容旧方法
* @deprecated 请使用 selectPad(int hardwareId, String deviceId, String token, NetworkCallback callback)
* @param padId 选择的Pad ID
* @param userId 用户ID
* @param token 访问令牌统一认证方式
* @param callback 回调接口
*/
@Deprecated
public static void selectPad(String padId, String userId, String token,
NetworkCallback<PadApiService.PadSelectResponse> callback) {
try {
int hardwareId = Integer.parseInt(padId);
selectPad(hardwareId, userId, token, callback);
} catch (NumberFormatException e) {
callback.onError(-1, "无效的padId格式: " + padId);
}
}
/**
* Pad选择确认支持完整API响应回调
* @param hardwareId 硬件ID设备ID
* @param deviceId 设备唯一标识
* @param token 访问令牌统一认证方式
* @param callback 完整API响应回调接口
*/
public static void selectPadWithFullResponse(int hardwareId, String deviceId, String token,
CompleteApiResponseCallback<PadApiService.PadSelectResponse> callback) {
if (padApiService == null) {
callback.onError(-1, "NetworkUtils未初始化,请先调用init()方法");
return;
}
PadApiService.PadSelectRequest request = new PadApiService.PadSelectRequest(padId, userId, token);
// 输出详细的调试日志
android.util.Log.d("NetworkUtils", "selectPadWithFullResponse - hardware_id: " + hardwareId +
", device_id: " + deviceId + ", token: " + (token != null ? "present" : "null"));
PadApiService.PadSelectRequest request = new PadApiService.PadSelectRequest(hardwareId, deviceId, token);
callback.onStart();
padApiService.padSelect(request).enqueue(new Callback<ApiResponse<PadApiService.PadSelectResponse>>() {
@ -424,11 +508,18 @@ public class NetworkUtils {
if (response.isSuccessful() && response.body() != null) {
ApiResponse<PadApiService.PadSelectResponse> apiResponse = response.body();
// 添加详细的调试日志
android.util.Log.d("NetworkUtils", "selectPadWithFullResponse Response - Code: " + apiResponse.getCode() +
", Message: '" + apiResponse.getMessage() + "'" +
", Success: " + apiResponse.isSuccess() +
", Data: " + (apiResponse.getData() != null ? "not null" : "null"));
if (apiResponse.isSuccess()) {
callback.onSuccess(apiResponse.getData());
// 传递完整的API响应对象
callback.onSuccessWithFullResponse(apiResponse);
} else {
// 打印详细的错误日志
logApiError("selectPad", apiResponse.getCode(), apiResponse.getMessage());
logApiError("selectPadWithFullResponse", apiResponse.getCode(), apiResponse.getMessage());
callback.onError(apiResponse.getCode(), apiResponse.getMessage());
}
} else {

Loading…
Cancel
Save