Commit 0b548e35 authored by 赵鹏翔's avatar 赵鹏翔

网络框架配置优化

parent 02a1d96a
......@@ -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
......
......@@ -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.utils.LogFileUtils
import com.miya.fastcashier.ui.dialog.SystemParameterDialog
/**
* 功能中心
......
......@@ -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 {
......
......@@ -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
......
......@@ -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.getInstance().getDataSourceIp(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) {
......
......@@ -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;
......
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
......@@ -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)
......
......@@ -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() {
......
package com.miya.fastcashier.log
package com.miya.fastcashier.ui.dialog
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
......
package com.miya.fastcashier.log
package com.miya.fastcashier.ui.dialog
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.*
......
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);
......
......@@ -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) {
......
package com.miya.fastcashier.log
package com.miya.fastcashier.widget
import android.content.Context
import android.util.AttributeSet
......
......@@ -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"
......
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
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
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)
......
package com.miya.fastcashier.utils
package com.fastcashier.lib_common.util
import android.content.Context
import android.content.pm.PackageInfo
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment