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
04541bdc
Commit
04541bdc
authored
Apr 02, 2021
by
YKai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:接口返回错误日志埋点补充参数
parent
018badf8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
139 deletions
+88
-139
ApiUtil.kt
ydl-net/src/main/java/com/ydl/ydlnet/builder/api/ApiUtil.kt
+0
-29
NetApi.kt
ydl-net/src/main/java/com/ydl/ydlnet/builder/api/NetApi.kt
+0
-22
RequestLogInterceptor.java
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
+0
-18
ApiErrorCountUtils.kt
ydl-net/src/main/java/com/ydl/ydlnet/utils/ApiErrorCountUtils.kt
+0
-59
HttpConfig.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/base/config/HttpConfig.kt
+37
-4
ActionCountUtils.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/utils/actionutil/ActionCountUtils.kt
+51
-7
No files found.
ydl-net/src/main/java/com/ydl/ydlnet/builder/api/ApiUtil.kt
deleted
100644 → 0
View file @
018badf8
package
com.ydl.ydlnet.builder.api
import
com.google.gson.Gson
import
com.ydl.ydlnet.YDLHttpUtils.Companion.obtainApi
import
com.ydl.ydlnet.builder.bean.ApiErrorActionBean
import
com.ydl.ydlnet.builder.bean.BaseAPIResponse
import
io.reactivex.Observable
import
okhttp3.MediaType
import
okhttp3.RequestBody
/**
* Created by Ykai on 2021/3/15.
*/
class
ApiUtil
{
companion
object
{
/**
* 行为数据埋点统计
*/
fun
actionDataCount
(
actionDataParams
:
ApiErrorActionBean
):
Observable
<
BaseAPIResponse
<
String
>>
{
val
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/json; charset=utf-8"
),
Gson
().
toJson
(
actionDataParams
)
)
return
obtainApi
(
NetApi
::
class
.
java
).
actionDataCount
(
body
)
}
}
}
\ No newline at end of file
ydl-net/src/main/java/com/ydl/ydlnet/builder/api/NetApi.kt
deleted
100644 → 0
View file @
018badf8
package
com.ydl.ydlnet.builder.api
import
com.ydl.ydlnet.builder.bean.BaseAPIResponse
import
io.reactivex.Observable
import
okhttp3.RequestBody
import
retrofit2.http.Body
import
retrofit2.http.Headers
import
retrofit2.http.POST
/**
* Created by Ykai on 2021/3/15.
*/
interface
NetApi
{
/**
* 行为动作埋点统计
*/
@Headers
(
"Domain-Name:JAVA_BASE_URL"
)
@POST
(
"data/bigdata/maidian/writeMaiDianData"
)
fun
actionDataCount
(
@Body
body
:
RequestBody
):
Observable
<
BaseAPIResponse
<
String
>>
}
\ No newline at end of file
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
View file @
04541bdc
...
...
@@ -2,13 +2,10 @@ package com.ydl.ydlnet.builder.interceptor.log;
import
android.support.annotation.Nullable
;
import
com.ydl.ydlnet.utils.ApiErrorCountUtils
;
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
com.ydl.ydlnet.utils.log.AliYunLogConfig
;
import
com.ydl.ydlnet.utils.log.AliYunLogHelper
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
...
...
@@ -90,21 +87,6 @@ public class RequestLogInterceptor implements Interceptor {
mPrinter
.
printFileResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
segmentList
,
message
,
url
);
}
}
else
{
int
code
=
originalResponse
.
code
();
// 接口返回错误的情况下,埋点告诉服务器原因
if
(
code
!=
200
)
{
String
params
=
""
;
Request
rq
=
originalResponse
.
request
();
if
(
rq
.
method
().
equals
(
"GET"
))
{
params
=
rq
.
url
().
query
();
}
else
if
(
rq
.
method
().
equals
(
"POST"
))
{
params
=
parseParams
(
rq
);
}
String
message
=
originalResponse
.
message
();
ApiErrorCountUtils
.
Companion
.
baiDuCount
(
"pardId-ydl_user_error_business"
,
"error_log"
,
params
,
message
);
AliYunLogHelper
.
Companion
.
getInstance
().
sendLog
(
AliYunLogConfig
.
API
,
"error_log--- params:"
+
params
+
" ---- message:"
+
message
);
}
}
return
originalResponse
;
}
...
...
ydl-net/src/main/java/com/ydl/ydlnet/utils/ApiErrorCountUtils.kt
deleted
100644 → 0
View file @
018badf8
package
com.ydl.ydlnet.utils
import
android.annotation.SuppressLint
import
android.util.Log
import
com.ydl.ydlnet.builder.api.ApiUtil
import
com.ydl.ydlnet.builder.bean.ApiErrorActionBean
import
io.reactivex.android.schedulers.AndroidSchedulers
import
io.reactivex.schedulers.Schedulers
/**
* Created by Ykai on 2021/3/15.
*/
class
ApiErrorCountUtils
{
companion
object
{
private
const
val
TAG
:
String
=
"ActionCountUtils"
/**
* 接口返回错误埋点调用该方法
* @param partId pardId-ydl_user_error_business
* @param position error_log
* @param sign1 访问接口对应的参数
* @param sign2 接口返回的错误信息
*/
fun
baiDuCount
(
partId
:
String
,
position
:
String
,
sign1
:
String
,
sign2
:
String
)
{
val
actionDataParams
=
ApiErrorActionBean
.
Builder
()
actionDataParams
.
partId
=
partId
actionDataParams
.
position
=
position
actionDataParams
.
sign1
=
sign1
actionDataParams
.
sign2
=
sign2
//请求
request
(
actionDataParams
.
build
())
}
/**
* 传入ActionDataParams参数,访问接口
*/
@SuppressLint
(
"CheckResult"
)
private
fun
request
(
actionDataBean
:
ApiErrorActionBean
)
{
try
{
ApiUtil
.
actionDataCount
(
actionDataBean
)
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
({
Log
.
i
(
TAG
,
it
.
data
)
})
{
Log
.
i
(
TAG
,
it
.
toString
())
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
}
}
\ No newline at end of file
ydl-platform/src/main/java/com/ydl/ydlcommon/base/config/HttpConfig.kt
View file @
04541bdc
...
...
@@ -16,9 +16,13 @@ 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.ydlcommon.utils.actionutil.ActionCountUtils
import
com.ydl.ydlcommon.utils.log.AliYunRichLogsHelper
import
com.ydl.ydlnet.builder.config.OkHttpConfig
import
com.ydl.ydlnet.builder.factory.ApiFactory
import
com.ydl.ydlnet.builder.interceptor.log.RequestHandler
import
com.ydl.ydlnet.builder.interceptor.log.RequestLogInterceptor
import
com.ydl.ydlnet.utils.log.AliYunLogConfig
import
com.yidianling.common.tools.LogUtil
import
com.yidianling.common.tools.RxAppTool
import
com.yidianling.common.tools.RxDeviceTool
...
...
@@ -118,6 +122,7 @@ class HttpConfig {
var
ENCRYPTION_APP_KEY
=
""
// 接口加密appKey
var
ENCRYPTION_APP_SECRET
=
""
// 接口加密appSecret
var
isEncryption
=
false
var
appDebug
:
Boolean
=
false
fun
getInstance
():
HttpConfig
{
return
Holder
.
INSTANCE
...
...
@@ -127,7 +132,7 @@ class HttpConfig {
fun
createOkHttp
():
OkHttpClient
{
val
globalConfig
=
BaseApp
.
instance
.
getGlobalConfig
()
val
context
=
BaseApp
.
getApp
()
val
appDebug
=
globalConfig
.
appDebug
appDebug
=
globalConfig
.
appDebug
val
appName
=
globalConfig
.
appName
//获取证书
...
...
@@ -144,7 +149,8 @@ class HttpConfig {
.
setInterceptor
(
commonParams
(),
requestHead
(
appName
),
addEncryptionHeaderParamsInterceptor
()
addEncryptionHeaderParamsInterceptor
(),
responseErrorInterceptor
()
)
.
setRequestHandler
(
getRequestHandler
())
.
setReadTimeout
(
15
)
...
...
@@ -170,7 +176,7 @@ class HttpConfig {
path
+=
it
.
request
().
url
().
encodedPath
().
substring
(
5
)
}
else
->
{
path
+
it
.
request
().
url
().
encodedPath
()
path
+
it
.
request
().
url
().
encodedPath
()
}
}
val
sign
=
EncryptionParams
.
getSign
(
path
,
timestamp
)
...
...
@@ -180,12 +186,39 @@ class HttpConfig {
.
addHeader
(
"timestamp"
,
timestamp
)
.
build
()
it
.
proceed
(
request
)
}
else
{
}
else
{
it
.
proceed
(
it
.
request
())
}
}
}
/**
* 接口返回错误日志埋点
*/
private
fun
responseErrorInterceptor
():
Interceptor
{
return
Interceptor
{
val
request
:
Request
=
it
.
request
()
val
originalResponse
:
Response
=
it
.
proceed
(
request
)
if
(!
appDebug
){
val
code
=
originalResponse
.
code
()
// 接口返回错误的情况下,埋点告诉服务器原因
if
(
code
!=
200
)
{
var
params
=
""
if
(
request
.
method
()
==
"GET"
)
{
params
=
request
.
url
().
query
().
toString
()
}
else
if
(
request
.
method
()
==
"POST"
)
{
params
=
RequestLogInterceptor
.
parseParams
(
request
)
}
val
message
=
originalResponse
.
message
()
val
api
=
request
.
url
().
encodedPath
()
ActionCountUtils
.
baiDuCount
(
"ydl_user_error_business"
,
"error_log"
,
api
,
params
,
message
)
AliYunRichLogsHelper
.
getInstance
().
sendRichLog
(
AliYunLogConfig
.
API
,
"error_log---api:$api---params:$params ---- message:$message"
)
}
}
originalResponse
}
}
private
fun
getRequestHandler
():
RequestHandler
{
return
object
:
RequestHandler
{
override
fun
onHttpResultResponse
(
...
...
ydl-platform/src/main/java/com/ydl/ydlcommon/utils/actionutil/ActionCountUtils.kt
View file @
04541bdc
...
...
@@ -134,10 +134,10 @@ class ActionCountUtils {
actionDataParams
.
appVersion
(
RxDeviceTool
.
getAppVersionName
(
BaseApp
.
getApp
()))
actionDataParams
.
appId
(
appId
)
actionDataParams
.
api
(
api
)
actionDataParams
.
manufacturer
(
android
.
os
.
Build
.
BRAND
.
trim
().
toUpperCase
())
actionDataParams
.
model
(
android
.
os
.
Build
.
MODEL
)
actionDataParams
.
manufacturer
(
Build
.
BRAND
.
trim
().
toUpperCase
())
actionDataParams
.
model
(
Build
.
MODEL
)
actionDataParams
.
os
(
BIConstants
.
OS
)
actionDataParams
.
osVersion
(
android
.
os
.
Build
.
VERSION
.
RELEASE
)
actionDataParams
.
osVersion
(
Build
.
VERSION
.
RELEASE
)
actionDataParams
.
wifi
(
if
(
isWifi
())
0
else
1
)
var
deviceId
=
""
/*
...
...
@@ -243,10 +243,10 @@ class ActionCountUtils {
actionDataParams
.
appVersion
(
RxDeviceTool
.
getAppVersionName
(
BaseApp
.
getApp
()))
actionDataParams
.
appId
(
appId
)
actionDataParams
.
api
(
api
)
actionDataParams
.
manufacturer
(
android
.
os
.
Build
.
BRAND
.
trim
().
toUpperCase
())
actionDataParams
.
model
(
android
.
os
.
Build
.
MODEL
)
actionDataParams
.
manufacturer
(
Build
.
BRAND
.
trim
().
toUpperCase
())
actionDataParams
.
model
(
Build
.
MODEL
)
actionDataParams
.
os
(
BIConstants
.
OS
)
actionDataParams
.
osVersion
(
android
.
os
.
Build
.
VERSION
.
RELEASE
)
actionDataParams
.
osVersion
(
Build
.
VERSION
.
RELEASE
)
actionDataParams
.
wifi
(
if
(
isWifi
())
0
else
1
)
actionDataParams
.
screenWidth
(
RxDeviceTool
.
getScreenWidth
(
RxTool
.
getContext
()
!!
))
actionDataParams
.
screenHeight
(
RxDeviceTool
.
getScreenHeight
(
RxTool
.
getContext
()
!!
))
...
...
@@ -287,7 +287,7 @@ class ActionCountUtils {
baiduActionDataParams
.
androidId
(
DeviceTool
.
getAndroidID
())
//MD5加密的androidId
baiduActionDataParams
.
ip
(
""
)
baiduActionDataParams
.
ipv6
(
""
)
//给服务端传IPV6地址DeviceTool.getLocalIpV6()
baiduActionDataParams
.
tp
(
android
.
os
.
Build
.
MODEL
)
baiduActionDataParams
.
tp
(
Build
.
MODEL
)
baiduActionDataParams
.
network
(
DeviceTool
.
getNetworkState
(
RxTool
.
getContext
()))
baiduActionDataParams
.
convertParam
(
""
)
baiduActionDataParams
.
uid
(
uid
)
...
...
@@ -316,8 +316,52 @@ class ActionCountUtils {
}
/**
* 接口返回错误埋点调用该方法
* @param partId pardId-ydl_user_error_business
* @param position error_log
* @param sign1 访问接口对应的参数
* @param sign2 接口返回的错误信息
*/
fun
baiDuCount
(
partId
:
String
,
position
:
String
,
api
:
String
,
sign1
:
String
,
sign2
:
String
)
{
val
actionDataParams
=
ActionDataBean
.
Builder
()
actionDataParams
.
partId
=
partId
actionDataParams
.
position
=
position
actionDataParams
.
sign1
=
sign1
actionDataParams
.
sign2
=
sign2
actionDataParams
.
api
=
api
actionDataParams
.
appVersion
(
RxDeviceTool
.
getAppVersionName
(
BaseApp
.
getApp
()))
val
deviceId
=
if
(
Build
.
VERSION
.
SDK_INT
<=
Build
.
VERSION_CODES
.
P
)
{
val
topTaskActivity
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
//获取imei
Utils
.
getIMEI
(
topTaskActivity
)
}
else
{
//android Q及以上取oaid
DeviceIDHelper
.
getInstance
().
deviceId
}
actionDataParams
.
deviceId
=
deviceId
actionDataParams
.
time
(
System
.
currentTimeMillis
())
actionDataParams
.
appId
(
appId
)
actionDataParams
.
manufacturer
(
Build
.
BRAND
.
trim
().
toUpperCase
())
actionDataParams
.
model
(
Build
.
MODEL
)
actionDataParams
.
os
(
BIConstants
.
OS
)
actionDataParams
.
osVersion
(
Build
.
VERSION
.
RELEASE
)
actionDataParams
.
wifi
(
if
(
isWifi
())
0
else
1
)
actionDataParams
.
uid
=
ModularServiceManager
.
getPlatformUserService
()
!!
.
getUser
()
?.
userId
//请求
request
(
actionDataParams
.
build
())
}
/**
* 传入ActionDataParams参数,访问接口
*/
@SuppressLint
(
"CheckResult"
)
fun
request
(
actionDataBean
:
ActionDataBean
)
{
try
{
ApiRequestUtil
.
actionDataCount
(
actionDataBean
)
...
...
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