Jelajahi Sumber

fix(网络请求):增加支付时的callbackoutTime

Zhenghj 1 tahun lalu
induk
melakukan
cd5167bb5f

+ 2 - 2
app/build.gradle

@@ -21,8 +21,8 @@ android {
         applicationId "com.doverfuelingsolutions.issp"
         minSdkVersion 22
         targetSdkVersion 26
-        versionCode 16
-        versionName "1.2.03"
+        versionCode 17
+        versionName "1.2.04"
         archivesBaseName = versionName + "." + getTime()
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

+ 10 - 1
app/src/main/java/com/doverfuelingsolutions/issp/api/SystemApi.kt

@@ -34,6 +34,7 @@ object SystemApi {
     private var serviceLogin = makeLoginService()
     private var serviceBase = makeBaseService()
     private var serviceTrx = makeTrxService()
+    private var servicePay = makePayService()
     private var serviceConfig = makeConfigService()
     private var serviceAssets = makeAssetsService()
 
@@ -227,7 +228,7 @@ object SystemApi {
         }
 
         DFSLog.i("支付类型:${posTrxMop.posMopPaymentId}")
-        serviceTrx.pay(posTrx.id, posTrxMop).enqueue(object : Callback<ResultPayment> {
+        servicePay.pay(posTrx.id, posTrxMop).enqueue(object : Callback<ResultPayment> {
             override fun onResponse(call: Call<ResultPayment>, response: Response<ResultPayment>) {
                 val body = response.body()
                 val codeResponse = response.code()
@@ -494,6 +495,7 @@ object SystemApi {
         serviceLogin = makeLoginService()
         serviceBase = makeBaseService()
         serviceTrx = makeTrxService()
+        servicePay = makePayService()
         serviceConfig = makeConfigService()
     }
 
@@ -563,6 +565,13 @@ object SystemApi {
             .create(ServiceTrx::class.java)
     }
 
+    private fun makePayService():ServiceTrx {
+        return RetrofitUtil.getPayBuilder()
+            .baseUrl(WayneApiConfig.HOST_TRX)
+            .build()
+            .create(ServiceTrx::class.java)
+    }
+
     private fun makeConfigService(): ServiceConfig {
         return RetrofitUtil.getAuthBuilder()
             .baseUrl(WayneApiConfig.HOST_CONFIG)

+ 1 - 0
app/src/main/java/com/doverfuelingsolutions/issp/api/WayneApiConfig.kt

@@ -9,6 +9,7 @@ class WayneApiConfig {
 
         const val timeoutConnect = 120L
         const val timeoutAll = 25L //超时时间由原本的 180 秒改为 20 秒
+        const val timeoutPay = 60L //支付的超时时间长一点,有时是等待输入密码导致响应时间比较长
 
         const val PATH_BASE_TOKEN = "token"
         const val PATH_BASE_DEVICE_SESSION = "api/DeviceManagement/GetCurrentSessionInfo"

+ 14 - 0
app/src/main/java/com/doverfuelingsolutions/issp/api/basic/RetrofitUtil.kt

@@ -29,6 +29,14 @@ object RetrofitUtil {
         .connectionPool(connectionPool)
         .addInterceptor(authInterceptor)
         .addInterceptor(loggingInterceptor)
+    private val payHttpBuilder = OkHttpClient.Builder()
+        .connectTimeout(WayneApiConfig.timeoutConnect, TimeUnit.SECONDS)
+        .readTimeout(WayneApiConfig.timeoutAll, TimeUnit.SECONDS)
+        .writeTimeout(WayneApiConfig.timeoutAll, TimeUnit.SECONDS)
+        .callTimeout(WayneApiConfig.timeoutPay, TimeUnit.SECONDS)
+        .connectionPool(connectionPool)
+        .addInterceptor(authInterceptor)
+        .addInterceptor(loggingInterceptor)
 
     private val mGsonConverterFactory: GsonConverterFactory by lazy { GsonConverterFactory.create() }
 
@@ -43,4 +51,10 @@ object RetrofitUtil {
             .addConverterFactory(mGsonConverterFactory)
             .client(authHttpBuilder.build())
     }
+
+    fun getPayBuilder():Retrofit.Builder {
+        return Retrofit.Builder()
+            .addConverterFactory(mGsonConverterFactory)
+            .client(payHttpBuilder.build())
+    }
 }