Commit 1a9e884c by YKai

feat:ydl-net组件升级,增加接口返回错误埋点

parent bf9d9ff1
......@@ -33,7 +33,7 @@ ext {
//-------------- 功能组件 --------------
//第一步
"ydl-platform" : "0.0.39.86",
"ydl-platform" : "0.0.39.87",
//第二步 若干
"ydl-webview" : "0.0.38.36",
......@@ -44,7 +44,7 @@ ext {
//以下 几乎不会动
"router" : "0.0.1",
"ydl-net" : "0.0.3.1",
"ydl-net" : "0.0.3.3",
"ydl-utils" : "0.0.3.1",
]
ydl_app = [
......@@ -114,7 +114,7 @@ ext {
//-------------- 功能组件 --------------
//第一步
"ydl-platform" : "0.0.39.86",
"ydl-platform" : "0.0.39.87",
//第二步 若干
"ydl-webview" : "0.0.38.36",
......@@ -125,7 +125,8 @@ ext {
//以下 几乎不会动
"router" : "0.0.1",
"ydl-net" : "0.0.3.1","ydl-utils" : "0.0.3.1",
"ydl-net" : "0.0.3.3",
"ydl-utils" : "0.0.3.1",
]
dependencies = [
......
......@@ -50,6 +50,5 @@ dependencies {
api rootProject.ext.dependencies["retrofit-converter-gson"]
api rootProject.ext.dependencies["retrofit-converter-scalars"]
api rootProject.ext.dependencies["retrofit-adapter-rxjava2"]
}
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
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
package com.ydl.ydlnet.builder.bean
/**
* Created by xj on 2019/6/22.
*/
class ApiErrorActionBean private constructor(builder: Builder) {
/**
* partId : sy_1 //埋点板块
* position : psychic_advisory_click //点击事件
* type : 1 //业务类型 1.埋点
* uid : 123 //用户ID
* channel :huawei //渠道
* deviceId : //设备ID Android端取imei做md5加密,iOS端取idfa做md5加密 为32位的串
* time : 1560389634000 //事件发生时间,毫秒级时间戳
* ip : 192.168.0.1 //IP地址
* appVersion : 3.8.00 //版本号
* appId : ydl-app-android-user
* url : https://www.baidu.com //访问地址
* server : 123
* api : https://www.baidu.com/api
* manufacturer : Apple //设备厂商,字符串类型,如"Apple"
* model : iphone6 //设备型号,字符串类型,如"iphone6"
* os : iOS //操作系统,字符串类型,如"iOS"
* osVersion : 8.1.1 //操作系统版本,字符串类型,如"8.1.1"
* screenHeight : 1920 //屏幕高度,数字类型,如1920
* screenWidth : 1080 //屏幕宽度,数字类型,如1080
* wifi : 1 //网络类型:1.2G 3.3G 4.4G 5.5G 6.WIFI
* sign1 :
* sign2 :
* sign3 :
* sign4 :
* sign5 :
*/
var partId: String? = null
var type : Int? = 0
var position: String? = null
var uid: String? = null
var channel:String? = null
var deviceId : String? = null
var time: Long = 0.toLong()
var ip: String? = null
var appVersion: String? = null
var appId: String? = null
var url: String? = null
var server: String? = null
var api: String? = null
var manufacturer: String? = null
var model: String? = null
var os: String? = null
var osVersion: String? = null
var screenHeight: Int = 0
var screenWidth: Int = 0
var wifi: Int = 0
var sign1: String? = null
var sign2: String? = null
var sign3: String? = null
var sign4: String? = null
var sign5: String? = null
init {
this.partId = builder.partId
this.type = builder.type
this.position = builder.position
this.uid = builder.uid
this.channel = builder.channel
this.deviceId = builder.deviceId
this.time = builder.time
this.ip = builder.ip
this.appVersion = builder.appVersion
this.appId = builder.appId
this.url = builder.url
this.server = builder.server
this.api = builder.api
this.manufacturer = builder.manufacturer
this.model = builder.model
this.os = builder.os
this.osVersion = builder.osVersion
this.screenHeight = builder.screenHeight
this.screenWidth = builder.screenWidth
this.wifi = builder.wifi
this.sign1 = builder.sign1
this.sign2 = builder.sign2
this.sign3 = builder.sign3
this.sign4 = builder.sign4
this.sign5 = builder.sign5
}
class Builder {
internal var partId: String? = ""
internal var type : Int? = 0
internal var position: String? = ""
internal var uid: String? = ""
internal var channel: String?=""
internal var deviceId : String? =""
internal var time: Long = 0.toLong()
internal var ip: String? = ""
internal var appVersion: String? = ""
internal var appId: String? = ""
internal var url: String? = ""
internal var server: String? = ""
internal var api: String? = ""
internal var manufacturer: String? = ""
internal var model: String? = ""
internal var os: String? = ""
internal var osVersion: String? = ""
internal var screenHeight: Int = 0
internal var screenWidth: Int = 0
internal var wifi: Int = 0
internal var sign1: String? = ""
internal var sign2: String? = ""
internal var sign3: String? = ""
internal var sign4: String? = ""
internal var sign5: String? = ""
fun partId(partId: String = ""): Builder {
this.partId = partId
return this
}
fun type(type : Int = 0) : Builder{
this.type = type
return this
}
fun position(position: String = ""): Builder {
this.position = position
return this
}
fun uid(uid: String = ""): Builder {
this.uid = uid
return this
}
fun channel(channel:String = ""): Builder{
this.channel = channel
return this
}
fun deviceId(deviceId: String = "") : Builder{
this.deviceId = deviceId
return this
}
fun time(time: Long = 0.toLong()): Builder {
this.time = time
return this
}
fun ip(ip: String = ""): Builder {
this.ip = ip
return this
}
fun appVersion(appVersion: String = ""): Builder {
this.appVersion = appVersion
return this
}
fun appId(appId: String = ""): Builder {
this.appId = appId
return this
}
fun url(url: String = ""): Builder {
this.url = url
return this
}
fun server(server: String = ""): Builder {
this.server = server
return this
}
fun api(api: String = ""): Builder {
this.api = api
return this
}
fun manufacturer(manufacturer: String = ""): Builder {
this.manufacturer = manufacturer
return this
}
fun model(model: String = ""): Builder {
this.model = model
return this
}
fun os(os: String = ""): Builder {
this.os = os
return this
}
fun osVersion(osVersion: String = ""): Builder {
this.osVersion = osVersion
return this
}
fun screenHeight(screenHeight: Int = 0): Builder {
this.screenHeight = screenHeight
return this
}
fun screenWidth(screenWidth: Int = 0): Builder {
this.screenWidth = screenWidth
return this
}
fun wifi(wifi: Int = 0): Builder {
this.wifi = wifi
return this
}
fun sign1(sign1: String = ""): Builder {
this.sign1 = sign1
return this
}
fun sign2(sign2: String = ""): Builder {
this.sign2 = sign2
return this
}
fun sign3(sign3: String = ""): Builder {
this.sign3 = sign3
return this
}
fun sign4(sign4: String = ""): Builder {
this.sign4 = sign4
return this
}
fun sign5(sign5: String = ""): Builder {
this.sign5 = sign5
return this
}
fun build() : ApiErrorActionBean {
return ApiErrorActionBean(this)
}
}
}
\ No newline at end of file
package com.ydl.ydlnet.builder.bean;
/**
* 基础返回数据类(java接口使用)
* Created by Dog on 2015/5/8.
*/
public class BaseAPIResponse<T> {
public String code;
public String msg;
public T data;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ 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;
......@@ -86,8 +87,22 @@ 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);
}
}
return originalResponse;
}
......
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
package com.ydl.ydlcommon.utils.actionutil
//import com.bun.miitmdid.content.ContextKeeper
//import com.ydl.devicesidlib.DemoHelper
import android.annotation.SuppressLint
import android.content.Context
import android.net.ConnectivityManager
......
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