Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
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
杨凯
YDL-Component-Medical
Commits
32044cb7
Commit
32044cb7
authored
Nov 26, 2019
by
konghaorui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充接口验签逻辑
parent
d2181d81
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
207 additions
and
42 deletions
+207
-42
MainActivity.kt
app/src/main/java/com/ydl/component/MainActivity.kt
+1
-2
config.gradle
config.gradle
+1
-1
OkHttpConfig.java
ydl-net/src/main/java/com/ydl/ydlnet/builder/config/OkHttpConfig.java
+15
-7
RequestHandler.java
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestHandler.java
+30
-0
RequestLogInterceptor.java
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
+35
-17
build.gradle
ydl-platform/build.gradle
+2
-1
GlobalConfig.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/base/config/GlobalConfig.kt
+1
-0
HttpConfig.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/base/config/HttpConfig.kt
+77
-9
AuthBean.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/bean/AuthBean.kt
+20
-0
ApiRequestUtil.java
ydl-platform/src/main/java/com/ydl/ydlcommon/data/http/api/ApiRequestUtil.java
+12
-2
NetApiStore.java
ydl-platform/src/main/java/com/ydl/ydlcommon/data/http/api/NetApiStore.java
+13
-3
No files found.
app/src/main/java/com/ydl/component/MainActivity.kt
View file @
32044cb7
...
...
@@ -13,7 +13,6 @@ import android.util.Log
import
com.alibaba.android.arouter.launcher.ARouter
import
com.tbruyelle.rxpermissions2.RxPermissions
import
com.umeng.analytics.MobclickAgent
import
com.umeng.commonsdk.framework.UMModuleRegister.getAppContext
import
com.ydl.audioim.YDLavManager
import
com.ydl.component.music.MusicPlayActivity
import
com.ydl.component.mvp.DemoContract
...
...
@@ -137,7 +136,7 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
override
fun
reLoadData
()
{
mPresenter
?.
loadUsers
()
mPresenter
.
loadHome
()
}
...
...
config.gradle
View file @
32044cb7
ext
{
kotlin_version
=
"1.3.21"
dev_mode
=
fals
e
dev_mode
=
tru
e
ydl_app
=
[
appName
:
"心理咨询壹点灵"
,
...
...
ydl-net/src/main/java/com/ydl/ydlnet/builder/config/OkHttpConfig.java
View file @
32044cb7
...
...
@@ -2,6 +2,7 @@ package com.ydl.ydlnet.builder.config;
import
android.content.Context
;
import
android.text.TextUtils
;
import
com.ydl.ydlnet.builder.cookie.CookieJarImpl
;
import
com.ydl.ydlnet.builder.cookie.store.CookieStore
;
import
com.ydl.ydlnet.builder.factory.ApiFactory
;
...
...
@@ -9,19 +10,22 @@ import com.ydl.ydlnet.builder.http.SSLUtils;
import
com.ydl.ydlnet.builder.interceptor.HeaderInterceptor
;
import
com.ydl.ydlnet.builder.interceptor.NetCacheInterceptor
;
import
com.ydl.ydlnet.builder.interceptor.NoNetCacheInterceptor
;
import
com.ydl.ydlnet.builder.interceptor.log.RequestHandler
;
import
com.ydl.ydlnet.builder.interceptor.log.RequestLogInterceptor
;
import
com.ydl.ydlnet.builder.manage.HttpUrlManager
;
import
com.ydl.ydlnet.client.interfaces.BuildHeadersListener
;
import
okhttp3.Cache
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
import
javax.net.ssl.HostnameVerifier
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
javax.net.ssl.HostnameVerifier
;
import
okhttp3.Cache
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
/**
* Created by haorui on 2019-09-02 .
* Des: 统一OkHttp配置信息
...
...
@@ -80,6 +84,7 @@ public class OkHttpConfig {
private
InputStream
bksFile
;
private
String
password
;
private
InputStream
[]
certificates
;
private
RequestHandler
requestHandler
;
private
Interceptor
[]
interceptors
;
private
Interceptor
[]
netInterceptors
;
private
BuildHeadersListener
buildHeadersListener
;
...
...
@@ -99,6 +104,11 @@ public class OkHttpConfig {
return
this
;
}
public
Builder
setRequestHandler
(
RequestHandler
requestHandler
)
{
this
.
requestHandler
=
requestHandler
;
return
this
;
}
public
Builder
setCache
(
boolean
isCache
)
{
this
.
isCache
=
isCache
;
return
this
;
...
...
@@ -210,9 +220,7 @@ public class OkHttpConfig {
* 配置开发环境
*/
private
void
setDebugConfig
()
{
if
(
isDebug
)
{
okHttpClientBuilder
.
addInterceptor
(
new
RequestLogInterceptor
());
}
okHttpClientBuilder
.
addInterceptor
(
new
RequestLogInterceptor
(
isDebug
,
requestHandler
));
}
...
...
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestHandler.java
0 → 100644
View file @
32044cb7
package
com
.
ydl
.
ydlnet
.
builder
.
interceptor
.
log
;
import
okhttp3.Interceptor
;
import
okhttp3.Request
;
import
okhttp3.Response
;
/**
* Created by haorui on 2019-11-26 .
* Des:
*/
public
interface
RequestHandler
{
Response
onHttpResultResponse
(
String
httpResult
,
Interceptor
.
Chain
chain
,
Response
response
);
Request
onHttpRequestBefore
(
Interceptor
.
Chain
chain
,
Request
request
);
RequestHandler
EMPTY
=
new
RequestHandler
()
{
@Override
public
Response
onHttpResultResponse
(
String
httpResult
,
Interceptor
.
Chain
chain
,
Response
response
)
{
//不管是否处理,都必须将response返回出去
return
response
;
}
@Override
public
Request
onHttpRequestBefore
(
Interceptor
.
Chain
chain
,
Request
request
)
{
//不管是否处理,都必须将request返回出去
return
request
;
}
};
}
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
View file @
32044cb7
package
com
.
ydl
.
ydlnet
.
builder
.
interceptor
.
log
;
import
android.support.annotation.Nullable
;
import
com.ydl.ydlnet.utils.CharacterHandler
;
import
com.ydl.ydlnet.utils.NetLogUtils
;
import
com.ydl.ydlnet.utils.UrlEncoderUtils
;
import
com.ydl.ydlnet.utils.ZipHelper
;
import
okhttp3.*
;
import
okio.Buffer
;
import
okio.BufferedSource
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
...
...
@@ -15,14 +13,27 @@ import java.net.URLDecoder;
import
java.nio.charset.Charset
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
okhttp3.Interceptor
;
import
okhttp3.MediaType
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
import
okhttp3.ResponseBody
;
import
okio.Buffer
;
import
okio.BufferedSource
;
/**
* Created by haorui on 2019-09-01 .
* Des: 解析框架中的网络请求和响应结果并打印
*/
public
class
RequestLogInterceptor
implements
Interceptor
{
private
DefaultFormatPrinter
mPrinter
=
new
DefaultFormatPrinter
();
private
boolean
mIsDebug
;
private
RequestHandler
mRequestHandler
;
public
RequestLogInterceptor
()
{
public
RequestLogInterceptor
(
boolean
isDebug
,
RequestHandler
requestHandler
)
{
this
.
mIsDebug
=
isDebug
;
this
.
mRequestHandler
=
requestHandler
;
}
@Override
...
...
@@ -36,6 +47,8 @@ public class RequestLogInterceptor implements Interceptor {
mPrinter
.
printFileRequest
(
request
);
}
if
(
mRequestHandler
!=
null
)
request
=
mRequestHandler
.
onHttpRequestBefore
(
chain
,
request
);
long
t1
=
System
.
nanoTime
()
;
Response
originalResponse
;
...
...
@@ -55,19 +68,24 @@ public class RequestLogInterceptor implements Interceptor {
bodyString
=
printResult
(
request
,
originalResponse
);
}
final
List
<
String
>
segmentList
=
request
.
url
().
encodedPathSegments
();
final
String
header
=
originalResponse
.
headers
().
toString
();
final
int
code
=
originalResponse
.
code
();
final
boolean
isSuccessful
=
originalResponse
.
isSuccessful
();
final
String
message
=
originalResponse
.
message
();
final
String
url
=
originalResponse
.
request
().
url
().
toString
();
if
(
responseBody
!=
null
&&
isParseable
(
responseBody
.
contentType
()))
{
mPrinter
.
printJsonResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
responseBody
.
contentType
(),
bodyString
,
segmentList
,
message
,
url
);
}
else
{
mPrinter
.
printFileResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
segmentList
,
message
,
url
);
if
(
mRequestHandler
!=
null
)
mRequestHandler
.
onHttpResultResponse
(
bodyString
,
chain
,
originalResponse
);
if
(
mIsDebug
)
{
final
List
<
String
>
segmentList
=
request
.
url
().
encodedPathSegments
();
final
String
header
=
originalResponse
.
headers
().
toString
();
final
int
code
=
originalResponse
.
code
();
final
boolean
isSuccessful
=
originalResponse
.
isSuccessful
();
final
String
message
=
originalResponse
.
message
();
final
String
url
=
originalResponse
.
request
().
url
().
toString
();
if
(
responseBody
!=
null
&&
isParseable
(
responseBody
.
contentType
()))
{
mPrinter
.
printJsonResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
responseBody
.
contentType
(),
bodyString
,
segmentList
,
message
,
url
);
}
else
{
mPrinter
.
printFileResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
segmentList
,
message
,
url
);
}
}
return
originalResponse
;
...
...
ydl-platform/build.gradle
View file @
32044cb7
...
...
@@ -83,7 +83,8 @@ dependencies {
api
rootProject
.
ext
.
dependencies
[
"ydl-utils"
]
api
rootProject
.
ext
.
dependencies
[
"ydl-js"
]
api
rootProject
.
ext
.
dependencies
[
"ydl-net"
]
// api rootProject.ext.dependencies["ydl-net"]
api
project
(
':ydl-net'
)
api
rootProject
.
ext
.
dependencies
[
"ydl-js"
]
api
rootProject
.
ext
.
dependencies
[
"ptr-lib-release"
]
api
(
rootProject
.
ext
.
dependencies
[
"ydl-device"
])
{
...
...
ydl-platform/src/main/java/com/ydl/ydlcommon/base/config/GlobalConfig.kt
View file @
32044cb7
...
...
@@ -91,6 +91,7 @@ class GlobalConfig private constructor(var builder: Builder) {
}
apiFactory
.
setOkClient
(
okHttpClient
)
HttpConfig
.
getInstance
().
initAuth
()
}
}
...
...
ydl-platform/src/main/java/com/ydl/ydlcommon/base/config/HttpConfig.kt
View file @
32044cb7
package
com.ydl.ydlcommon.base.config
import
android.annotation.SuppressLint
import
android.content.Context
import
android.text.TextUtils
import
com.facebook.stetho.okhttp3.StethoInterceptor
import
com.ydl.ydlcommon.base.BaseApp
import
com.ydl.ydlcommon.bean.AuthBean
import
com.ydl.ydlcommon.data.PlatformDataManager
import
com.ydl.ydlcommon.data.http.BaseAPIResponse
import
com.ydl.ydlcommon.data.http.EncryptUtils
import
com.ydl.ydlcommon.data.http.GsonProvider
import
com.ydl.ydlcommon.data.http.RxUtils
import
com.ydl.ydlcommon.data.http.api.ApiRequestUtil
import
com.ydl.ydlcommon.modular.ModularServiceManager
import
com.ydl.ydlcommon.utils.YDLCacheUtils
import
com.ydl.ydlnet.builder.config.OkHttpConfig
import
com.ydl.ydlnet.builder.interceptor.log.RequestHandler
import
com.yidianling.common.tools.LogUtil
import
com.yidianling.common.tools.RxAppTool
import
com.yidianling.common.tools.RxDeviceTool
import
okhttp3.FormBody
import
okhttp3.Interceptor
import
okhttp3.MultipartBody
import
okhttp3.OkHttpClient
import
com.yidianling.common.tools.ToastUtil
import
okhttp3.*
import
okio.Buffer
import
okio.BufferedSink
import
java.util.*
...
...
@@ -32,7 +38,10 @@ class HttpConfig {
//====================应用默认配置====================
private
const
val
AUTHORIZATION_NAME
=
"Authorization"
private
const
val
AUTHORIZATION_JAVA_NAME
=
"AuthorizationJava"
private
const
val
SESSION_KEY
=
"dc59cf294f37d237c1f06240568ffe21"
private
var
DYNAMIC_SESSION_KEY
:
String
=
"dc59cf294f37d237c1f06240568ffe21"
private
const
val
YDL
=
"Ydl"
private
const
val
UID
=
"uid"
private
const
val
FFROM
=
"ffrom"
...
...
@@ -43,6 +52,8 @@ class HttpConfig {
private
const
val
TOKEN
=
"accessToken"
private
val
OS_TYPE
=
"osType"
// 1.ios 2.android
private
val
APP_NAME
=
"appName"
//用于标识 是哪个应用 yidianling:用户版 xinlizixun:心理咨询 haoshi:情感壹点灵 zhuanjia:专家版
//验证签名失败
private
val
AUTH_INEFFECTIVE_CODE
=
"-201"
//====================网络环境====================
...
...
@@ -75,6 +86,7 @@ class HttpConfig {
return
builder
.
setInterceptor
(
commonParams
(),
requestHead
(
appFrom
))
.
setRequestHandler
(
getRequestHandler
())
.
setReadTimeout
(
15
)
.
setWriteTimeout
(
15
)
.
setConnectTimeout
(
15
)
...
...
@@ -82,6 +94,35 @@ class HttpConfig {
.
build
()
}
private
fun
getRequestHandler
():
RequestHandler
{
return
object
:
RequestHandler
{
override
fun
onHttpResultResponse
(
httpResult
:
String
,
chain
:
Interceptor
.
Chain
,
response
:
Response
):
Response
{
val
gson
=
GsonProvider
.
getGson
()
val
resultData
=
gson
.
fromJson
(
httpResult
,
BaseAPIResponse
::
class
.
java
)
when
(
resultData
.
code
)
{
AUTH_INEFFECTIVE_CODE
->
{
//签证签名失败
ToastUtil
.
toastShort
(
resultData
.
msg
)
//更新动态密钥
if
(
resultData
.
data
!=
null
){
var
authBean
=
gson
.
fromJson
<
AuthBean
>(
gson
.
toJson
(
resultData
.
data
),
AuthBean
::
class
.
java
)
DYNAMIC_SESSION_KEY
=
authBean
?.
appKey
.
toString
()
}
}
}
return
response
}
override
fun
onHttpRequestBefore
(
chain
:
Interceptor
.
Chain
?,
request
:
Request
):
Request
{
return
request
}
}
}
// 添加公共参数
private
fun
commonParams
():
Interceptor
{
...
...
@@ -202,6 +243,7 @@ class HttpConfig {
}
}
}
params
.
sortWith
(
Comparator
{
o1
,
o2
->
val
res
=
o1
.
name
.
compareTo
(
o2
.
name
)
when
{
...
...
@@ -214,14 +256,14 @@ class HttpConfig {
if
(
index
!=
0
)
paramsString
.
append
(
"&"
)
paramsString
.
append
(
"${param.name}=${param.value}"
)
}
paramsString
.
append
(
SESSION_KEY
)
val
head
=
"$YDL ${EncryptUtils.encryptMD5ToString(
paramsString
.
toString
()
)}
"
val
oldAuth
=
getOldAuth
(
paramsString
)
val
newAuth
=
getNewAuth
(
paramsString
)
val
builder
=
it
.
request
()
.
newBuilder
()
.
header
(
AUTHORIZATION_NAME
,
head
)
.
header
(
AUTHORIZATION_NAME
,
oldAuth
)
.
header
(
AUTHORIZATION_JAVA_NAME
,
newAuth
)
.
addHeader
(
"Connection"
,
"close"
)
.
addHeader
(
FFROM
,
PlatformDataManager
.
getRam
().
getChannelName
())
.
addHeader
(
IS_FROM_APP
,
"1"
)
...
...
@@ -243,6 +285,18 @@ class HttpConfig {
}
}
private
fun
getOldAuth
(
paramsString
:
StringBuilder
):
String
{
paramsString
.
append
(
SESSION_KEY
)
return
"$YDL ${EncryptUtils.encryptMD5ToString(
paramsString
.
toString
()
)}
"
}
private
fun
getNewAuth
(
paramsString
:
StringBuilder
):
String
{
//md5({静态秘钥} + {参数} + md5{动态秘钥(明文)}
return
"$YDL ${EncryptUtils.encryptMD5ToString(SESSION_KEY+ paramsString.toString()+EncryptUtils.encryptMD5ToString(DYNAMIC_SESSION_KEY))}"
}
//初始化网络环境
fun
initEnv
(
c
:
Context
,
env
:
String
)
{
var
appEnv
=
env
...
...
@@ -271,6 +325,20 @@ class HttpConfig {
SERVER_COUPON_URL
=
properties
.
getProperty
(
"javacouponurl.$appEnv"
)
}
@SuppressLint
(
"CheckResult"
)
fun
initAuth
(){
ApiRequestUtil
.
getDynamicToken
()
.
compose
(
RxUtils
.
applySchedulers
())
.
compose
(
RxUtils
.
resultJavaData
())
.
subscribe
({
if
(!
TextUtils
.
isEmpty
(
it
.
appKey
)){
DYNAMIC_SESSION_KEY
=
it
?.
appKey
.
toString
()
}
})
{
LogUtil
.
i
(
"HttpConfig"
,
it
.
toString
())
}
}
private
object
Holder
{
val
INSTANCE
=
HttpConfig
()
}
...
...
ydl-platform/src/main/java/com/ydl/ydlcommon/bean/AuthBean.kt
0 → 100644
View file @
32044cb7
package
com.ydl.ydlcommon.bean
/**
* Created by haorui on 2019-11-26.
* Des:
*/
class
AuthBean
{
/**
* id : 1
* appId : android_zhuzhan
* appKey : 123456
* version : 4.0.00
*/
var
id
:
Int
=
0
var
appId
:
String
?
=
null
var
appKey
:
String
?
=
null
var
version
:
String
?
=
null
}
ydl-platform/src/main/java/com/ydl/ydlcommon/data/http/api/ApiRequestUtil.java
View file @
32044cb7
package
com
.
ydl
.
ydlcommon
.
data
.
http
.
api
;
import
com.google.gson.Gson
;
import
com.ydl.ydlcommon.bean.AuthBean
;
import
com.ydl.ydlcommon.bean.MustUP
;
import
com.ydl.ydlcommon.data.http.BaseAPIResponse
;
import
com.ydl.ydlcommon.data.http.BaseResponse
;
...
...
@@ -8,12 +9,13 @@ import com.ydl.ydlcommon.data.http.FormatText;
import
com.ydl.ydlcommon.data.http.params.ActionDataBean
;
import
com.ydl.ydlcommon.utils.NetworkParamsUtils
;
import
com.ydl.ydlnet.YDLHttpUtils
;
import
java.util.List
;
import
io.reactivex.Observable
;
import
okhttp3.MediaType
;
import
okhttp3.RequestBody
;
import
java.util.List
;
/**
* 模块请求工具类
* Created by hgw on 2018/1/23.
...
...
@@ -39,4 +41,12 @@ public class ApiRequestUtil {
RequestBody
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/json; charset=utf-8"
),
new
Gson
().
toJson
(
actionDataParams
));
return
YDLHttpUtils
.
Companion
.
obtainApi
(
NetApiStore
.
class
).
actionDataCount
(
body
);
}
/**
* 获取动态密钥
* @return
*/
public
static
Observable
<
BaseAPIResponse
<
AuthBean
>>
getDynamicToken
()
{
return
YDLHttpUtils
.
Companion
.
obtainApi
(
NetApiStore
.
class
).
getDynamicToken
();
}
}
ydl-platform/src/main/java/com/ydl/ydlcommon/data/http/api/NetApiStore.java
View file @
32044cb7
package
com
.
ydl
.
ydlcommon
.
data
.
http
.
api
;
import
com.ydl.ydlcommon.bean.AuthBean
;
import
com.ydl.ydlcommon.bean.MustUP
;
import
com.ydl.ydlcommon.data.http.BaseAPIResponse
;
import
com.ydl.ydlcommon.data.http.BaseResponse
;
import
io.reactivex.Observable
;
import
okhttp3.RequestBody
;
import
retrofit2.http.*
;
import
java.util.Map
;
import
io.reactivex.Observable
;
import
okhttp3.RequestBody
;
import
retrofit2.http.Body
;
import
retrofit2.http.FieldMap
;
import
retrofit2.http.FormUrlEncoded
;
import
retrofit2.http.Headers
;
import
retrofit2.http.POST
;
import
static
com
.
ydl
.
ydlcommon
.
base
.
config
.
AppConfigKt
.
YDL_DOMAIN
;
import
static
com
.
ydl
.
ydlcommon
.
base
.
config
.
AppConfigKt
.
YDL_DOMAIN_JAVA
;
...
...
@@ -32,4 +38,8 @@ interface NetApiStore {
@POST
(
"data/bigdata/maidian/writeMaiDianData"
)
Observable
<
BaseAPIResponse
<
String
>>
actionDataCount
(
@Body
RequestBody
body
);
@Headers
(
YDL_DOMAIN
+
YDL_DOMAIN_JAVA
)
@POST
(
"risk/key/info"
)
Observable
<
BaseAPIResponse
<
AuthBean
>>
getDynamicToken
();
}
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