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
2ae50809
Commit
2ae50809
authored
May 12, 2022
by
赵鹏翔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成日志上传,配置请求拦截签名,配置环境区分
parent
e30804f8
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
158 additions
and
62 deletions
+158
-62
build.gradle
app/build.gradle
+1
-0
LFilePickerActivity.java
...in/java/com/miya/fastcashier/log/LFilePickerActivity.java
+62
-40
SystemParameterDialog.java
.../java/com/miya/fastcashier/log/SystemParameterDialog.java
+2
-2
ApiConfig.kt
app/src/main/java/com/miya/fastcashier/net/ApiConfig.kt
+15
-0
ApiRequest.kt
app/src/main/java/com/miya/fastcashier/net/ApiRequest.kt
+11
-12
ApiService.kt
app/src/main/java/com/miya/fastcashier/net/ApiService.kt
+23
-3
BaseResponse.kt
app/src/main/java/com/miya/fastcashier/net/BaseResponse.kt
+1
-1
CommonCallback.java
...rc/main/java/com/miya/fastcashier/net/CommonCallback.java
+3
-3
RequestSignInterceptor.java
...java/com/miya/fastcashier/net/RequestSignInterceptor.java
+37
-0
gradle.properties
gradle.properties
+3
-1
No files found.
app/build.gradle
View file @
2ae50809
...
...
@@ -28,6 +28,7 @@ android {
multiDexEnabled
true
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
buildConfigField
'String'
,
"CHANNEL"
,
"\"$CHANNEL\""
buildConfigField
"Boolean"
,
"ISTEST"
,
ISTEST
.
toString
()
buildConfigField
"String"
,
"appType"
,
"\"mpos\""
}
...
...
app/src/main/java/com/miya/fastcashier/log/LFilePickerActivity.java
View file @
2ae50809
...
...
@@ -13,12 +13,18 @@ import android.widget.TextView;
import
android.widget.Toast
;
import
com.blankj.utilcode.util.EncodeUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.StringUtils
;
import
com.miya.fastcashier.BuildConfig
;
import
com.miya.fastcashier.R
;
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.ui.BaseActivity
;
import
com.miya.fastcashier.utils.LogFileUtils
;
import
java.io.File
;
import
java.util.ArrayList
;
...
...
@@ -27,6 +33,10 @@ import java.util.List;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.recyclerview.widget.LinearLayoutManager
;
import
es.dmoral.toasty.Toasty
;
import
okhttp3.MediaType
;
import
okhttp3.MultipartBody
;
import
okhttp3.RequestBody
;
public
class
LFilePickerActivity
extends
BaseActivity
{
...
...
@@ -254,50 +264,61 @@ public class LFilePickerActivity extends BaseActivity {
}
public
void
uploadFile
(
String
path
)
{
// LogFileUtils.INSTANCE.setProhibitWrite(true);
// String equType = getEquType();
//
// File file = new File(path);
// RequestBody requestBody = RequestBody.create(MediaType.parse(""), file);
// MultipartBody.Part part = MultipartBody.Part.createFormData("logFile", file.getName(), requestBody);
// String ip = DataSourceIpUtils.getDataSourceIp(selfCashierTerminalConfig, NetWorkUrl.UPLOAD_LOG_FILE + "?equType=" + equType);
// if (!TextUtils.isEmpty(selfCashierTerminalConfig.getScoRuntimeConfig().getPlatformUrl())) {
// ip = selfCashierTerminalConfig.getScoRuntimeConfig().getPlatformUrl() + NetWorkUrl.UPLOAD_LOG_FILE;
// }
//
// LogUtils.e("ip = " + ip);
//
// //防止文件过大 导致OOM 30M
LogFileUtils
.
INSTANCE
.
setProhibitWrite
(
true
);
String
equType
=
getEquType
();
File
file
=
new
File
(
path
);
RequestBody
requestBody
=
RequestBody
.
create
(
MediaType
.
parse
(
""
),
file
);
MultipartBody
.
Part
part
=
MultipartBody
.
Part
.
createFormData
(
"logFile"
,
file
.
getName
(),
requestBody
);
String
ip
=
getDataSourceIp
(
selfCashierTerminalConfig
,
ApiService
.
Companion
.
getUPLOAD_LOG_FILE
()
+
"?equType="
+
equType
);
if
(!
TextUtils
.
isEmpty
(
selfCashierTerminalConfig
.
getScoRuntimeConfig
().
getPlatformUrl
()))
{
ip
=
selfCashierTerminalConfig
.
getScoRuntimeConfig
().
getPlatformUrl
()
+
ApiService
.
Companion
.
getUPLOAD_LOG_FILE
();
}
LogUtils
.
e
(
"ip = "
+
ip
);
//防止文件过大 导致OOM 30M
// long size = file.length();
// if
(size > 34307335)
{
// if
(size > 34307335)
{
// ToastUtils.showLong("日志文件过大");
// LogFileUtils.INSTANCE.setProhibitWrite(false);
// hidProgressDialog();
// return;
// }
//
// tryGenQrCodeMsg(file.getName());
//
// ApiClient.get().getFileApi().uploadFile(ip, part)
// .subscribeOn(RxExecutorsUtils.getScheduler())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new Action1<HttpResult>() {
// @Override
// public void call(HttpResult s) {
// hidProgressDialog();
// LogFileUtils.INSTANCE.setProhibitWrite(false);
// successToast = Toasty.success(LFilePickerActivity.this, "文件上传成功!");
// successToast.show();
// showQrImageIfNeeded();
// }
// }, new Action1<Throwable>() {
// @Override
// public void call(Throwable throwable) {
// hidProgressDialog();
// LogFileUtils.INSTANCE.setProhibitWrite(false);
// Toasty.error(LFilePickerActivity.this, "文件上传失败!").show();
// }
// });
tryGenQrCodeMsg
(
file
.
getName
());
ApiRequest
.
Companion
.
getInstance
().
uploadFile
(
ip
,
part
,
new
CommonCallback
<
Object
>()
{
@Override
public
void
onSuccess
(
Object
data
)
{
hidProgressDialog
();
LogFileUtils
.
INSTANCE
.
setProhibitWrite
(
false
);
successToast
=
Toasty
.
success
(
LFilePickerActivity
.
this
,
"文件上传成功!"
);
successToast
.
show
();
showQrImageIfNeeded
();
}
@Override
public
void
onFailure
(
int
errorType
,
String
errorCode
,
String
errorMessage
)
{
hidProgressDialog
();
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
...
...
@@ -310,6 +331,7 @@ public class LFilePickerActivity extends BaseActivity {
//支付宝
equType
=
"ALIPAY_EQU"
;
}
else
if
(
BuildConfig
.
appType
.
equals
(
"mpos"
))
{
//mpos
equType
=
"MPOS_EQU"
;
}
else
if
(
BuildConfig
.
appType
.
equals
(
"miya"
))
{
//强制进入米雅页面
...
...
@@ -324,7 +346,7 @@ public class LFilePickerActivity extends BaseActivity {
String
hhMerchant
=
huihuaConfig
.
getHhMerchant
();
String
storeId
=
huihuaConfig
.
getStoreId
();
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
());
}
}
...
...
@@ -346,7 +368,7 @@ public class LFilePickerActivity extends BaseActivity {
private
String
getUploadEq
()
{
String
eq
=
""
;
String
equType
=
getEquType
();
switch
(
equType
){
switch
(
equType
)
{
case
"WECHAT_EQU"
:
eq
=
"w_eq"
;
break
;
...
...
app/src/main/java/com/miya/fastcashier/log/SystemParameterDialog.java
View file @
2ae50809
...
...
@@ -11,7 +11,7 @@ import com.miya.fastcashier.BuildConfig;
import
com.miya.fastcashier.R
;
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
;
import
com.miya.fastcashier.databinding.DialogSystemParameterBinding
;
import
com.miya.fastcashier.net.Api
Request
;
import
com.miya.fastcashier.net.Api
Config
;
import
com.miya.fastcashier.service.AccountService
;
import
com.miya.fastcashier.utils.BaseFunctionKt
;
import
com.miya.print.PrinterManager
;
...
...
@@ -44,7 +44,7 @@ public class SystemParameterDialog extends Dialog {
setInfo
(
viewBinding
.
tvCashier
,
accountInfo
.
getShopInfo
().
getOperatorId
());
setInfo
(
viewBinding
.
tvVersionType
,
"fastCashier_"
+
BuildConfig
.
appType
);
setInfo
(
viewBinding
.
tvEquipment
,
"sunmi_v2pro"
);
setInfo
(
viewBinding
.
tvServerUrl
,
Api
Request
.
Companion
.
getBaseUrl
());
setInfo
(
viewBinding
.
tvServerUrl
,
Api
Config
.
getBaseUrl
());
setInfo
(
viewBinding
.
tvWifiName
,
BaseFunctionKt
.
getWifyName
(
getContext
()));
setInfo
(
viewBinding
.
tvNetIp
,
BaseFunctionKt
.
getNetIp
(
getContext
())
==
null
?
"未知"
:
BaseFunctionKt
.
getNetIp
(
getContext
()));
setInfo
(
viewBinding
.
tvPrintType
,
PrinterManager
.
getInstance
().
getPrinter
()
==
null
?
...
...
app/src/main/java/com/miya/fastcashier/net/ApiConfig.kt
0 → 100644
View file @
2ae50809
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
app/src/main/java/com/miya/fastcashier/net/ApiRequest.kt
View file @
2ae50809
...
...
@@ -3,22 +3,16 @@ package com.miya.fastcashier.net
import
android.util.Log
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
import
com.miya.fastcashier.beans.LoginRequest;
import
com.miya.fastcashier.net.BaseResult
import
com.miya.fastcashier.net.MiyaHttpLoggingInterceptor
import
com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import
okhttp3.MultipartBody
import
okhttp3.OkHttpClient
import
okhttp3.logging.HttpLoggingInterceptor
import
retrofit2.Retrofit
import
retrofit2.converter.gson.GsonConverterFactory
import
retrofit2.http.Body
import
retrofit2.http.POST
class
ApiRequest
private
constructor
()
{
companion
object
{
private
const
val
BASE_URL
=
"https://hhms.miyapay.com/"
private
var
apiService
:
ApiService
?
=
null
private
var
sInstance
:
ApiRequest
?
=
null
...
...
@@ -39,10 +33,11 @@ class ApiRequest private constructor() {
val
client
=
OkHttpClient
.
Builder
()
.
addInterceptor
(
httpLoggingInterceptor
)
.
addInterceptor
(
RequestSignInterceptor
())
.
build
()
val
retrofit
=
Retrofit
.
Builder
()
.
baseUrl
(
BASE_URL
)
.
baseUrl
(
ApiConfig
.
baseUrl
)
.
client
(
client
)
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
build
()
...
...
@@ -52,10 +47,6 @@ class ApiRequest private constructor() {
return
apiService
!!
}
fun
getBaseUrl
():
String
{
return
BASE_URL
}
}
fun
login
(
...
...
@@ -64,4 +55,12 @@ class ApiRequest private constructor() {
)
{
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
app/src/main/java/com/miya/fastcashier/net/ApiService.kt
View file @
2ae50809
...
...
@@ -2,9 +2,9 @@ package com.miya.fastcashier.net
import
com.miya.fastcashier.beans.LoginRequest
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
import
okhttp3.MultipartBody
import
retrofit2.Call
import
retrofit2.http.Body
import
retrofit2.http.POST
import
retrofit2.http.*
interface
ApiService
{
...
...
@@ -12,9 +12,29 @@ interface ApiService {
companion
object
{
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
)
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
app/src/main/java/com/miya/fastcashier/net/BaseRes
ult
.kt
→
app/src/main/java/com/miya/fastcashier/net/BaseRes
ponse
.kt
View file @
2ae50809
...
...
@@ -3,7 +3,7 @@ package com.miya.fastcashier.net
import
java.io.Serializable
data class
BaseRes
ult
<
T
>(
val
code
:
String
,
val
msg
:
String
,
val
data
:
T
)
:
Serializable
{
data class
BaseRes
ponse
<
T
>(
val
code
:
String
,
val
msg
:
String
,
val
data
:
T
)
:
Serializable
{
fun
isSuccess
():
Boolean
{
return
code
.
equals
(
"200"
)
...
...
app/src/main/java/com/miya/fastcashier/net/CommonCallback.java
View file @
2ae50809
...
...
@@ -19,7 +19,7 @@ import retrofit2.Response;
* 修改人:
* 修改时间:
*/
public
abstract
class
CommonCallback
<
T
>
implements
Callback
<
BaseRes
ult
<
T
>>
{
public
abstract
class
CommonCallback
<
T
>
implements
Callback
<
BaseRes
ponse
<
T
>>
{
private
static
final
String
RESPONSE_MSG_UNKNOW
=
"未知异常"
;
...
...
@@ -38,7 +38,7 @@ public abstract class CommonCallback<T> implements Callback<BaseResult<T>> {
}
@Override
public
void
onResponse
(
Call
<
BaseRes
ult
<
T
>>
call
,
Response
<
BaseResult
<
T
>>
response
)
{
public
void
onResponse
(
Call
<
BaseRes
ponse
<
T
>>
call
,
Response
<
BaseResponse
<
T
>>
response
)
{
if
(
response
.
isSuccessful
()
&&
response
.
body
()
!=
null
)
{
String
responseCode
=
response
.
body
().
getCode
();
// 业务自定义Code
if
(
CALLBACK_SUCCEED_CODE
.
equals
(
responseCode
))
{
...
...
@@ -60,7 +60,7 @@ public abstract class CommonCallback<T> implements Callback<BaseResult<T>> {
}
@Override
public
void
onFailure
(
Call
<
BaseRes
ult
<
T
>>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
BaseRes
ponse
<
T
>>
call
,
Throwable
t
)
{
String
temp
=
t
.
getMessage
();
Log
.
e
(
"#### HttpLog"
,
"请求失败:"
+
temp
);
String
errorMessage
;
...
...
app/src/main/java/com/miya/fastcashier/net/RequestSignInterceptor.java
0 → 100644
View file @
2ae50809
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
);
}
}
gradle.properties
View file @
2ae50809
...
...
@@ -23,3 +23,5 @@ android.useDeprecatedNdk=true
#区别品牌
CHANNEL
=
converse
#区别环境 true:是测试环境,仅供内部人员测试使用;false:非测试包,供外部人员、渠道推广、应用商店等使用
ISTEST
=
false
\ No newline at end of file
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