Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
ShenghuoquanBusiness
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
ShenghuoquanBusiness
Commits
6db4e0c1
Commit
6db4e0c1
authored
Aug 13, 2021
by
yinjiacheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update 网络请求公共参数在C端通过客户端信息服务获取
parent
d9c3bc48
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
13 deletions
+90
-13
HttpParamsUtils.kt
.../src/main/java/com/yidian/bcommon/http/HttpParamsUtils.kt
+56
-10
ZapServiceActionConstants.kt
.../com/yidian/bcommon/services/ZapServiceActionConstants.kt
+4
-1
ClientInfoService.kt
...om/yidian/shenghuoquan/bdemo/service/ClientInfoService.kt
+30
-2
No files found.
CommonLib/BCommon/src/main/java/com/yidian/bcommon/http/HttpParamsUtils.kt
View file @
6db4e0c1
...
@@ -6,8 +6,14 @@ import com.yidian.bcommon.app.YdBaseApplication
...
@@ -6,8 +6,14 @@ import com.yidian.bcommon.app.YdBaseApplication
import
com.yidian.bcommon.constant.AppConfig
import
com.yidian.bcommon.constant.AppConfig
import
com.yidian.bcommon.constant.RunConfig
import
com.yidian.bcommon.constant.RunConfig
import
com.yidian.bcommon.sdk.BCommonManager
import
com.yidian.bcommon.sdk.BCommonManager
import
com.yidian.bcommon.sdk.ClientType
import
com.yidian.bcommon.sdk.JudgeClientUtils
import
com.yidian.bcommon.services.ZapServiceActionConstants
import
com.yidian.bcommon.services.ZapServiceNameConstants
import
com.yidian.bcommon.utils.NetWorkUtils
import
com.yidian.bcommon.utils.NetWorkUtils
import
com.yidian.yac.core.zap.ZapTicket
import
com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import
com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import
org.json.JSONObject
import
timber.log.Timber
import
timber.log.Timber
import
java.lang.reflect.Type
import
java.lang.reflect.Type
...
@@ -16,9 +22,15 @@ class HttpParamsUtils {
...
@@ -16,9 +22,15 @@ class HttpParamsUtils {
private
val
gson
by
lazy
{
Gson
()
}
private
val
gson
by
lazy
{
Gson
()
}
/**
* 获取公共参数
* C端通过服务获取
*/
fun
getPublicParamsMap
(
timeStamp
:
Long
):
HashMap
<
String
,
String
>
{
fun
getPublicParamsMap
(
timeStamp
:
Long
):
HashMap
<
String
,
String
>
{
val
paramsMap
=
hashMapOf
(
var
paramsMap
=
hashMapOf
<
String
,
String
>()
"appid"
to
BCommonManager
.
getAppId
(),
if
(
JudgeClientUtils
.
judgeClient
(
YdBaseApplication
.
context
.
packageName
)
==
ClientType
.
MERCHANT_B
)
{
paramsMap
=
hashMapOf
(
"appid"
to
AppConfig
.
appIdMerchantB
,
"cv"
to
AppConfig
.
cv
,
"cv"
to
AppConfig
.
cv
,
"version"
to
RunConfig
.
SERVICE_VERSION
,
"version"
to
RunConfig
.
SERVICE_VERSION
,
"distribution"
to
AppConfig
.
distribution
,
"distribution"
to
AppConfig
.
distribution
,
...
@@ -27,10 +39,30 @@ class HttpParamsUtils {
...
@@ -27,10 +39,30 @@ class HttpParamsUtils {
"device_finger"
to
getDeviceFinger
(),
"device_finger"
to
getDeviceFinger
(),
"reqid"
to
getRequestId
(
timeStamp
)
"reqid"
to
getRequestId
(
timeStamp
)
)
)
}
else
{
ZapTicket
(
ZapServiceNameConstants
.
ClientInfoService
).
withAction
(
ZapServiceActionConstants
.
ActionGetRequestPublicParameters
)
.
onResult
{
val
result
=
it
.
result
as
JSONObject
paramsMap
=
hashMapOf
(
"appid"
to
result
.
optString
(
"appid"
),
"cv"
to
result
.
optString
(
"cv"
),
"version"
to
result
.
optString
(
"version"
),
"distribution"
to
result
.
optString
(
"distribution"
),
"net"
to
result
.
optString
(
"net"
),
"platform"
to
result
.
optString
(
"platform"
),
"device_finger"
to
getDeviceFinger
(),
"reqid"
to
getRequestId
(
timeStamp
)
)
}.
ship
()
}
Timber
.
tag
(
BCommonManager
.
TAG_HTTP
).
d
(
"request public params: ${gson.toJson(paramsMap)}"
)
Timber
.
tag
(
BCommonManager
.
TAG_HTTP
).
d
(
"request public params: ${gson.toJson(paramsMap)}"
)
return
paramsMap
return
paramsMap
}
}
/**
* 获取业务参数
* C端增加user_id
*/
fun
getPrivateParamsMap
(
paramsMap
:
HashMap
<
String
,
String
?
>,
timeStamp
:
Long
):
HashMap
<
String
,
String
?
>
{
fun
getPrivateParamsMap
(
paramsMap
:
HashMap
<
String
,
String
?
>,
timeStamp
:
Long
):
HashMap
<
String
,
String
?
>
{
return
if
(
RunConfig
.
IS_ENCRYPT
)
{
return
if
(
RunConfig
.
IS_ENCRYPT
)
{
paramsMap
[
"secret"
]
=
getSignString
(
getRequestId
(
timeStamp
),
timeStamp
)
paramsMap
[
"secret"
]
=
getSignString
(
getRequestId
(
timeStamp
),
timeStamp
)
...
@@ -47,6 +79,9 @@ class HttpParamsUtils {
...
@@ -47,6 +79,9 @@ class HttpParamsUtils {
}
}
}
}
/**
* RSA解密Response
*/
fun
<
T
>
rsaDecryptResult
(
res
:
HttpResult
<
Any
?
>,
type
:
Type
):
HttpResult
<
T
>
{
fun
<
T
>
rsaDecryptResult
(
res
:
HttpResult
<
Any
?
>,
type
:
Type
):
HttpResult
<
T
>
{
val
rsaResult
=
res
.
result
val
rsaResult
=
res
.
result
val
decodeResult
=
HttpResult
<
T
>()
val
decodeResult
=
HttpResult
<
T
>()
...
@@ -82,15 +117,26 @@ class HttpParamsUtils {
...
@@ -82,15 +117,26 @@ class HttpParamsUtils {
return
decodeResult
return
decodeResult
}
}
/**
* 获取设备指纹
*/
private
fun
getDeviceFinger
():
String
{
private
fun
getDeviceFinger
():
String
{
return
FtDeviceFingerManager
.
getDeviceFinger
()
?:
""
return
FtDeviceFingerManager
.
getDeviceFinger
()
?:
""
}
}
/**
* 获取唯一请求标识
* 规则:appId + "_" + deviceFinger + "_" + timeStamp
*/
private
fun
getRequestId
(
timeStamp
:
Long
):
String
{
private
fun
getRequestId
(
timeStamp
:
Long
):
String
{
return
StringBuilder
().
append
(
BCommonManager
.
getAppId
()).
append
(
'_'
).
append
(
getDeviceFinger
()).
append
(
'_'
).
append
(
timeStamp
)
return
StringBuilder
().
append
(
BCommonManager
.
getAppId
()).
append
(
'_'
).
append
(
getDeviceFinger
()).
append
(
'_'
).
append
(
timeStamp
)
.
toString
()
.
toString
()
}
}
/**
* 获取签名串
* 规则: reqId + timeStamp
*/
private
fun
getSignString
(
reqId
:
String
,
timeStamp
:
Long
):
String
{
private
fun
getSignString
(
reqId
:
String
,
timeStamp
:
Long
):
String
{
return
BCommonManager
.
getEncryptIml
().
sign
(
StringBuilder
().
append
(
reqId
).
append
(
timeStamp
).
toString
())
return
BCommonManager
.
getEncryptIml
().
sign
(
StringBuilder
().
append
(
reqId
).
append
(
timeStamp
).
toString
())
}
}
...
...
CommonLib/BCommon/src/main/java/com/yidian/bcommon/services/ZapServiceActionConstants.kt
View file @
6db4e0c1
...
@@ -40,9 +40,12 @@ class ZapServiceActionConstants {
...
@@ -40,9 +40,12 @@ class ZapServiceActionConstants {
// AES解密
// AES解密
const
val
ActionAESDecrypt
=
"AESDecrypt"
const
val
ActionAESDecrypt
=
"AESDecrypt"
// 获取用户信息
// 获取
C端
用户信息
const
val
ActionGetUserInfo
=
"getUserInfo"
const
val
ActionGetUserInfo
=
"getUserInfo"
// 获取C端网络请求公共参数
const
val
ActionGetRequestPublicParameters
=
"getRequestPublicParameters"
// 延迟初始化
// 延迟初始化
const
val
ActionLazyInit
=
"lazyInit"
const
val
ActionLazyInit
=
"lazyInit"
...
...
Components/BDemo/src/main/java/com/yidian/shenghuoquan/bdemo/service/ClientInfoService.kt
View file @
6db4e0c1
...
@@ -3,6 +3,7 @@ package com.yidian.shenghuoquan.bdemo.service
...
@@ -3,6 +3,7 @@ package com.yidian.shenghuoquan.bdemo.service
import
com.yidian.bcommon.services.ZapServiceActionConstants
import
com.yidian.bcommon.services.ZapServiceActionConstants
import
com.yidian.xarc.xrouter.ResultResolver
import
com.yidian.xarc.xrouter.ResultResolver
import
com.yidian.yac.core.zap.ZapService
import
com.yidian.yac.core.zap.ZapService
import
com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import
org.json.JSONObject
import
org.json.JSONObject
/**
/**
...
@@ -15,8 +16,35 @@ class ClientInfoService : ZapService() {
...
@@ -15,8 +16,35 @@ class ClientInfoService : ZapService() {
override
fun
onAction
(
path
:
String
,
action
:
String
,
params
:
Any
,
options
:
Any
,
resolver
:
ResultResolver
)
{
override
fun
onAction
(
path
:
String
,
action
:
String
,
params
:
Any
,
options
:
Any
,
resolver
:
ResultResolver
)
{
when
(
action
)
{
when
(
action
)
{
ZapServiceActionConstants
.
ActionGetUserInfo
->
{
ZapServiceActionConstants
.
ActionGetUserInfo
->
{
// 获取C端userId 调试时可修改为开发者自己的userId
// 获取C端userId、userName、userPhone
resolver
.
success
(
JSONObject
().
put
(
"userId"
,
"510227073302"
).
put
(
"userName"
,
"yjc0314"
).
put
(
"userPhone"
,
"15054298387"
))
resolver
.
success
(
JSONObject
()
.
put
(
"userId"
,
"510227073302"
)
.
put
(
"userName"
,
"yjc0314"
)
.
put
(
"userPhone"
,
"15054298387"
)
)
}
// 获取C端网络请求公共参数
ZapServiceActionConstants
.
ActionGetRequestPublicParameters
->
{
resolver
.
success
(
JSONObject
()
.
put
(
"appid"
,
"merchant-c"
)
.
put
(
"cv"
,
"1.0.0"
)
.
put
(
"version"
,
"001000"
)
.
put
(
"distribution"
,
"official"
)
.
put
(
"net"
,
"wifi"
)
.
put
(
"platform"
,
"1"
)
.
put
(
"device_finger"
,
FtDeviceFingerManager
.
getDeviceFinger
())
.
put
(
"reqid"
,
StringBuilder
()
.
append
(
"merchant-c"
)
.
append
(
'_'
)
.
append
(
FtDeviceFingerManager
.
getDeviceFinger
())
.
append
(
'_'
)
.
append
(
System
.
currentTimeMillis
())
.
toString
()
)
)
}
}
}
}
}
}
...
...
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