Commit 2ae50809 authored by 赵鹏翔's avatar 赵鹏翔

完成日志上传,配置请求拦截签名,配置环境区分

parent e30804f8
...@@ -28,6 +28,7 @@ android { ...@@ -28,6 +28,7 @@ android {
multiDexEnabled true multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField 'String', "CHANNEL", "\"$CHANNEL\"" buildConfigField 'String', "CHANNEL", "\"$CHANNEL\""
buildConfigField "Boolean", "ISTEST", ISTEST.toString()
buildConfigField "String", "appType", "\"mpos\"" buildConfigField "String", "appType", "\"mpos\""
} }
......
...@@ -13,12 +13,18 @@ import android.widget.TextView; ...@@ -13,12 +13,18 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.blankj.utilcode.util.EncodeUtils; import com.blankj.utilcode.util.EncodeUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.StringUtils; import com.blankj.utilcode.util.StringUtils;
import com.miya.fastcashier.BuildConfig; import com.miya.fastcashier.BuildConfig;
import com.miya.fastcashier.R; import com.miya.fastcashier.R;
import com.miya.fastcashier.beans.SelfCashierTerminalConfig; import com.miya.fastcashier.beans.SelfCashierTerminalConfig;
import com.miya.fastcashier.net.ApiConfig;
import com.miya.fastcashier.net.ApiRequest;
import com.miya.fastcashier.net.ApiService;
import com.miya.fastcashier.net.CommonCallback;
import com.miya.fastcashier.service.AccountService; import com.miya.fastcashier.service.AccountService;
import com.miya.fastcashier.ui.BaseActivity; import com.miya.fastcashier.ui.BaseActivity;
import com.miya.fastcashier.utils.LogFileUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -27,6 +33,10 @@ import java.util.List; ...@@ -27,6 +33,10 @@ import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import es.dmoral.toasty.Toasty;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
public class LFilePickerActivity extends BaseActivity { public class LFilePickerActivity extends BaseActivity {
...@@ -254,50 +264,61 @@ public class LFilePickerActivity extends BaseActivity { ...@@ -254,50 +264,61 @@ public class LFilePickerActivity extends BaseActivity {
} }
public void uploadFile(String path) { public void uploadFile(String path) {
// LogFileUtils.INSTANCE.setProhibitWrite(true); LogFileUtils.INSTANCE.setProhibitWrite(true);
// String equType = getEquType(); String equType = getEquType();
//
// File file = new File(path); File file = new File(path);
// RequestBody requestBody = RequestBody.create(MediaType.parse(""), file); RequestBody requestBody = RequestBody.create(MediaType.parse(""), file);
// MultipartBody.Part part = MultipartBody.Part.createFormData("logFile", file.getName(), requestBody); MultipartBody.Part part = MultipartBody.Part.createFormData("logFile", file.getName(), requestBody);
// String ip = DataSourceIpUtils.getDataSourceIp(selfCashierTerminalConfig, NetWorkUrl.UPLOAD_LOG_FILE + "?equType=" + equType); String ip = getDataSourceIp(selfCashierTerminalConfig,
// if (!TextUtils.isEmpty(selfCashierTerminalConfig.getScoRuntimeConfig().getPlatformUrl())) { ApiService.Companion.getUPLOAD_LOG_FILE() + "?equType=" + equType);
// ip = selfCashierTerminalConfig.getScoRuntimeConfig().getPlatformUrl() + NetWorkUrl.UPLOAD_LOG_FILE; if (!TextUtils.isEmpty(selfCashierTerminalConfig.getScoRuntimeConfig().getPlatformUrl())) {
// } ip = selfCashierTerminalConfig.getScoRuntimeConfig().getPlatformUrl()
// + ApiService.Companion.getUPLOAD_LOG_FILE();
// LogUtils.e("ip = " + ip); }
//
// //防止文件过大 导致OOM 30M LogUtils.e("ip = " + ip);
//防止文件过大 导致OOM 30M
// long size = file.length(); // long size = file.length();
// if(size > 34307335){ // if (size > 34307335) {
// ToastUtils.showLong("日志文件过大"); // ToastUtils.showLong("日志文件过大");
// LogFileUtils.INSTANCE.setProhibitWrite(false); // LogFileUtils.INSTANCE.setProhibitWrite(false);
// hidProgressDialog(); // hidProgressDialog();
// return; // return;
// } // }
//
// tryGenQrCodeMsg(file.getName()); tryGenQrCodeMsg(file.getName());
//
// ApiClient.get().getFileApi().uploadFile(ip, part) ApiRequest.Companion.getInstance().uploadFile(ip, part,
// .subscribeOn(RxExecutorsUtils.getScheduler()) new CommonCallback<Object>() {
// .observeOn(AndroidSchedulers.mainThread()) @Override
// .subscribe(new Action1<HttpResult>() { public void onSuccess(Object data) {
// @Override hidProgressDialog();
// public void call(HttpResult s) { LogFileUtils.INSTANCE.setProhibitWrite(false);
// hidProgressDialog(); successToast = Toasty.success(LFilePickerActivity.this, "文件上传成功!");
// LogFileUtils.INSTANCE.setProhibitWrite(false); successToast.show();
// successToast = Toasty.success(LFilePickerActivity.this, "文件上传成功!"); showQrImageIfNeeded();
// successToast.show(); }
// showQrImageIfNeeded();
// } @Override
// }, new Action1<Throwable>() { public void onFailure(int errorType, String errorCode, String errorMessage) {
// @Override hidProgressDialog();
// public void call(Throwable throwable) { LogFileUtils.INSTANCE.setProhibitWrite(false);
// hidProgressDialog(); Toasty.error(LFilePickerActivity.this, "文件上传失败!").show();
// LogFileUtils.INSTANCE.setProhibitWrite(false); }
// Toasty.error(LFilePickerActivity.this, "文件上传失败!").show(); });
// } }
// });
public static String getDataSourceIp(@NonNull SelfCashierTerminalConfig selfCashierTerminalConfig, @NonNull String path) {
if (selfCashierTerminalConfig == null
|| selfCashierTerminalConfig.getScoRuntimeConfig() == null
) {
throw new RuntimeException("DataSourceIpUtils SelfCashierTerminalConfig is null");
}
return TextUtils.isEmpty(selfCashierTerminalConfig.getScoRuntimeConfig().getErpIp()) ?
ApiConfig.getBaseUrl() + path :
selfCashierTerminalConfig.getScoRuntimeConfig().getErpIp() + path;
} }
@NonNull @NonNull
...@@ -310,6 +331,7 @@ public class LFilePickerActivity extends BaseActivity { ...@@ -310,6 +331,7 @@ public class LFilePickerActivity extends BaseActivity {
//支付宝 //支付宝
equType = "ALIPAY_EQU"; equType = "ALIPAY_EQU";
} else if (BuildConfig.appType.equals("mpos")) { } else if (BuildConfig.appType.equals("mpos")) {
//mpos
equType = "MPOS_EQU"; equType = "MPOS_EQU";
} else if (BuildConfig.appType.equals("miya")) { } else if (BuildConfig.appType.equals("miya")) {
//强制进入米雅页面 //强制进入米雅页面
...@@ -324,7 +346,7 @@ public class LFilePickerActivity extends BaseActivity { ...@@ -324,7 +346,7 @@ public class LFilePickerActivity extends BaseActivity {
String hhMerchant = huihuaConfig.getHhMerchant(); String hhMerchant = huihuaConfig.getHhMerchant();
String storeId = huihuaConfig.getStoreId(); String storeId = huihuaConfig.getStoreId();
String username = AccountService.INSTANCE.getUserName(); String username = AccountService.INSTANCE.getUserName();
String qrMsg = String.format("%s/%s/%s/%s/%s", hhMerchant, storeId, username, getUploadEq(),fileName); String qrMsg = String.format("%s/%s/%s/%s/%s", hhMerchant, storeId, username, getUploadEq(), fileName);
mQrCodeEncodeMsg = EncodeUtils.base64Encode2String(qrMsg.getBytes()); mQrCodeEncodeMsg = EncodeUtils.base64Encode2String(qrMsg.getBytes());
} }
} }
...@@ -346,7 +368,7 @@ public class LFilePickerActivity extends BaseActivity { ...@@ -346,7 +368,7 @@ public class LFilePickerActivity extends BaseActivity {
private String getUploadEq() { private String getUploadEq() {
String eq = ""; String eq = "";
String equType = getEquType(); String equType = getEquType();
switch (equType){ switch (equType) {
case "WECHAT_EQU": case "WECHAT_EQU":
eq = "w_eq"; eq = "w_eq";
break; break;
......
...@@ -11,7 +11,7 @@ import com.miya.fastcashier.BuildConfig; ...@@ -11,7 +11,7 @@ import com.miya.fastcashier.BuildConfig;
import com.miya.fastcashier.R; import com.miya.fastcashier.R;
import com.miya.fastcashier.beans.SelfCashierAccountInfo; import com.miya.fastcashier.beans.SelfCashierAccountInfo;
import com.miya.fastcashier.databinding.DialogSystemParameterBinding; import com.miya.fastcashier.databinding.DialogSystemParameterBinding;
import com.miya.fastcashier.net.ApiRequest; import com.miya.fastcashier.net.ApiConfig;
import com.miya.fastcashier.service.AccountService; import com.miya.fastcashier.service.AccountService;
import com.miya.fastcashier.utils.BaseFunctionKt; import com.miya.fastcashier.utils.BaseFunctionKt;
import com.miya.print.PrinterManager; import com.miya.print.PrinterManager;
...@@ -44,7 +44,7 @@ public class SystemParameterDialog extends Dialog { ...@@ -44,7 +44,7 @@ public class SystemParameterDialog extends Dialog {
setInfo(viewBinding.tvCashier, accountInfo.getShopInfo().getOperatorId()); setInfo(viewBinding.tvCashier, accountInfo.getShopInfo().getOperatorId());
setInfo(viewBinding.tvVersionType, "fastCashier_" + BuildConfig.appType); setInfo(viewBinding.tvVersionType, "fastCashier_" + BuildConfig.appType);
setInfo(viewBinding.tvEquipment, "sunmi_v2pro"); setInfo(viewBinding.tvEquipment, "sunmi_v2pro");
setInfo(viewBinding.tvServerUrl, ApiRequest.Companion.getBaseUrl()); setInfo(viewBinding.tvServerUrl, ApiConfig.getBaseUrl());
setInfo(viewBinding.tvWifiName, BaseFunctionKt.getWifyName(getContext())); setInfo(viewBinding.tvWifiName, BaseFunctionKt.getWifyName(getContext()));
setInfo(viewBinding.tvNetIp, BaseFunctionKt.getNetIp(getContext()) == null ? "未知" : BaseFunctionKt.getNetIp(getContext())); setInfo(viewBinding.tvNetIp, BaseFunctionKt.getNetIp(getContext()) == null ? "未知" : BaseFunctionKt.getNetIp(getContext()));
setInfo(viewBinding.tvPrintType, PrinterManager.getInstance().getPrinter() == null ? setInfo(viewBinding.tvPrintType, PrinterManager.getInstance().getPrinter() == null ?
......
package com.miya.fastcashier.net
import com.miya.fastcashier.BuildConfig
import com.miya.fastcashier.net.ApiConfig
object ApiConfig {
private const val BASE_URL = "https://hhms.miyapay.com/"
private const val BASE_URL_4_TEST = ""
@JvmStatic
val baseUrl: String
get() = if (BuildConfig.ISTEST) {
BASE_URL_4_TEST
} else BASE_URL
}
\ No newline at end of file
...@@ -3,22 +3,16 @@ package com.miya.fastcashier.net ...@@ -3,22 +3,16 @@ package com.miya.fastcashier.net
import android.util.Log import android.util.Log
import com.miya.fastcashier.beans.SelfCashierAccountInfo import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.miya.fastcashier.beans.LoginRequest; import com.miya.fastcashier.beans.LoginRequest;
import com.miya.fastcashier.net.BaseResult import okhttp3.MultipartBody
import com.miya.fastcashier.net.MiyaHttpLoggingInterceptor
import com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Body
import retrofit2.http.POST
class ApiRequest private constructor() { class ApiRequest private constructor() {
companion object { companion object {
private const val BASE_URL = "https://hhms.miyapay.com/"
private var apiService: ApiService? = null private var apiService: ApiService? = null
private var sInstance: ApiRequest? = null private var sInstance: ApiRequest? = null
...@@ -39,10 +33,11 @@ class ApiRequest private constructor() { ...@@ -39,10 +33,11 @@ class ApiRequest private constructor() {
val client = OkHttpClient.Builder() val client = OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor) .addInterceptor(httpLoggingInterceptor)
.addInterceptor(RequestSignInterceptor())
.build() .build()
val retrofit = Retrofit.Builder() val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL) .baseUrl(ApiConfig.baseUrl)
.client(client) .client(client)
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build() .build()
...@@ -52,10 +47,6 @@ class ApiRequest private constructor() { ...@@ -52,10 +47,6 @@ class ApiRequest private constructor() {
return apiService!! return apiService!!
} }
fun getBaseUrl(): String {
return BASE_URL
}
} }
fun login( fun login(
...@@ -64,4 +55,12 @@ class ApiRequest private constructor() { ...@@ -64,4 +55,12 @@ class ApiRequest private constructor() {
) { ) {
getApiService().login(loginRequest).enqueue(commonCallback) getApiService().login(loginRequest).enqueue(commonCallback)
} }
fun uploadFile(
url: String,
part: MultipartBody.Part,
commonCallback: CommonCallback<Object>
) {
getApiService().uploadFile(url, part).enqueue(commonCallback)
}
} }
\ No newline at end of file
...@@ -2,9 +2,9 @@ package com.miya.fastcashier.net ...@@ -2,9 +2,9 @@ package com.miya.fastcashier.net
import com.miya.fastcashier.beans.LoginRequest import com.miya.fastcashier.beans.LoginRequest
import com.miya.fastcashier.beans.SelfCashierAccountInfo import com.miya.fastcashier.beans.SelfCashierAccountInfo
import okhttp3.MultipartBody
import retrofit2.Call import retrofit2.Call
import retrofit2.http.Body import retrofit2.http.*
import retrofit2.http.POST
interface ApiService { interface ApiService {
...@@ -12,9 +12,29 @@ interface ApiService { ...@@ -12,9 +12,29 @@ interface ApiService {
companion object { companion object {
const val LOGIN: String = "verify/auth/token" const val LOGIN: String = "verify/auth/token"
/**
* 上传日志文件
*/
var UPLOAD_LOG_FILE: String = "verify/r-log/upload-log-file"
fun wrapUrl(suffix: String): String {
return ApiConfig.baseUrl.plus(suffix)
}
} }
@POST(LOGIN) @POST(LOGIN)
fun login(@Body loginRequestCall: LoginRequest): Call<BaseResult<SelfCashierAccountInfo>> fun login(@Body loginRequestCall: LoginRequest): Call<BaseResponse<SelfCashierAccountInfo>>
/**
* 上传日志文件
*
* @param file
* @return
*/
@Multipart
@POST
fun uploadFile(@Url url: String?, @Part part: MultipartBody.Part): Call<BaseResponse<Object>>
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ package com.miya.fastcashier.net ...@@ -3,7 +3,7 @@ package com.miya.fastcashier.net
import java.io.Serializable import java.io.Serializable
data class BaseResult<T>(val code: String, val msg: String, val data: T) : Serializable { data class BaseResponse<T>(val code: String, val msg: String, val data: T) : Serializable {
fun isSuccess(): Boolean { fun isSuccess(): Boolean {
return code.equals("200") return code.equals("200")
......
...@@ -19,7 +19,7 @@ import retrofit2.Response; ...@@ -19,7 +19,7 @@ import retrofit2.Response;
* 修改人: * 修改人:
* 修改时间: * 修改时间:
*/ */
public abstract class CommonCallback<T> implements Callback<BaseResult<T>> { public abstract class CommonCallback<T> implements Callback<BaseResponse<T>> {
private static final String RESPONSE_MSG_UNKNOW = "未知异常"; private static final String RESPONSE_MSG_UNKNOW = "未知异常";
...@@ -38,7 +38,7 @@ public abstract class CommonCallback<T> implements Callback<BaseResult<T>> { ...@@ -38,7 +38,7 @@ public abstract class CommonCallback<T> implements Callback<BaseResult<T>> {
} }
@Override @Override
public void onResponse(Call<BaseResult<T>> call, Response<BaseResult<T>> response) { public void onResponse(Call<BaseResponse<T>> call, Response<BaseResponse<T>> response) {
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
String responseCode = response.body().getCode(); // 业务自定义Code String responseCode = response.body().getCode(); // 业务自定义Code
if (CALLBACK_SUCCEED_CODE.equals(responseCode)) { if (CALLBACK_SUCCEED_CODE.equals(responseCode)) {
...@@ -60,7 +60,7 @@ public abstract class CommonCallback<T> implements Callback<BaseResult<T>> { ...@@ -60,7 +60,7 @@ public abstract class CommonCallback<T> implements Callback<BaseResult<T>> {
} }
@Override @Override
public void onFailure(Call<BaseResult<T>> call, Throwable t) { public void onFailure(Call<BaseResponse<T>> call, Throwable t) {
String temp = t.getMessage(); String temp = t.getMessage();
Log.e("#### HttpLog", "请求失败:" + temp); Log.e("#### HttpLog", "请求失败:" + temp);
String errorMessage; String errorMessage;
......
package com.miya.fastcashier.net;
import com.miya.fastcashier.beans.SelfCashierAccountInfo;
import com.miya.fastcashier.service.AccountService;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
/**
* 签名拦截器
* 添加请求头校验 AUTHORIZATION
*/
public class RequestSignInterceptor implements Interceptor {
private static final String AUTHORIZATION = "Authorization";
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
String requestUrl = original.url().toString();
Request.Builder requestBuilder = original.newBuilder();
SelfCashierAccountInfo accountInfo = AccountService.INSTANCE.getAccountInfo();
if (accountInfo != null && accountInfo.getAccessToken() != null) {
String loginUrl = ApiService.Companion.wrapUrl(ApiService.LOGIN);
if (!requestUrl.equals(loginUrl)) {
requestBuilder.addHeader(AUTHORIZATION, "bearer " + accountInfo.getAccessToken().getAccessToken());
}
}
Request request = requestBuilder.build();
return chain.proceed(request);
}
}
...@@ -22,4 +22,6 @@ android.jetifier.blacklist=miya-print ...@@ -22,4 +22,6 @@ android.jetifier.blacklist=miya-print
android.useDeprecatedNdk=true android.useDeprecatedNdk=true
#区别品牌 #区别品牌
CHANNEL=converse CHANNEL=converse
\ No newline at end of file #区别环境 true:是测试环境,仅供内部人员测试使用;false:非测试包,供外部人员、渠道推广、应用商店等使用
ISTEST=false
\ No newline at end of file
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