新路交工具类以及网络请求改造
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.arpa.mylibrary.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName LJDriverBean
|
||||
* @Author john
|
||||
* @Date 2025/1/21 10:47
|
||||
* @Description TODO
|
||||
*/
|
||||
public class LJDriverBean implements Serializable {
|
||||
private String driverCode;
|
||||
private String isTaxRegistered;
|
||||
private String taxRegisterStatus;
|
||||
private String taxRegisterStatusDescription;
|
||||
|
||||
public String getDriverCode() {
|
||||
return driverCode;
|
||||
}
|
||||
|
||||
public void setDriverCode(String driverCode) {
|
||||
this.driverCode = driverCode;
|
||||
}
|
||||
|
||||
public String getIsTaxRegistered() {
|
||||
return isTaxRegistered;
|
||||
}
|
||||
|
||||
public void setIsTaxRegistered(String isTaxRegistered) {
|
||||
this.isTaxRegistered = isTaxRegistered;
|
||||
}
|
||||
|
||||
public String getTaxRegisterStatus() {
|
||||
return taxRegisterStatus;
|
||||
}
|
||||
|
||||
public void setTaxRegisterStatus(String taxRegisterStatus) {
|
||||
this.taxRegisterStatus = taxRegisterStatus;
|
||||
}
|
||||
|
||||
public String getTaxRegisterStatusDescription() {
|
||||
return taxRegisterStatusDescription;
|
||||
}
|
||||
|
||||
public void setTaxRegisterStatusDescription(String taxRegisterStatusDescription) {
|
||||
this.taxRegisterStatusDescription = taxRegisterStatusDescription;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.arpa.mylibrary.net;
|
||||
|
||||
import com.arpa.mylibrary.bean.LJDriverBean;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -18,6 +20,70 @@ public class CommonResponseBean<T> extends JSONObject implements Serializable {
|
||||
|
||||
private boolean success;
|
||||
|
||||
private String message;
|
||||
private String url;
|
||||
private String fileName;
|
||||
private String token;
|
||||
private String expiryIn;
|
||||
private String statusCode;
|
||||
|
||||
private LJDriverBean driver;
|
||||
|
||||
public LJDriverBean getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
public void setDriver(LJDriverBean driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getExpiryIn() {
|
||||
return expiryIn;
|
||||
}
|
||||
|
||||
public void setExpiryIn(String expiryIn) {
|
||||
this.expiryIn = expiryIn;
|
||||
}
|
||||
|
||||
public String getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(String statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public int getRes() {
|
||||
return res;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.arpa.mylibrary.net;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
|
||||
/**
|
||||
* json的Interceptor
|
||||
*/
|
||||
|
||||
public class JsonInterceptor implements Interceptor {
|
||||
private static final String TAG = "JsonInterceptor";
|
||||
|
||||
public JsonInterceptor() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
Response response = chain.proceed(request);
|
||||
ResponseBody responseBody = response.body();
|
||||
//为了不消耗buffer,我们这里使用source先获得buffer对象,然后clone()后使用
|
||||
BufferedSource source = responseBody.source();
|
||||
source.request(Long.MAX_VALUE); // Buffer the entire body.
|
||||
//获得返回的数据
|
||||
Buffer buffer = source.buffer();
|
||||
//使用前clone()下,避免直接消耗
|
||||
String responseBodyStr = buffer.clone().readString(Charset.forName("UTF-8"));
|
||||
Log.i(TAG, "result-body= " + responseBodyStr);
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(responseBodyStr);
|
||||
String str = jsonObject.optString("data");
|
||||
int code = jsonObject.optInt("code");
|
||||
// if (500 == code) {
|
||||
// jsonObject.put("data", new JSONObject());
|
||||
// throw new ResultException();
|
||||
// } else {
|
||||
// if (TextUtils.isEmpty(str)) {
|
||||
// jsonObject.put("data", new JSONObject());
|
||||
// }
|
||||
// }
|
||||
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
jsonObject.put("data", new JSONObject());
|
||||
}
|
||||
|
||||
String data = jsonObject.toString();
|
||||
responseBody = ResponseBody.create(MediaType.parse("application/json; charset=utf-8"), data);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
response = response.newBuilder().body(responseBody).build();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public class BaseSPUtils {
|
||||
public static final String USER_INFO_KEY = "driver_user_info_key";
|
||||
public static final String USER_TOKEN_KEY = "driver_user_token_key";
|
||||
public static final String NET_SERVICE_TEST = "driver_net_service_test";
|
||||
public static final String NEW_LJ_TOKEN = "NEW_LJ_TOKEN";
|
||||
public static final String SEARRH_CACHE = "driver_search_cache";
|
||||
public static final String NAVI_PH_EDIT_CACHE = "driver_navi_ph_edit_cache";
|
||||
public static final String FIRST_OPEN = "driver_first_open";
|
||||
|
||||
Reference in New Issue
Block a user