Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MiYaFastCashier
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
MiYaFastCashier
Commits
0b548e35
Commit
0b548e35
authored
Jun 29, 2022
by
赵鹏翔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
网络框架配置优化
parent
02a1d96a
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
213 additions
and
117 deletions
+213
-117
MiyaApplication.kt
app/src/main/java/com/miya/fastcashier/MiyaApplication.kt
+1
-1
FunctionCenterActivity.kt
...n/java/com/miya/fastcashier/log/FunctionCenterActivity.kt
+2
-1
LFileFilter.kt
app/src/main/java/com/miya/fastcashier/log/LFileFilter.kt
+0
-4
LFilePicker.kt
app/src/main/java/com/miya/fastcashier/log/LFilePicker.kt
+1
-0
LFilePickerActivity.java
...in/java/com/miya/fastcashier/log/LFilePickerActivity.java
+6
-3
PathAdapter.java
app/src/main/java/com/miya/fastcashier/log/PathAdapter.java
+1
-0
ApiRequest.kt
app/src/main/java/com/miya/fastcashier/net/ApiRequest.kt
+100
-76
ApiService.kt
app/src/main/java/com/miya/fastcashier/net/ApiService.kt
+2
-6
MainActivity.kt
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
+1
-4
CustomImageCenterDialog.kt
...com/miya/fastcashier/ui/dialog/CustomImageCenterDialog.kt
+2
-2
SystemParameterDialog.kt
...a/com/miya/fastcashier/ui/dialog/SystemParameterDialog.kt
+1
-2
FileUtils.java
app/src/main/java/com/miya/fastcashier/utils/FileUtils.java
+4
-4
LoginViewModel.kt
...ain/java/com/miya/fastcashier/viewmodel/LoginViewModel.kt
+1
-1
EmptyRecyclerView.kt
...ain/java/com/miya/fastcashier/widget/EmptyRecyclerView.kt
+1
-1
activity_lfile_picker.xml
app/src/main/res/layout/activity_lfile_picker.xml
+1
-1
BaseApi.kt
...n/src/main/java/com/fastcashier/lib_common/net/BaseApi.kt
+14
-0
NetClient.kt
...src/main/java/com/fastcashier/lib_common/net/NetClient.kt
+69
-0
RequestSignInterceptor.kt
.../com/fastcashier/lib_common/net/RequestSignInterceptor.kt
+5
-10
LogFileUtils.kt
...main/java/com/fastcashier/lib_common/util/LogFileUtils.kt
+1
-1
No files found.
app/src/main/java/com/miya/fastcashier/MiyaApplication.kt
View file @
0b548e35
...
...
@@ -17,9 +17,9 @@ import com.fastcashier.lib_common.base.BaseApplication
import
com.fastcashier.lib_common.function.account.AccountService
import
com.fastcashier.lib_common.function.pay.OrderRecordManageKit
import
com.fastcashier.lib_common.util.DateUtils
import
com.fastcashier.lib_common.util.LogFileUtils
import
com.miya.fastcashier.utils.ContextUtils
import
com.miya.fastcashier.utils.DensityUtils
import
com.miya.fastcashier.utils.LogFileUtils
import
com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import
com.miya.print.PrinterManager
import
com.sdy.miya.moblie.component.pay.core.net.MiYaPayMobileApiClient
...
...
app/src/main/java/com/miya/fastcashier/log/FunctionCenterActivity.kt
View file @
0b548e35
...
...
@@ -3,9 +3,10 @@ package com.miya.fastcashier.log
import
android.content.Intent
import
android.os.Bundle
import
com.fastcashier.lib_common.base.BaseActivity
import
com.fastcashier.lib_common.util.LogFileUtils
import
com.fastcashier.lib_common.util.clickWithTrigger
import
com.miya.fastcashier.databinding.ActivityFunctionCenterBinding
import
com.miya.fastcashier.u
tils.LogFileUtils
import
com.miya.fastcashier.u
i.dialog.SystemParameterDialog
/**
* 功能中心
...
...
app/src/main/java/com/miya/fastcashier/log/LFileFilter.kt
View file @
0b548e35
...
...
@@ -3,10 +3,6 @@ package com.miya.fastcashier.log
import
java.io.File
import
java.io.FileFilter
/**
* 作者:Leon
* 时间:2017/3/24 13:43
*/
class
LFileFilter
(
private
val
mTypes
:
Array
<
String
>?)
:
FileFilter
{
override
fun
accept
(
file
:
File
):
Boolean
{
...
...
app/src/main/java/com/miya/fastcashier/log/LFilePicker.kt
View file @
0b548e35
...
...
@@ -12,6 +12,7 @@ import com.miya.fastcashier.R
* 时间:2017/3/20 16:57
*/
class
LFilePicker
{
private
var
mActivity
:
Activity
?
=
null
private
var
mFragment
:
Fragment
?
=
null
private
var
mTitle
:
String
?
=
null
...
...
app/src/main/java/com/miya/fastcashier/log/LFilePickerActivity.java
View file @
0b548e35
...
...
@@ -20,10 +20,13 @@ import com.fastcashier.lib_common.base.BaseActivity;
import
com.fastcashier.lib_common.function.account.AccountService
;
import
com.fastcashier.lib_common.function.account.SelfCashierTerminalConfig
;
import
com.fastcashier.lib_common.net.CommonCallback
;
import
com.fastcashier.lib_common.util.LogFileUtils
;
import
com.miya.fastcashier.R
;
import
com.miya.fastcashier.net.ApiRequest
;
import
com.miya.fastcashier.net.ApiService
;
import
com.miya.fastcashier.utils.LogFileUtils
;
import
com.miya.fastcashier.ui.dialog.CustomImageCenterDialog
;
import
com.miya.fastcashier.utils.FileUtils
;
import
com.miya.fastcashier.widget.EmptyRecyclerView
;
import
java.io.File
;
import
java.util.ArrayList
;
...
...
@@ -268,7 +271,7 @@ public class LFilePickerActivity extends BaseActivity {
File
file
=
new
File
(
path
);
RequestBody
requestBody
=
RequestBody
.
create
(
MediaType
.
parse
(
""
),
file
);
MultipartBody
.
Part
part
=
MultipartBody
.
Part
.
createFormData
(
"logFile"
,
file
.
getName
(),
requestBody
);
String
ip
=
ApiRequest
.
Companion
.
get
Instance
().
get
DataSourceIp
(
selfCashierTerminalConfig
,
equType
);
String
ip
=
ApiRequest
.
Companion
.
getDataSourceIp
(
selfCashierTerminalConfig
,
equType
);
if
(!
TextUtils
.
isEmpty
(
selfCashierTerminalConfig
.
getScoRuntimeConfig
().
getPlatformUrl
()))
{
ip
=
selfCashierTerminalConfig
.
getScoRuntimeConfig
().
getPlatformUrl
()
+
ApiService
.
Companion
.
getUPLOAD_LOG_FILE
();
...
...
@@ -276,7 +279,7 @@ public class LFilePickerActivity extends BaseActivity {
LogUtils
.
e
(
"ip = "
+
ip
);
tryGenQrCodeMsg
(
file
.
getName
());
ApiRequest
.
Companion
.
getInstance
().
uploadFile
(
ip
,
part
,
ApiRequest
.
Companion
.
uploadFile
(
ip
,
part
,
new
CommonCallback
<
String
>()
{
@Override
public
void
onSuccess
(
String
data
)
{
...
...
app/src/main/java/com/miya/fastcashier/log/PathAdapter.java
View file @
0b548e35
...
...
@@ -11,6 +11,7 @@ import android.widget.RelativeLayout;
import
android.widget.TextView
;
import
com.miya.fastcashier.R
;
import
com.miya.fastcashier.utils.FileUtils
;
import
java.io.File
;
import
java.io.FileFilter
;
...
...
app/src/main/java/com/miya/fastcashier/net/ApiRequest.kt
View file @
0b548e35
package
com.miya.fastcashier.net
import
android.text.TextUtils
import
android.util.Log
import
com.fastcashier.lib_common.base.BaseApplication
import
com.fastcashier.lib_common.function.account.SelfCashierAccountInfo
import
com.fastcashier.lib_common.function.account.SelfCashierTerminalConfig
import
com.fastcashier.lib_common.net.ApiConfig
import
com.fastcashier.lib_common.net.CommonCallback
import
com.fastcashier.lib_common.net.MiyaHttpLoggingInterceptor
import
com.fastcashier.lib_common.net.SSLCertificatesInit
import
com.fastcashier.lib_common.net.*
import
com.miya.fastcashier.net.param.LoginParams
import
com.miya.fastcashier.utils.LogFileUtils
import
okhttp3.MultipartBody
import
okhttp3.OkHttpClient
import
retrofit2.Retrofit
import
retrofit2.converter.gson.GsonConverterFactory
import
javax.net.ssl.SSLSocketFactory
import
javax.net.ssl.X509TrustManager
class
ApiRequest
private
constructor
()
{
class
ApiRequest
{
companion
object
{
private
var
apiService
:
ApiService
?
=
null
private
var
sInstance
:
ApiRequest
?
=
null
@Synchronized
fun
getInstance
():
ApiRequest
{
if
(
null
==
sInstance
)
{
sInstance
=
ApiRequest
()
}
return
sInstance
!!
// private var apiService: ApiService? = null
// private var sInstance: ApiRequest? = null
//
// @Synchronized
// fun getInstance(): ApiRequest {
// if (null == sInstance) {
// sInstance = ApiRequest()
// }
// return sInstance!!
// }
//
// private fun getApiService(): ApiService {
// if (null == apiService) {
// val httpLoggingInterceptor =
// MiyaHttpLoggingInterceptor {
// Log.e("####", it)
// if (!LogFileUtils.isProhibitWrite) {
// LogFileUtils.writeLog(BaseApplication.getApplication(),it)
// }
// }.apply { level = MiyaHttpLoggingInterceptor.Level.BODY }
//
//
// val socketFactory = arrayOfNulls<SSLSocketFactory>(1)
// val trustManager = arrayOfNulls<X509TrustManager>(1)
// SSLCertificatesInit.init(socketFactory, trustManager)
//
// val client = OkHttpClient.Builder()
// .addInterceptor(httpLoggingInterceptor)
// .addInterceptor(RequestSignInterceptor())
// .sslSocketFactory(socketFactory[0]!!, trustManager[0]!!)
// .build()
//
// val retrofit = Retrofit.Builder()
// .baseUrl(ApiConfig.baseUrl)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .build()
//
// apiService = retrofit.create(ApiService::class.java)
// }
//
// return apiService!!
// }
private
fun
getBusinessApi
():
ApiService
{
return
NetClient
.
getInstance
().
getApi
(
ApiService
::
class
.
java
)
}
private
fun
getApiService
():
ApiService
{
if
(
null
==
apiService
)
{
val
httpLoggingInterceptor
=
MiyaHttpLoggingInterceptor
{
Log
.
e
(
"####"
,
it
)
if
(!
LogFileUtils
.
isProhibitWrite
)
{
LogFileUtils
.
writeLog
(
BaseApplication
.
getApplication
(),
it
)
}
}.
apply
{
level
=
MiyaHttpLoggingInterceptor
.
Level
.
BODY
}
val
socketFactory
=
arrayOfNulls
<
SSLSocketFactory
>(
1
)
val
trustManager
=
arrayOfNulls
<
X509TrustManager
>(
1
)
SSLCertificatesInit
.
init
(
socketFactory
,
trustManager
)
fun
login
(
loginParams
:
LoginParams
,
commonCallback
:
CommonCallback
<
SelfCashierAccountInfo
>
)
{
getBusinessApi
().
login
(
loginParams
).
enqueue
(
commonCallback
)
}
val
client
=
OkHttpClient
.
Builder
()
.
addInterceptor
(
httpLoggingInterceptor
)
.
addInterceptor
(
RequestSignInterceptor
())
.
sslSocketFactory
(
socketFactory
[
0
]
!!
,
trustManager
[
0
]
!!
)
.
build
()
fun
uploadFile
(
url
:
String
,
part
:
MultipartBody
.
Part
,
commonCallback
:
CommonCallback
<
String
>
)
{
getBusinessApi
().
uploadFile
(
url
,
part
).
enqueue
(
commonCallback
)
}
val
retrofit
=
Retrofit
.
Builder
()
.
baseUrl
(
ApiConfig
.
baseUrl
)
.
client
(
client
)
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
build
()
fun
getDataSourceIp
(
selfCashierTerminalConfig
:
SelfCashierTerminalConfig
,
equType
:
String
):
String
?
{
apiService
=
retrofit
.
create
(
ApiService
::
class
.
java
)
if
(
selfCashierTerminalConfig
?.
scoRuntimeConfig
==
null
)
{
throw
RuntimeException
(
"DataSourceIpUtils SelfCashierTerminalConfig is null"
)
}
return
apiService
!!
val
path
=
"${ApiService.UPLOAD_LOG_FILE}?equType=$equType"
return
if
(
TextUtils
.
isEmpty
(
selfCashierTerminalConfig
.
scoRuntimeConfig
.
erpIp
))
(
ApiConfig
.
baseUrl
+
path
)
else
selfCashierTerminalConfig
.
scoRuntimeConfig
.
erpIp
+
path
}
}
fun
login
(
loginParams
:
LoginParams
,
commonCallback
:
CommonCallback
<
SelfCashierAccountInfo
>
)
{
getApiService
().
login
(
loginParams
).
enqueue
(
commonCallback
)
}
fun
uploadFile
(
url
:
String
,
part
:
MultipartBody
.
Part
,
commonCallback
:
CommonCallback
<
String
>
)
{
getApiService
().
uploadFile
(
url
,
part
).
enqueue
(
commonCallback
)
}
fun
getDataSourceIp
(
selfCashierTerminalConfig
:
SelfCashierTerminalConfig
,
equType
:
String
):
String
?
{
if
(
selfCashierTerminalConfig
?.
scoRuntimeConfig
==
null
)
{
throw
RuntimeException
(
"DataSourceIpUtils SelfCashierTerminalConfig is null"
)
}
val
path
=
"${ApiService.UPLOAD_LOG_FILE}?equType=$equType"
return
if
(
TextUtils
.
isEmpty
(
selfCashierTerminalConfig
.
scoRuntimeConfig
.
erpIp
))
(
ApiConfig
.
baseUrl
+
path
)
else
selfCashierTerminalConfig
.
scoRuntimeConfig
.
erpIp
+
path
}
// fun login(
// loginParams: LoginParams,
// commonCallback: CommonCallback<SelfCashierAccountInfo>
// ) {
// val apiService = ApiClient.getInstance().getApi(ApiService.javaClass) as ApiService
// apiService.login(loginParams).enqueue(commonCallback)
// }
//
// fun uploadFile(
// url: String,
// part: MultipartBody.Part,
// commonCallback: CommonCallback<String>
// ) {
// val apiService = ApiClient.getInstance().getApi(ApiService.javaClass) as ApiService
// apiService.uploadFile(url, part).enqueue(commonCallback)
// }
//
// fun getDataSourceIp(
// selfCashierTerminalConfig: SelfCashierTerminalConfig,
// equType: String
// ): String? {
//
// if (selfCashierTerminalConfig?.scoRuntimeConfig == null) {
// throw RuntimeException("DataSourceIpUtils SelfCashierTerminalConfig is null")
// }
//
// val path = "${ApiService.UPLOAD_LOG_FILE}?equType=$equType"
// return if (TextUtils.isEmpty(selfCashierTerminalConfig.scoRuntimeConfig.erpIp)) (ApiConfig.baseUrl + path)
// else selfCashierTerminalConfig.scoRuntimeConfig.erpIp + path
// }
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/net/ApiService.kt
View file @
0b548e35
...
...
@@ -2,6 +2,7 @@ package com.miya.fastcashier.net
import
com.fastcashier.lib_common.function.account.SelfCashierAccountInfo
import
com.fastcashier.lib_common.net.ApiConfig
import
com.fastcashier.lib_common.net.BaseApi
import
com.fastcashier.lib_common.net.BaseResponse
import
com.miya.fastcashier.net.param.LoginParams
import
okhttp3.MultipartBody
...
...
@@ -11,7 +12,7 @@ import retrofit2.http.*
/**
* 请求地址配置
*/
interface
ApiService
{
interface
ApiService
:
BaseApi
{
companion
object
{
...
...
@@ -24,11 +25,6 @@ interface ApiService {
* 上传日志文件
*/
var
UPLOAD_LOG_FILE
:
String
=
"verify/r-log/upload-log-file"
fun
wrapUrl
(
suffix
:
String
):
String
{
return
ApiConfig
.
baseUrl
.
plus
(
suffix
)
}
}
@POST
(
LOGIN
)
...
...
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
View file @
0b548e35
...
...
@@ -2,7 +2,6 @@ package com.miya.fastcashier.ui
import
android.content.Intent
import
android.os.Bundle
import
android.util.Log
import
android.view.Gravity
import
android.widget.Toast
import
androidx.appcompat.app.AppCompatActivity
...
...
@@ -15,9 +14,7 @@ import com.fastcashier.lib_common.function.print.PrintService
import
com.fastcashier.lib_common.ui.dialog.CommonDialog
import
com.fastcashier.lib_common.util.DateUtils
import
com.fastcashier.lib_common.util.clickWithTrigger
import
com.fastcashier.lib_common.util.getVersion
import
com.fastcashier.lib_common.util.getVersionName
import
com.miya.fastcashier.BuildConfig
import
com.miya.fastcashier.R
import
com.miya.fastcashier.databinding.ActivityMainBinding
import
com.miya.fastcashier.ui.dialog.AuthorizePasswordInputDialog
...
...
@@ -26,7 +23,7 @@ import com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import
com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import
com.miya.fastcashier.viewmodel.MainViewModel
import
com.sdy.miya.moblie.component.pay.core.utils.PayLogFileUtils
import
es.dmoral.toasty.Toasty
import
com.fastcashier.lib_common.util.LogFileUtils
import
java.util.*
class
MainActivity
:
BaseActivity
()
{
...
...
app/src/main/java/com/miya/fastcashier/log/CustomImageCenterDialog.kt
→
app/src/main/java/com/miya/fastcashier/
ui/dia
log/CustomImageCenterDialog.kt
View file @
0b548e35
package
com.miya.fastcashier.log
package
com.miya.fastcashier.
ui.dia
log
import
android.app.Dialog
import
android.content.Context
import
com.miya.fastcashier.R
import
android.widget.TextView
import
android.graphics.Bitmap
import
com.miya.fastcashier.log.CustomImageCenterDialog
import
android.os.Build
import
android.view.WindowManager
import
android.text.TextUtils
...
...
@@ -17,6 +16,7 @@ import android.view.Window
import
android.widget.ImageView
class
CustomImageCenterDialog
(
context
:
Context
)
:
Dialog
(
context
,
R
.
style
.
CommonDialog
)
{
private
var
tvOk
:
TextView
?
=
null
private
var
tvHint
:
TextView
?
=
null
private
var
ivContent
:
ImageView
?
=
null
...
...
app/src/main/java/com/miya/fastcashier/log/SystemParameterDialog.kt
→
app/src/main/java/com/miya/fastcashier/
ui/dia
log/SystemParameterDialog.kt
View file @
0b548e35
package
com.miya.fastcashier.log
package
com.miya.fastcashier.
ui.dia
log
import
android.app.Dialog
import
android.content.Context
...
...
@@ -15,7 +15,6 @@ import com.fastcashier.lib_common.util.getVersionCode
import
com.fastcashier.lib_common.util.getWifyName
import
com.miya.fastcashier.R
import
com.miya.fastcashier.databinding.DialogSystemParameterBinding
import
com.miya.fastcashier.utils.*
import
com.miya.print.PrinterManager
import
java.util.*
...
...
app/src/main/java/com/miya/fastcashier/
log
/FileUtils.java
→
app/src/main/java/com/miya/fastcashier/
utils
/FileUtils.java
View file @
0b548e35
package
com
.
miya
.
fastcashier
.
log
;
package
com
.
miya
.
fastcashier
.
utils
;
import
com.miya.fastcashier.log.FileComparator
;
import
java.io.File
;
import
java.io.FileFilter
;
...
...
@@ -8,10 +10,8 @@ import java.util.Collections;
import
java.util.Iterator
;
import
java.util.List
;
/**
* Created by Dimorinny on 24.10.15.
*/
public
class
FileUtils
{
public
static
List
<
File
>
getFileListByDirPath
(
String
path
,
FileFilter
filter
)
{
File
directory
=
new
File
(
path
);
File
[]
files
=
directory
.
listFiles
(
filter
);
...
...
app/src/main/java/com/miya/fastcashier/viewmodel/LoginViewModel.kt
View file @
0b548e35
...
...
@@ -23,7 +23,7 @@ class LoginViewModel : ViewModel() {
viewModelScope
.
launch
(
Dispatchers
.
IO
)
{
ApiRequest
.
getInstance
().
login
(
ApiRequest
.
login
(
LoginParams
(
userName
,
passWord
,
""
),
object
:
CommonCallback
<
SelfCashierAccountInfo
>(){
override
fun
onSuccess
(
data
:
SelfCashierAccountInfo
)
{
...
...
app/src/main/java/com/miya/fastcashier/
log
/EmptyRecyclerView.kt
→
app/src/main/java/com/miya/fastcashier/
widget
/EmptyRecyclerView.kt
View file @
0b548e35
package
com.miya.fastcashier.
log
package
com.miya.fastcashier.
widget
import
android.content.Context
import
android.util.AttributeSet
...
...
app/src/main/res/layout/activity_lfile_picker.xml
View file @
0b548e35
...
...
@@ -60,7 +60,7 @@
android:textColor=
"@color/lfile_white"
android:textSize=
"18sp"
/>
<com.miya.fastcashier.
log
.EmptyRecyclerView
<com.miya.fastcashier.
widget
.EmptyRecyclerView
android:id=
"@+id/recylerview"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
...
...
lib_common/src/main/java/com/fastcashier/lib_common/net/BaseApi.kt
0 → 100644
View file @
0b548e35
package
com.fastcashier.lib_common.net
/**
* 请求Api基础配置
*/
interface
BaseApi
{
companion
object
{
fun
wrapUrl
(
suffix
:
String
):
String
{
return
ApiConfig
.
baseUrl
.
plus
(
suffix
)
}
}
}
\ No newline at end of file
lib_common/src/main/java/com/fastcashier/lib_common/net/NetClient.kt
0 → 100644
View file @
0b548e35
package
com.fastcashier.lib_common.net
import
android.util.Log
import
com.fastcashier.lib_common.base.BaseApplication
import
com.fastcashier.lib_common.util.LogFileUtils
import
okhttp3.OkHttpClient
import
retrofit2.Retrofit
import
retrofit2.converter.gson.GsonConverterFactory
import
javax.net.ssl.SSLSocketFactory
import
javax.net.ssl.X509TrustManager
class
NetClient
private
constructor
()
{
companion
object
{
// private var apiService: BaseApi? = null
private
var
sInstance
:
NetClient
?
=
null
@Synchronized
fun
getInstance
():
NetClient
{
if
(
null
==
sInstance
)
{
sInstance
=
NetClient
()
}
return
sInstance
!!
}
}
private
fun
generateClient
():
Retrofit
{
val
httpLoggingInterceptor
=
MiyaHttpLoggingInterceptor
{
Log
.
e
(
"####"
,
it
)
if
(!
LogFileUtils
.
isProhibitWrite
)
{
LogFileUtils
.
writeLog
(
BaseApplication
.
getApplication
(),
it
)
}
}.
apply
{
level
=
MiyaHttpLoggingInterceptor
.
Level
.
BODY
}
val
socketFactory
=
arrayOfNulls
<
SSLSocketFactory
>(
1
)
val
trustManager
=
arrayOfNulls
<
X509TrustManager
>(
1
)
SSLCertificatesInit
.
init
(
socketFactory
,
trustManager
)
val
client
=
OkHttpClient
.
Builder
()
.
addInterceptor
(
httpLoggingInterceptor
)
.
addInterceptor
(
RequestSignInterceptor
())
.
sslSocketFactory
(
socketFactory
[
0
]
!!
,
trustManager
[
0
]
!!
)
.
build
()
val
retrofit
=
Retrofit
.
Builder
()
.
baseUrl
(
ApiConfig
.
baseUrl
)
.
client
(
client
)
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
build
()
return
retrofit
}
// fun <T> getApi(tClass: Class<T>?): T {
// if (null == apiService) {
// apiService = generateClient().create(tClass)
// }
//
// return apiService!!
// }
fun
<
T
>
getApi
(
tClass
:
Class
<
T
>?):
T
{
return
generateClient
().
create
(
tClass
)
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier
/net/RequestSignInterceptor.kt
→
lib_common/src/main/java/com/fastcashier/lib_common
/net/RequestSignInterceptor.kt
View file @
0b548e35
package
com.
miya.fastcashier
.net
package
com.
fastcashier.lib_common
.net
import
com.fastcashier.lib_common.function.account.AccountService.getAccountInfo
import
com.fastcashier.lib_common.net.ApiConfig.getAuthorization
import
com.miya.fastcashier.net.ApiService.Companion.wrapUrl
import
okhttp3.Interceptor
import
okhttp3.Request
import
okhttp3.Response
...
...
@@ -21,17 +20,13 @@ class RequestSignInterceptor : Interceptor {
@Throws
(
IOException
::
class
)
override
fun
intercept
(
chain
:
Interceptor
.
Chain
):
Response
{
val
original
:
Request
=
chain
.
request
()
val
requestUrl
=
original
.
url
.
toString
()
val
requestBuilder
:
Request
.
Builder
=
original
.
newBuilder
()
val
accountInfo
=
getAccountInfo
()
if
(
accountInfo
!=
null
&&
accountInfo
.
accessToken
!=
null
)
{
val
loginUrl
=
wrapUrl
(
ApiService
.
LOGIN
)
if
(
requestUrl
!=
loginUrl
)
{
requestBuilder
.
addHeader
(
AUTHORIZATION
,
getAuthorization
(
accountInfo
.
accessToken
.
accessToken
)
)
}
requestBuilder
.
addHeader
(
AUTHORIZATION
,
getAuthorization
(
accountInfo
.
accessToken
.
accessToken
)
)
}
val
request
:
Request
=
requestBuilder
.
build
()
return
chain
.
proceed
(
request
)
...
...
app/src/main/java/com/miya/fastcashier/utils
/LogFileUtils.kt
→
lib_common/src/main/java/com/fastcashier/lib_common/util
/LogFileUtils.kt
View file @
0b548e35
package
com.
miya.fastcashier.utils
package
com.
fastcashier.lib_common.util
import
android.content.Context
import
android.content.pm.PackageInfo
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment