新路交工具类以及网络请求改造
This commit is contained in:
parent
a3cae11a8a
commit
1ded7d3719
@ -94,8 +94,8 @@ android {
|
||||
JPUSH_APPKEY : "fba6f55621c670d8c1fe9191",
|
||||
//暂时填写默认值即可.
|
||||
JPUSH_CHANNEL: "developer-n"]
|
||||
buildConfigField("String", "OPEN_AL_URL", "\"https://oapi-staging.alct56.com\"")
|
||||
buildConfigField("String", "BASE_URL", "\"http://192.168.1.118:8082/devApi/\"")
|
||||
buildConfigField("String", "BASE_LJ_URL", "\"http://api.kehui56.cn/api/v1/\"")
|
||||
// buildConfigField("String", "BASE_URL", "\"http://192.168.1.118:8080/devApi/\"")
|
||||
// buildConfigField("String", "BASE_URL", "\"http://platform.test.v2.dahehuoyun.com/devApi/\"")
|
||||
buildConfigField "boolean", "isTest", "true"
|
||||
@ -111,8 +111,8 @@ android {
|
||||
JPUSH_APPKEY : "fba6f55621c670d8c1fe9191",
|
||||
//暂时填写默认值即可.
|
||||
JPUSH_CHANNEL: "developer-default"]
|
||||
buildConfigField("String", "OPEN_AL_URL", "\"https://oapi.alct56.com\"")
|
||||
buildConfigField("String", "BASE_URL", "\"http://app.dahehuoyun.com/api/\"")
|
||||
buildConfigField("String", "BASE_LJ_URL", "\"https://api.kehui56.com/api/v1/\"")
|
||||
buildConfigField "boolean", "isTest", "false"
|
||||
resValue "string", "appName", "司机端"
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.base
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.BuildConfig
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2022/1/10 11:34
|
||||
* @description:交通厅参数
|
||||
*/
|
||||
object NewLJConstant {
|
||||
const val ENTER_PRISE_CODE: String = "E0019169"
|
||||
|
||||
val ENTER_PRISE_IDENTITY: String = if (BuildConfig.isTest) "95033cc3492e420d83d7f09eea1400ac" else "9179388b0e0847e1862d6400f9cbc778"
|
||||
|
||||
val ENTER_PRISE_KEY: String =
|
||||
if (BuildConfig.isTest) "e9844a9b0bba417e89cb8623489abd2f" else "156d724e9701420198fcbd52cb1ca529"
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.bean
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
/**
|
||||
* @ClassName NewLjBean
|
||||
* @Author john
|
||||
* @Date 2025/1/21 09:16
|
||||
* @Description TODO
|
||||
*/
|
||||
data class LjTokenBean(
|
||||
var enterpriseCode: String = "",
|
||||
var enterpriseIdentity: String = "",
|
||||
var enterpriseKey: String = ""
|
||||
)
|
||||
|
||||
|
||||
data class PickupBean(
|
||||
var shipmentCode: String = "", var enterpriseCode: String = "", var location: GDLocation? = null
|
||||
)
|
||||
|
||||
data class GDLocation(
|
||||
var baiduLongitude: Double = 0.0,
|
||||
var baiduLatitude: Double = 0.0,
|
||||
var location: String,
|
||||
var time: String,
|
||||
var altitude: Double = 0.0,
|
||||
var speed: Float = 0f,
|
||||
var direction: Float = 0f,
|
||||
var interval: Int = 0
|
||||
)
|
||||
|
||||
data class UpimgBean(var shipmentCode: String="", var enterpriseCode: String="", var image: GDImage? = null)
|
||||
|
||||
data class GDImage(
|
||||
var fileName: String, var fileData: String, var fileExt: String, var imageTakenDate: String
|
||||
)
|
||||
|
||||
data class InvoiceBean(
|
||||
var driverIdentification: String="",
|
||||
var driverInvoiceCode: String="",
|
||||
var enterpriseCode: String=""
|
||||
)
|
||||
|
||||
data class ShipmentStatusBean(var shipmentCode: String="", var enterpriseCode: String="")
|
||||
|
||||
|
||||
data class InvoicesBean(
|
||||
var totalPage: String? = null,
|
||||
var totalCount: String? = null,
|
||||
var pageSize: String? = null,
|
||||
var currentPage: String? = null,
|
||||
var sortField: String? = null,
|
||||
var sortDirection: String? = null,
|
||||
var driverInvoices: List<DataDTO>? = null
|
||||
) : Serializable {
|
||||
|
||||
data class DataDTO(
|
||||
var taxAmount: String? = null,
|
||||
var totalAmount: String? = null,
|
||||
var invoiceReceiverName: String? = null,
|
||||
var totalAmountIncludeTax: String? = null,
|
||||
var driverInvoiceCode: String? = null,
|
||||
var taxRate: String? = null
|
||||
)
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.callback
|
||||
|
||||
/**
|
||||
* @ClassName OnGDDownloadResultListener
|
||||
* @Author john
|
||||
* @Date 2025/1/21 10:40
|
||||
* @Description TODO
|
||||
*/
|
||||
interface OnGDDownloadResultListener {
|
||||
fun onSuccess(var1: String)
|
||||
|
||||
fun onFailure(code: String, message: String)
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.callback
|
||||
|
||||
/**
|
||||
* @ClassName OnGDResultListener
|
||||
* @Author john
|
||||
* @Date 2025/1/21 10:14
|
||||
* @Description TODO
|
||||
*/
|
||||
interface OnGDResultListener {
|
||||
fun onSuccess()
|
||||
|
||||
fun onFailure(code: String, message: String)
|
||||
}
|
@ -1,26 +1,36 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.net
|
||||
|
||||
import com.arpa.glex.bean.*
|
||||
import com.arpa.hndahesudintocctmsdriver.BuildConfig
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.AppVersion
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.AuthTeamBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.CaptainBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.CarBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.CarDetail
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.CashConfig
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.DiCarColor
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.DriverBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.FaceBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.InviteRecord
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.InvoiceBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.InvoicesBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.LjTokenBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.MessageBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.MyJtt
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.MyLocation
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.OcrPersonBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.OrderChild
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.OrderDetailBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.OssBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.PickupBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.ProBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.QueDetail
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.QuestionBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.RateBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.ShipmentStatusBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpBankInfoBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpCaptain
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpCashBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpDriverCar
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpDriverInfoBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpDrivingInfoBean
|
||||
@ -32,19 +42,18 @@ import com.arpa.hndahesudintocctmsdriver.bean.UpPicBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpQualiInfoBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpRate
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpRoadInfoBean
|
||||
import com.arpa.glex.bean.*
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.CashConfig
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.MyJtt
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.MyLocation
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpCashBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpimgBean
|
||||
import com.arpa.mylibrary.net.CommonResponseBean
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import okhttp3.MultipartBody
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.PUT
|
||||
import retrofit2.http.Part
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
||||
|
||||
@ -662,10 +671,149 @@ interface Api {
|
||||
@GET(BASE_URL + "driver/message/read")
|
||||
fun messageRead(@Query("messageId") messageId: String): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
|
||||
/*********安联开始***********/
|
||||
|
||||
@POST(BASE_LJ_URL + "openapi/enterprises/login")
|
||||
fun getToken(@Body bean: LjTokenBean?): Observable<CommonResponseBean<Any>>
|
||||
|
||||
@POST(BASE_LJ_URL + "openapi/enterprises/login")
|
||||
fun getRefreshToken(@Body bean: LjTokenBean?): Call<HashMap<String, String>>
|
||||
|
||||
|
||||
/**
|
||||
* 运单提货
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "openapi/shipments/pickup")
|
||||
fun pickup(@Body bean: PickupBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 运单卸货
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "openapi/shipments/unload")
|
||||
fun unload(@Body bean: PickupBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 运单签收
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "openapi/shipments/sign")
|
||||
fun sign(@Body bean: PickupBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 运单回单
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "openapi/shipments/pod")
|
||||
fun pod(@Body bean: PickupBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 运单提货照片上传
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "openapi/shipments/uploadPickupImage")
|
||||
fun uploadPickupImage(@Body bean: UpimgBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 运单卸货照片上传
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "openapi/shipments/uploadUnloadImage")
|
||||
fun uploadUnloadImage(@Body bean: UpimgBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 运单回单照片上传
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "openapi/shipments/uploadPODImage")
|
||||
fun uploadPODImage(@Body bean: UpimgBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 同意发票申请
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@PUT(BASE_LJ_URL + "openapi/confirmInvoice")
|
||||
fun confirmInvoice(@Body bean: InvoiceBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
/**
|
||||
* 待同意发票列表获取
|
||||
* @param enterpriseCodeParam
|
||||
* @param driverIdentification
|
||||
* @param currentPage
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GET(BASE_LJ_URL + "openapi/getInvoices")
|
||||
fun getInvoices(
|
||||
@Query("enterpriseCodeParam") enterpriseCodeParam: String?,
|
||||
@Query("driverIdentification") driverIdentification: String?,
|
||||
@Query("currentPage") currentPage: Int,
|
||||
@Query("pageSize") pageSize: Int
|
||||
): Observable<CommonResponseBean<InvoicesBean>>
|
||||
|
||||
|
||||
/**
|
||||
* 获取运单状态
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
@POST(BASE_LJ_URL + "/openapi/getShipmentStatus")
|
||||
fun getShipmentStatus(@Body bean: ShipmentStatusBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
@POST(BASE_LJ_URL + "/openapi/shipments/getPODImageNames")
|
||||
fun getPODImageNames(@Body bean: ShipmentStatusBean): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
@GET("$BASE_LJ_URL/openapi/drivers")
|
||||
fun searchDriver(@Query("identityNo") identityNo: String): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/**
|
||||
* 司机车辆绑定关系
|
||||
* @param identityNo
|
||||
* @return
|
||||
*/
|
||||
@GET(BASE_LJ_URL + "openapi/drivers/{identityNo}/trucks")
|
||||
fun trucks(@Path("identityNo") identityNo: String): Observable<CommonResponseBean<Any>>
|
||||
|
||||
|
||||
/*********安联结束***********/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
// String BASE_URL = "https://tmstest.dahehuoyun.com/";
|
||||
const val BASE_URL = BuildConfig.BASE_URL
|
||||
|
||||
const val BASE_LJ_URL: String =BuildConfig.BASE_LJ_URL
|
||||
|
||||
//获取版本
|
||||
const val VERSION = BASE_URL + "app/version"
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.arpa.hndahesudintocctmsdriver.net
|
||||
|
||||
import com.arpa.mylibrary.CommonBaseLibrary
|
||||
import com.arpa.mylibrary.base.BaseSingNoParam
|
||||
import com.arpa.mylibrary.net.JsonInterceptor
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.ObservableTransformer
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
|
@ -0,0 +1,120 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.net;
|
||||
|
||||
import static com.arpa.mylibrary.utils.BaseSPUtils.NEW_LJ_TOKEN;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.BuildConfig;
|
||||
import com.arpa.hndahesudintocctmsdriver.base.App;
|
||||
import com.arpa.hndahesudintocctmsdriver.base.NewLJConstant;
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.LjTokenBean;
|
||||
import com.arpa.hndahesudintocctmsdriver.utils.SPUtils;
|
||||
import com.arpa.mylibrary.CommonBaseLibrary;
|
||||
import com.arpa.mylibrary.net.ResultException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import kotlin.jvm.Synchronized;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
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");
|
||||
String url = request.url().url().toString();
|
||||
|
||||
//判断是否是路交接口
|
||||
if (url.startsWith(BuildConfig.BASE_LJ_URL)){
|
||||
if (401 == code) {
|
||||
refreshToken();
|
||||
response.close();
|
||||
try {
|
||||
return chain.proceed(request);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (-1 == code) {
|
||||
jsonObject.put("data", new JSONObject());
|
||||
throw new ResultException();
|
||||
} else {
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
jsonObject.put("data", new JSONObject());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
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;
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private void refreshToken() throws IOException {
|
||||
Api api = CommonBaseLibrary.getRetrofit().newBuilder()
|
||||
.client(new OkHttpClient.Builder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.build())
|
||||
// .addNetworkInterceptor(new TokenInterceptor())
|
||||
.build().create(Api.class);
|
||||
LjTokenBean ljTokenBean = new LjTokenBean();
|
||||
ljTokenBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
||||
ljTokenBean.setEnterpriseIdentity(NewLJConstant.INSTANCE.getENTER_PRISE_IDENTITY());
|
||||
ljTokenBean.setEnterpriseKey(NewLJConstant.INSTANCE.getENTER_PRISE_KEY());
|
||||
retrofit2.Response<HashMap<String, String>> execute = api.getRefreshToken(ljTokenBean).execute();
|
||||
if (execute.body() != null) {
|
||||
String refreshToken = execute.body().get("token");
|
||||
SPUtils.put(App.Companion.getApp(), NEW_LJ_TOKEN, refreshToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,591 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.arpa.hndahesudintocctmsdriver.BuildConfig
|
||||
import com.arpa.hndahesudintocctmsdriver.base.NewLJConstant
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.GDImage
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.GDLocation
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.InvoiceBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.LjTokenBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.PickupBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.ShipmentStatusBean
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UpimgBean
|
||||
import com.arpa.hndahesudintocctmsdriver.callback.OnGDDownloadResultListener
|
||||
import com.arpa.hndahesudintocctmsdriver.callback.OnGDResultListener
|
||||
import com.arpa.hndahesudintocctmsdriver.net.BaseObserver
|
||||
import com.arpa.hndahesudintocctmsdriver.net.DataManager
|
||||
import com.arpa.hndahesudintocctmsdriver.net.RxHttpCallBack
|
||||
import com.arpa.mylibrary.base.SingletonNoPHolder
|
||||
import com.arpa.mylibrary.bean.LJDriverBean
|
||||
import com.arpa.mylibrary.net.CommonResponseBean
|
||||
import com.arpa.mylibrary.utils.BaseSPUtils
|
||||
import com.arpa.mylibrary.utils.BaseSPUtils.NEW_LJ_TOKEN
|
||||
import com.arpa.mylibrary.utils.ToastUtils
|
||||
import com.express.mdp.Api
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
* @ClassName NewLJUtils
|
||||
* @Author john
|
||||
* @Date 2025/1/21 08:59
|
||||
* @Description TODO
|
||||
*/
|
||||
class NewLJUtils private constructor() {
|
||||
|
||||
companion object : SingletonNoPHolder<NewLJUtils>(::NewLJUtils)
|
||||
|
||||
fun getToken(ctx: Context) {
|
||||
val ljTokenBean = LjTokenBean().apply {
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
enterpriseIdentity = NewLJConstant.ENTER_PRISE_IDENTITY
|
||||
enterpriseKey = NewLJConstant.ENTER_PRISE_KEY
|
||||
}
|
||||
|
||||
DataManager.getInstance().getToken(ljTokenBean)
|
||||
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
BaseSPUtils.put(ctx, NEW_LJ_TOKEN, t.getToken())
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
fun getToken(ctx: Context?, listener: OnGDResultListener) {
|
||||
val ljTokenBean = LjTokenBean().apply {
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
enterpriseIdentity = NewLJConstant.ENTER_PRISE_IDENTITY
|
||||
enterpriseKey = NewLJConstant.ENTER_PRISE_KEY
|
||||
}
|
||||
|
||||
DataManager.getInstance().getToken(ljTokenBean)
|
||||
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx!!, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
BaseSPUtils.put(ctx, NEW_LJ_TOKEN, t.getToken())
|
||||
if (listener != null) listener.onSuccess()
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 运单提货
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
* @param location
|
||||
*/
|
||||
fun pickUp(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
location: GDLocation,
|
||||
listener: OnGDResultListener
|
||||
) {
|
||||
if (TextUtils.isEmpty(shipmentCode)) {
|
||||
ToastUtils.showToast(ctx, "运单号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if (location.baiduLongitude == 0.0 || location.baiduLatitude == 0.0) {
|
||||
ToastUtils.showToast(ctx, "经纬度不能为空")
|
||||
return
|
||||
}
|
||||
val pickupBean = PickupBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
this.location = location
|
||||
}
|
||||
DataManager.getInstance().pickup(pickupBean)
|
||||
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单提货操作异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 运单卸货
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
* @param location
|
||||
*/
|
||||
fun unload(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
location: GDLocation,
|
||||
listener: OnGDResultListener
|
||||
) {
|
||||
if (TextUtils.isEmpty(shipmentCode)) {
|
||||
ToastUtils.showToast(ctx, "运单号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if (location.baiduLongitude == 0.0 || location.baiduLatitude == 0.0) {
|
||||
ToastUtils.showToast(ctx, "经纬度不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
val pickupBean = PickupBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
this.location = location
|
||||
}
|
||||
DataManager.getInstance().unload(pickupBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单卸货操作异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 运单签收
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
* @param location
|
||||
*/
|
||||
fun sign(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
location: GDLocation,
|
||||
listener: OnGDResultListener
|
||||
) {
|
||||
if (TextUtils.isEmpty(shipmentCode)) {
|
||||
ToastUtils.showToast(ctx, "运单号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if (location.baiduLongitude == 0.0 || location.baiduLatitude == 0.0) {
|
||||
ToastUtils.showToast(ctx, "经纬度不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
val pickupBean = PickupBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
this.location = location
|
||||
}
|
||||
DataManager.getInstance().sign(pickupBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单签收操作异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 运单回单
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
* @param location
|
||||
*/
|
||||
fun pod(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
location: GDLocation,
|
||||
listener: OnGDResultListener
|
||||
) {
|
||||
if (TextUtils.isEmpty(shipmentCode)) {
|
||||
ToastUtils.showToast(ctx, "运单号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if (location.baiduLongitude == 0.0 || location.baiduLatitude == 0.0) {
|
||||
ToastUtils.showToast(ctx, "经纬度不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
val pickupBean = PickupBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
this.location = location
|
||||
}
|
||||
|
||||
DataManager.getInstance().pod(pickupBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单回单操作异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 运单提货照片上传
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
* @param imageDTO
|
||||
*/
|
||||
fun uploadPickupImage(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
imageDTO: GDImage,
|
||||
listener: OnGDResultListener
|
||||
) {
|
||||
if (TextUtils.isEmpty(shipmentCode)) {
|
||||
ToastUtils.showToast(ctx, "运单号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(imageDTO.fileName)) {
|
||||
ToastUtils.showToast(ctx, "照片不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
val pickupBean: UpimgBean = UpimgBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
image = imageDTO
|
||||
}
|
||||
DataManager.getInstance().uploadPickupImage(pickupBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单提货照片操作异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 运单卸货照片上传
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
* @param imageDTO
|
||||
*/
|
||||
fun uploadUnloadImage(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
imageDTO: GDImage,
|
||||
listener: OnGDResultListener
|
||||
) {
|
||||
if (TextUtils.isEmpty(shipmentCode)) {
|
||||
ToastUtils.showToast(ctx, "运单号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(imageDTO.fileName)) {
|
||||
ToastUtils.showToast(ctx, "照片不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
val pickupBean: UpimgBean = UpimgBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
image = imageDTO
|
||||
}
|
||||
|
||||
DataManager.getInstance().uploadUnloadImage(pickupBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单卸货照片操作异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 运单回单照片上传
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
* @param imageDTO
|
||||
*/
|
||||
fun uploadPODImage(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
imageDTO: GDImage,
|
||||
listener: OnGDResultListener
|
||||
) {
|
||||
if (TextUtils.isEmpty(shipmentCode)) {
|
||||
ToastUtils.showToast(ctx, "运单号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(imageDTO.fileName)) {
|
||||
ToastUtils.showToast(ctx, "照片不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
val pickupBean: UpimgBean = UpimgBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
image = imageDTO
|
||||
}
|
||||
DataManager.getInstance().uploadPODImage(pickupBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单回单照片操作异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 同意发票申请
|
||||
*
|
||||
* @param ctx
|
||||
*/
|
||||
fun confirmInvoice(ctx: Context, listener: OnGDResultListener) {
|
||||
val userInfo = SPUtils.instance.getUserInfo(ctx)
|
||||
if (userInfo == null){
|
||||
ToastUtils.showToast(ctx, "未查到身份证号码")
|
||||
return
|
||||
}
|
||||
val idCardValidity = userInfo.idCardValidity
|
||||
|
||||
searchDriver(ctx, idCardValidity, object : OnGDDownloadResultListener {
|
||||
override fun onSuccess(var1: String) {
|
||||
val invoiceBean: InvoiceBean = InvoiceBean().apply {
|
||||
enterpriseCode=NewLJConstant.ENTER_PRISE_CODE
|
||||
driverInvoiceCode = var1
|
||||
driverIdentification = idCardValidity
|
||||
}
|
||||
DataManager.getInstance().confirmInvoice(invoiceBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess()
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "同意发票异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
override fun onFailure(code: String, message: String) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 运单状态查询
|
||||
*
|
||||
* @param ctx
|
||||
* @param shipmentCode
|
||||
*/
|
||||
fun getShipmentStatus(
|
||||
ctx: Context,
|
||||
shipmentCode: String,
|
||||
listener: OnGDDownloadResultListener
|
||||
) {
|
||||
val shipmentStatusBean: ShipmentStatusBean = ShipmentStatusBean().apply {
|
||||
this.shipmentCode = shipmentCode
|
||||
enterpriseCode = NewLJConstant.ENTER_PRISE_CODE
|
||||
}
|
||||
DataManager.getInstance().getShipmentStatus(shipmentStatusBean)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
listener.onSuccess(t.statusCode)
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "运单状态查询异常" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启位置上传
|
||||
*
|
||||
* @param act
|
||||
*/
|
||||
fun startLocationService(act: AppCompatActivity) {
|
||||
val userInfo = SPUtils.instance.getUserInfo(act)
|
||||
if (userInfo == null){
|
||||
ToastUtils.showToast(act, "未查到身份证号码")
|
||||
return
|
||||
}
|
||||
val idCardValidity = userInfo.idCardValidity
|
||||
searchDriver(act, idCardValidity, object : OnGDDownloadResultListener {
|
||||
override fun onSuccess(var1: String) {
|
||||
try {
|
||||
//开启定位服务
|
||||
if (BuildConfig.isTest) {
|
||||
Api.setBaseUrl("https://kehui56.cn/api", "https://api.kehui56.cn/api")
|
||||
}
|
||||
val result = Api.startLocationService(
|
||||
act, var1
|
||||
) { s: String? ->
|
||||
Log.e(
|
||||
"位置上报",
|
||||
s!!
|
||||
)
|
||||
}
|
||||
println(result)
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(code: String, message: String) {
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭定位服务
|
||||
*/
|
||||
fun stopLocationService() {
|
||||
Api.stopLocationService()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询司机
|
||||
*/
|
||||
fun searchDriver(ctx: Context, idCard: String, listener: OnGDDownloadResultListener) {
|
||||
DataManager.getInstance().searchDriver(idCard)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(ctx, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
val driver: LJDriverBean = t.driver
|
||||
if (!TextUtils.isEmpty(driver.driverCode)) {
|
||||
listener.onSuccess(driver.driverCode)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCodeError(
|
||||
mContext: Context?,
|
||||
t: CommonResponseBean<Any>
|
||||
) {
|
||||
super.onCodeError(mContext, t)
|
||||
listener.onFailure(
|
||||
t.code.toString(),
|
||||
if (TextUtils.isEmpty(t.message)) "司机异常请联系管理员" else t.message
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user