Files
yusheng-android/moduleUtil/src/main/java/com/qxcm/moduleutil/http/ResponseBodyConverter.java
梁小江 314c484cea 1、修改登录功能并验证,除了支付宝登录其他都已验证
2、完成个人中心的功能,个人主页完成、钱包完成、背包完成
2025-05-22 19:03:01 +08:00

42 lines
1.1 KiB
Java

package com.qxcm.moduleutil.http;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.qxcm.moduleutil.utils.GsonUtils;
import java.io.IOException;
import io.reactivex.annotations.NonNull;
import okhttp3.ResponseBody;
import retrofit2.Converter;
public class ResponseBodyConverter<T> implements Converter<ResponseBody, T> {
private final Gson gson;
private final TypeAdapter<T> adapter;
ResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
this.gson = gson;
this.adapter = adapter;
}
@Override
public T convert(@NonNull ResponseBody value) throws IOException {
String json = value.string();
BaseModel obj = GsonUtils.GsonToBean(json, BaseModel.class);
if (obj.getCode() != 1) {
String info = obj.getMsg();
if ("当前余额不足".equals(info)) {
value.close();
return adapter.fromJson(json);
} else {
throw new APIException(obj.getCode(), info);
}
}
value.close();
return adapter.fromJson(json);
}
}