Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_youyou
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
android
android_youyou
Commits
ca0273d7
Commit
ca0273d7
authored
Apr 06, 2021
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级枫岚sdk
parent
d5f3b302
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
316 additions
and
160 deletions
+316
-160
build.gradle
app/build.gradle
+2
-2
mh-adsdk-ext.aar
app/libs/mh-adsdk-ext.aar
+0
-0
mh-adsdk.aar
app/libs/mh-adsdk.aar
+0
-0
WenshuApplication.java
app/src/main/java/com/wenshu/youyou/WenshuApplication.java
+1
-0
MhVideoAdManager.kt
.../main/java/com/wenshu/youyou/ad/video/MhVideoAdManager.kt
+116
-116
VideoAdingManager.java
...in/java/com/wenshu/youyou/ad/video/VideoAdingManager.java
+51
-2
MhManager.kt
app/src/main/java/com/wenshu/youyou/manager/MhManager.kt
+2
-2
TrackManager.java
...src/main/java/com/wenshu/youyou/manager/TrackManager.java
+6
-0
TrackPresenter.java
...java/com/wenshu/youyou/mvp/presenters/TrackPresenter.java
+22
-0
LoanService.java
app/src/main/java/com/wenshu/youyou/net/LoanService.java
+8
-0
OkHttpInterceptor.java
...rc/main/java/com/wenshu/youyou/net/OkHttpInterceptor.java
+108
-38
No files found.
app/build.gradle
View file @
ca0273d7
...
@@ -9,8 +9,8 @@ android {
...
@@ -9,8 +9,8 @@ android {
applicationId
"com.wenshu.youyou"
applicationId
"com.wenshu.youyou"
minSdkVersion
rootProject
.
ext
.
androidMinSdkVersion
minSdkVersion
rootProject
.
ext
.
androidMinSdkVersion
targetSdkVersion
rootProject
.
ext
.
androidTargetSdkVersion
targetSdkVersion
rootProject
.
ext
.
androidTargetSdkVersion
versionCode
4
versionCode
5
versionName
"1.0.
4
"
versionName
"1.0.
5
"
flavorDimensions
"default"
flavorDimensions
"default"
// dex突破65535的限制
// dex突破65535的限制
...
...
app/libs/mh-adsdk-ext.aar
100644 → 100755
View file @
ca0273d7
No preview for this file type
app/libs/mh-adsdk.aar
100644 → 100755
View file @
ca0273d7
No preview for this file type
app/src/main/java/com/wenshu/youyou/WenshuApplication.java
View file @
ca0273d7
...
@@ -12,6 +12,7 @@ import androidx.multidex.MultiDexApplication;
...
@@ -12,6 +12,7 @@ import androidx.multidex.MultiDexApplication;
import
com.hjq.toast.ToastUtils
;
import
com.hjq.toast.ToastUtils
;
import
com.wenshu.youyou.common.Constant
;
import
com.wenshu.youyou.common.Constant
;
import
com.wenshu.youyou.manager.KsManager
;
import
com.wenshu.youyou.manager.MhManager
;
import
com.wenshu.youyou.manager.MhManager
;
import
com.wenshu.youyou.manager.MiitHelper
;
import
com.wenshu.youyou.manager.MiitHelper
;
import
com.wenshu.youyou.manager.RsNewsManager
;
import
com.wenshu.youyou.manager.RsNewsManager
;
...
...
app/src/main/java/com/wenshu/youyou/ad/video/MhVideoAdManager.kt
View file @
ca0273d7
//package com.wenshu.youyou.ad.video
package
com.wenshu.youyou.ad.video
//
//import android.app.Activity
import
android.app.Activity
//import com.maplehaze.adsdk.video.RewardVideoAd
import
com.maplehaze.adsdk.video.RewardVideoAd
//import com.wenshu.youyou.ad.video.base.BaseVideoAd
import
com.wenshu.youyou.ad.video.base.BaseVideoAd
//import com.wenshu.youyou.ad.video.base.VideoAdStatusListener
import
com.wenshu.youyou.ad.video.base.VideoAdStatusListener
//import com.wenshu.youyou.common.AppConfig
import
com.wenshu.youyou.common.AppConfig
//import com.wenshu.youyou.common.Constant
import
com.wenshu.youyou.common.Constant
//import com.wenshu.youyou.manager.MhManager
import
com.wenshu.youyou.manager.MhManager
//import com.wenshu.youyou.manager.TrackManager
import
com.wenshu.youyou.manager.TrackManager
//import com.wenshu.youyou.utils.LogUtil
import
com.wenshu.youyou.utils.LogUtil
//
//private val TAG = MhVideoAdManager::class.java.simpleName
private
val
TAG
=
MhVideoAdManager
::
class
.
java
.
simpleName
//
///**
/**
// * 枫岚广告视频
* 枫岚广告视频
// */
*/
//class MhVideoAdManager private constructor() :
class
MhVideoAdManager
private
constructor
()
:
// BaseVideoAd() {
BaseVideoAd
()
{
//
// private var videoAdStatusListener: VideoAdStatusListener? = null
private
var
videoAdStatusListener
:
VideoAdStatusListener
?
=
null
// private var mRewardVideoAd: RewardVideoAd? = null
private
var
mRewardVideoAd
:
RewardVideoAd
?
=
null
//
// private var isClickScreen: Boolean = true
private
var
isClickScreen
:
Boolean
=
true
//
// companion object {
companion
object
{
// private var _inst: MhVideoAdManager? = null
private
var
_inst
:
MhVideoAdManager
?
=
null
// fun getInstance(): MhVideoAdManager? {
fun
getInstance
():
MhVideoAdManager
?
{
// return if (_inst != null) {
return
if
(
_inst
!=
null
)
{
// _inst
_inst
// } else {
}
else
{
// _inst = MhVideoAdManager()
_inst
=
MhVideoAdManager
()
// _inst
_inst
// }
}
// }
}
// }
}
//
// override fun loadAd(activity: Activity, curCoin: Int, carrierType: String, extraId: String?) {
override
fun
loadAd
(
activity
:
Activity
,
curCoin
:
Int
,
carrierType
:
String
,
extraId
:
String
?)
{
// isClickScreen = true
isClickScreen
=
true
//
// val postId: String = when (carrierType) {
val
postId
:
String
=
when
(
carrierType
)
{
// Constant.CARRIER_VERSUS_VIDEO -> MhManager.POS_ID
Constant
.
CARRIER_VERSUS_VIDEO
->
MhManager
.
POS_ID
// Constant.CARRIER_HOMEWATER -> MhManager.POS_ID
Constant
.
CARRIER_HOMEWATER
->
MhManager
.
POS_ID
// Constant.CARRIER_CHALLENGE_TURN, Constant.CARRIER_DRAWCASH -> MhManager.POS_ID
Constant
.
CARRIER_CHALLENGE_TURN
,
Constant
.
CARRIER_DRAWCASH
->
MhManager
.
POS_ID
// Constant.CARRIER_CHALLENGE_CARD -> MhManager.POS_ID
Constant
.
CARRIER_CHALLENGE_CARD
->
MhManager
.
POS_ID
// else -> MhManager.POS_ID
else
->
MhManager
.
POS_ID
// }
}
//
// val orientation = RewardVideoAd.VERTICAL
val
orientation
=
RewardVideoAd
.
VERTICAL
//
// mRewardVideoAd = RewardVideoAd(activity, MhManager.APP_ID, postId, orientation, object : RewardVideoAd.RewardVideoListener {
mRewardVideoAd
=
RewardVideoAd
(
activity
,
MhManager
.
APP_ID
,
postId
,
orientation
,
object
:
RewardVideoAd
.
RewardVideoListener
{
// override fun onADCached() {
override
fun
onADCached
()
{
// LogUtil.d(TAG, "onADCached")
LogUtil
.
d
(
TAG
,
"onADCached"
)
// mRewardVideoAd?.showAd(activity)
mRewardVideoAd
?.
showAd
(
activity
)
// }
}
//
// override fun onADShow() {
override
fun
onADShow
()
{
// LogUtil.d(TAG, "onADShow")
LogUtil
.
d
(
TAG
,
"onADShow"
)
// TrackManager.getInstance().addCallImp(Constant.AD_SOURCE_FL, Constant.EVENT_TYPE_ZERO, "", "")
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_FL
,
Constant
.
EVENT_TYPE_ZERO
,
""
,
""
)
// }
}
//
// override fun onReward() {
override
fun
onReward
()
{
// LogUtil.d(TAG, "onReward")
LogUtil
.
d
(
TAG
,
"onReward"
)
// }
}
//
// override fun onADClick() {
override
fun
onADClick
()
{
// if (AppConfig.needReportClickAdEvent) {
if
(
AppConfig
.
needReportClickAdEvent
)
{
// TrackManager.getInstance().reportClickAdEvent()
TrackManager
.
getInstance
().
reportClickAdEvent
()
// }
}
//
// LogUtil.d(TAG, "onADClick")
LogUtil
.
d
(
TAG
,
"onADClick"
)
// TrackManager.getInstance().addCallImp(Constant.AD_SOURCE_FL, Constant.EVENT_TYPE_TWO, "", "")
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_FL
,
Constant
.
EVENT_TYPE_TWO
,
""
,
""
)
// if (isClickScreen) {
if
(
isClickScreen
)
{
// // 防止重复
// 防止重复
// TrackManager.getInstance().addCallImp(Constant.AD_SOURCE_FL, Constant.EVENT_TYPE_FOUR, "", "")
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_FL
,
Constant
.
EVENT_TYPE_FOUR
,
""
,
""
)
// isClickScreen = false
isClickScreen
=
false
// }
}
//
// videoAdStatusListener?.adDownload()
videoAdStatusListener
?.
adDownload
()
// }
}
//
// override fun onVideoComplete() {
override
fun
onVideoComplete
()
{
// LogUtil.d(TAG, "onVideoComplete")
LogUtil
.
d
(
TAG
,
"onVideoComplete"
)
// }
}
//
// override fun onADClose() {
override
fun
onADClose
()
{
// LogUtil.d(TAG, "onADClose")
LogUtil
.
d
(
TAG
,
"onADClose"
)
//
// TrackManager.getInstance().reportAddCoinMsg(activity, getAdMapVO(carrierType, Constant.AD_SOURCE_FL, extraId, curCoin))
TrackManager
.
getInstance
().
reportAddCoinMsg
(
activity
,
getAdMapVO
(
carrierType
,
Constant
.
AD_SOURCE_FL
,
extraId
,
curCoin
))
//
// TrackManager.getInstance().addCallImp(Constant.AD_SOURCE_FL, Constant.EVENT_TYPE_THREE, "", "")
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_FL
,
Constant
.
EVENT_TYPE_THREE
,
""
,
""
)
//
// videoAdStatusListener?.adSuccess()
videoAdStatusListener
?.
adSuccess
()
// }
}
//
// override fun onADError(p0: Int) {
override
fun
onADError
(
p0
:
Int
)
{
// LogUtil.d(TAG, "onADError->$p0")
LogUtil
.
d
(
TAG
,
"onADError->$p0"
)
//
// TrackManager.getInstance().addCallImp(Constant.AD_SOURCE_FL, Constant.EVENT_TYPE_ONE, (p0).toString(), "")
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_FL
,
Constant
.
EVENT_TYPE_ONE
,
(
p0
).
toString
(),
""
)
//
// videoAdStatusListener?.adFail()
videoAdStatusListener
?.
adFail
()
// }
}
//
// })
})
//
// mRewardVideoAd?.loadAd()
mRewardVideoAd
?.
loadAd
()
// }
}
//
// fun setVideoAdStatusListener(videoAdStatusListener: VideoAdStatusListener?) {
fun
setVideoAdStatusListener
(
videoAdStatusListener
:
VideoAdStatusListener
?)
{
// this.videoAdStatusListener = videoAdStatusListener
this
.
videoAdStatusListener
=
videoAdStatusListener
// }
}
//
// override fun onDestroy() {
override
fun
onDestroy
()
{
// mRewardVideoAd = null
mRewardVideoAd
=
null
// }
}
//}
}
\ No newline at end of file
\ No newline at end of file
app/src/main/java/com/wenshu/youyou/ad/video/VideoAdingManager.java
View file @
ca0273d7
...
@@ -38,6 +38,7 @@ public class VideoAdingManager {
...
@@ -38,6 +38,7 @@ public class VideoAdingManager {
private
ShVideoAdManager
shVideoAdManager
;
private
ShVideoAdManager
shVideoAdManager
;
private
CsjFullVideoAdManager
csjFullVideoAdManager
;
private
CsjFullVideoAdManager
csjFullVideoAdManager
;
private
KsVideoAdManager
ksVideoAdManager
;
private
KsVideoAdManager
ksVideoAdManager
;
private
MhVideoAdManager
mhVideoAdManager
;
private
int
wnWeight
;
private
int
wnWeight
;
private
int
ylhWeight
;
private
int
ylhWeight
;
...
@@ -45,6 +46,7 @@ public class VideoAdingManager {
...
@@ -45,6 +46,7 @@ public class VideoAdingManager {
private
int
shVideoWeight
;
private
int
shVideoWeight
;
private
int
csjFullVideoWeight
;
private
int
csjFullVideoWeight
;
private
int
ksVideoWeight
;
private
int
ksVideoWeight
;
private
int
flVideoWeight
;
private
ArrayList
<
WeightBean
>
weightList
;
private
ArrayList
<
WeightBean
>
weightList
;
...
@@ -80,6 +82,7 @@ public class VideoAdingManager {
...
@@ -80,6 +82,7 @@ public class VideoAdingManager {
shVideoAdManager
=
ShVideoAdManager
.
Companion
.
getInstance
(
activity
);
shVideoAdManager
=
ShVideoAdManager
.
Companion
.
getInstance
(
activity
);
csjFullVideoAdManager
=
CsjFullVideoAdManager
.
getInstance
(
activity
);
csjFullVideoAdManager
=
CsjFullVideoAdManager
.
getInstance
(
activity
);
ksVideoAdManager
=
KsVideoAdManager
.
Companion
.
getInstance
();
ksVideoAdManager
=
KsVideoAdManager
.
Companion
.
getInstance
();
mhVideoAdManager
=
MhVideoAdManager
.
Companion
.
getInstance
();
weightList
=
new
ArrayList
<>();
weightList
=
new
ArrayList
<>();
}
}
...
@@ -136,6 +139,7 @@ public class VideoAdingManager {
...
@@ -136,6 +139,7 @@ public class VideoAdingManager {
this
.
csjVideoWeight
=
csjVideoWeight
;
this
.
csjVideoWeight
=
csjVideoWeight
;
this
.
ylhWeight
=
ylhWeight
;
this
.
ylhWeight
=
ylhWeight
;
this
.
wnWeight
=
wnWeight
;
this
.
wnWeight
=
wnWeight
;
this
.
flVideoWeight
=
flVideoWeight
;
this
.
shVideoWeight
=
shVideoWeight
;
this
.
shVideoWeight
=
shVideoWeight
;
this
.
csjFullVideoWeight
=
csjFullVideoWeight
;
this
.
csjFullVideoWeight
=
csjFullVideoWeight
;
this
.
ksVideoWeight
=
ksVideoWeight
;
this
.
ksVideoWeight
=
ksVideoWeight
;
...
@@ -295,6 +299,11 @@ public class VideoAdingManager {
...
@@ -295,6 +299,11 @@ public class VideoAdingManager {
weight
=
weight
+
wnWeight
;
weight
=
weight
+
wnWeight
;
LogUtil
.
d
(
TAG
,
"权重值:sdhzWeight:"
+
wnWeight
);
LogUtil
.
d
(
TAG
,
"权重值:sdhzWeight:"
+
wnWeight
);
}
}
if
(
AppConfig
.
flVideoAdCount
>
0
)
{
weightList
.
add
(
new
WeightBean
(
flVideoWeight
,
Constant
.
FL_VEDIO_AD
));
weight
=
weight
+
flVideoWeight
;
LogUtil
.
d
(
TAG
,
"权重值:flVideoWeight:"
+
flVideoWeight
);
}
// 权重随机
// 权重随机
if
(
weightList
!=
null
&&
weightList
.
size
()
>
0
&&
weight
>
0
)
{
if
(
weightList
!=
null
&&
weightList
.
size
()
>
0
&&
weight
>
0
)
{
...
@@ -373,13 +382,16 @@ public class VideoAdingManager {
...
@@ -373,13 +382,16 @@ public class VideoAdingManager {
shVideoAdManager
.
onDestroy
();
shVideoAdManager
.
onDestroy
();
shVideoAdManager
=
null
;
shVideoAdManager
=
null
;
}
}
if
(
mReceiverBroadcastReceiver
!=
null
)
{
if
(
mReceiverBroadcastReceiver
!=
null
)
{
activity
.
stopService
(
new
Intent
(
activity
,
AppInstallService
.
class
));
activity
.
stopService
(
new
Intent
(
activity
,
AppInstallService
.
class
));
activity
.
unregisterReceiver
(
mReceiverBroadcastReceiver
);
activity
.
unregisterReceiver
(
mReceiverBroadcastReceiver
);
mReceiverBroadcastReceiver
=
null
;
mReceiverBroadcastReceiver
=
null
;
}
}
if
(
mhVideoAdManager
!=
null
)
{
mhVideoAdManager
.
setVideoAdStatusListener
(
null
);
mhVideoAdManager
.
onDestroy
();
mhVideoAdManager
=
null
;
}
activity
=
null
;
activity
=
null
;
}
}
...
@@ -629,6 +641,43 @@ public class VideoAdingManager {
...
@@ -629,6 +641,43 @@ public class VideoAdingManager {
});
});
ksVideoAdManager
.
loadAd
(
activity
,
bean
.
getCurCoin
(),
bean
.
getCarrierType
(),
bean
.
getExtraId
());
ksVideoAdManager
.
loadAd
(
activity
,
bean
.
getCurCoin
(),
bean
.
getCarrierType
(),
bean
.
getExtraId
());
}
else
if
(
TextUtils
.
equals
(
videoAdType
,
Constant
.
FL_VEDIO_AD
))
{
// 枫岚广告激励视频
if
(
mhVideoAdManager
==
null
)
{
if
(
activity
==
null
)
{
if
(
videoAdingListener
!=
null
)
{
videoAdingListener
.
videoAdingListenerError
(
Constant
.
FL_VEDIO_AD
);
}
return
;
}
mhVideoAdManager
=
MhVideoAdManager
.
Companion
.
getInstance
();
}
mhVideoAdManager
.
setVideoAdStatusListener
(
new
VideoAdStatusListener
()
{
@Override
public
void
adSuccess
()
{
AppConfig
.
flVideoAdCount
--;
if
(
videoAdingListener
!=
null
)
{
videoAdingListener
.
videoAdingListenerSuccess
(
Constant
.
FL_VEDIO_AD
);
}
}
@Override
public
void
adFail
()
{
if
(
videoAdingListener
!=
null
)
{
videoAdingListener
.
videoAdingListenerFail
(
Constant
.
FL_VEDIO_AD
);
}
}
@Override
public
void
adDownload
()
{
isVideoAdDownload
=
true
;
// 注册下载任务监听
registerBroad
();
}
});
mhVideoAdManager
.
loadAd
(
activity
,
bean
.
getCurCoin
(),
bean
.
getCarrierType
(),
bean
.
getExtraId
());
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
app/src/main/java/com/wenshu/youyou/manager/MhManager.kt
View file @
ca0273d7
...
@@ -9,8 +9,8 @@ import com.maplehaze.adsdk.MaplehazeSDK
...
@@ -9,8 +9,8 @@ import com.maplehaze.adsdk.MaplehazeSDK
*/
*/
object
MhManager
{
object
MhManager
{
const
val
APP_ID
=
""
const
val
APP_ID
=
"
10230
"
const
val
POS_ID
=
""
const
val
POS_ID
=
"
56930
"
/**
/**
* 初始化
* 初始化
...
...
app/src/main/java/com/wenshu/youyou/manager/TrackManager.java
View file @
ca0273d7
...
@@ -133,4 +133,10 @@ public class TrackManager {
...
@@ -133,4 +133,10 @@ public class TrackManager {
trackPresenter
.
reportAddCoinMsg
(
activity
,
vo
);
trackPresenter
.
reportAddCoinMsg
(
activity
,
vo
);
}
}
}
}
public
void
reportErrornterface
(
String
url
,
String
request
)
{
if
(
trackPresenter
!=
null
)
{
trackPresenter
.
reportErrornterface
(
url
,
request
);
}
}
}
}
app/src/main/java/com/wenshu/youyou/mvp/presenters/TrackPresenter.java
View file @
ca0273d7
...
@@ -304,4 +304,26 @@ public class TrackPresenter extends BaseTrackPresenter {
...
@@ -304,4 +304,26 @@ public class TrackPresenter extends BaseTrackPresenter {
}
}
});
});
}
}
public
void
reportErrornterface
(
String
url
,
String
request
)
{
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"url"
,
url
);
vo
.
put
(
"request"
,
request
);
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
reportErrornterface
(
vo
),
new
BaseSubscriber
<
BaseResponse
<
JsonObject
>>()
{
@Override
public
void
onCompleted
()
{
}
@Override
public
void
onError
(
Throwable
e
)
{
}
@Override
public
void
onNext
(
BaseResponse
<
JsonObject
>
baseResponse
)
{
}
});
}
}
}
app/src/main/java/com/wenshu/youyou/net/LoanService.java
View file @
ca0273d7
...
@@ -638,6 +638,14 @@ public interface LoanService {
...
@@ -638,6 +638,14 @@ public interface LoanService {
@POST
(
"na/getAdcodesInOpenApp"
)
@POST
(
"na/getAdcodesInOpenApp"
)
Observable
<
BaseResponse
<
CodeBean
>>
getAdcodesInOpenApp
();
Observable
<
BaseResponse
<
CodeBean
>>
getAdcodesInOpenApp
();
/**
* 临时使用-接口加密异常时调用
*
* @return
*/
@POST
(
"common/reportErrornterface"
)
Observable
<
BaseResponse
<
JsonObject
>>
reportErrornterface
(
@Body
Map
<
String
,
Object
>
vo
);
/**
/**
* 默认http工厂
* 默认http工厂
...
...
app/src/main/java/com/wenshu/youyou/net/OkHttpInterceptor.java
View file @
ca0273d7
...
@@ -6,14 +6,19 @@ import com.bytedance.hume.readapk.HumeSDK;
...
@@ -6,14 +6,19 @@ import com.bytedance.hume.readapk.HumeSDK;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.wenshu.youyou.BuildConfig
;
import
com.wenshu.youyou.BuildConfig
;
import
com.wenshu.youyou.WenshuApplication
;
import
com.wenshu.youyou.WenshuApplication
;
import
com.wenshu.youyou.manager.TrackManager
;
import
com.wenshu.youyou.manager.UserManager
;
import
com.wenshu.youyou.manager.UserManager
;
import
com.wenshu.youyou.mvp.model.AppRequest
;
import
com.wenshu.youyou.mvp.model.AppRequest
;
import
com.wenshu.youyou.utils.AESUtils
;
import
com.wenshu.youyou.utils.AESUtils
;
import
com.wenshu.youyou.utils.Base64
;
import
com.wenshu.youyou.utils.Base64
;
import
com.wenshu.youyou.utils.LogUtil
;
import
com.wenshu.youyou.utils.MD5
;
import
com.wenshu.youyou.utils.MD5
;
import
com.wenshu.library.utils.CommonUtils
;
import
com.wenshu.library.utils.CommonUtils
;
import
org.json.JSONObject
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
okhttp3.Interceptor
;
import
okhttp3.Interceptor
;
...
@@ -22,6 +27,9 @@ import okhttp3.MultipartBody;
...
@@ -22,6 +27,9 @@ import okhttp3.MultipartBody;
import
okhttp3.Request
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
import
okhttp3.Response
;
import
okhttp3.ResponseBody
;
import
okio.Buffer
;
import
okio.BufferedSource
;
/**
/**
* 用拦截器对传输数据加密
* 用拦截器对传输数据加密
...
@@ -41,9 +49,26 @@ public class OkHttpInterceptor implements Interceptor {
...
@@ -41,9 +49,26 @@ public class OkHttpInterceptor implements Interceptor {
@Override
@Override
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
String
tokenID
=
UserManager
.
getInstance
().
getTokenID
();
String
tokenID
=
UserManager
.
getInstance
().
getTokenID
();
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
String
channel
=
createChannel
();
Request
request
=
chain
.
request
();
// 加密
request
=
encrypt
(
request
,
tokenID
,
time
,
channel
);
// header
Request
builder
=
addHeader
(
request
,
tokenID
,
time
,
channel
);
// 解密
Response
response
=
chain
.
proceed
(
builder
);
response
=
decrypt
(
response
);
return
response
;
}
/**
* 创建渠道
*
* @return
*/
private
String
createChannel
()
{
String
channel
=
CommonUtils
.
getAppMetaData
(
WenshuApplication
.
getContext
(),
"CHANNEL_NAME"
);
String
channel
=
CommonUtils
.
getAppMetaData
(
WenshuApplication
.
getContext
(),
"CHANNEL_NAME"
);
try
{
try
{
// 穿山甲分包渠道
// 穿山甲分包渠道
...
@@ -55,31 +80,39 @@ public class OkHttpInterceptor implements Interceptor {
...
@@ -55,31 +80,39 @@ public class OkHttpInterceptor implements Interceptor {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
channel
;
}
Request
request
=
chain
.
request
();
/**
request
=
encrypt
(
request
,
tokenID
,
time
,
channel
);
//加密方法
* 添加header
Request
builder
=
request
.
newBuilder
().
*
* @param request
* @param tokenID
* @param time
* @param channel
* @return
*/
private
Request
addHeader
(
Request
request
,
String
tokenID
,
long
time
,
String
channel
)
throws
UnsupportedEncodingException
{
return
request
.
newBuilder
().
addHeader
(
"version"
,
BuildConfig
.
VERSION_NAME
).
addHeader
(
"version"
,
BuildConfig
.
VERSION_NAME
).
addHeader
(
"token"
,
tokenID
).
addHeader
(
"token"
,
tokenID
).
addHeader
(
"channel"
,
channel
).
addHeader
(
"channel"
,
channel
).
addHeader
(
"new-session"
,
MD5
.
GetMD5Code
(
String
.
valueOf
(
time
))).
addHeader
(
"new-session"
,
MD5
.
GetMD5Code
(
String
.
valueOf
(
time
))).
addHeader
(
"last-session"
,
Base64
.
encode
(
String
.
valueOf
(
time
).
getBytes
(
"UTF-8"
))).
addHeader
(
"last-session"
,
Base64
.
encode
(
String
.
valueOf
(
time
).
getBytes
(
"UTF-8"
))).
build
();
build
();
return
chain
.
proceed
(
builder
);
}
}
// json加密
/**
* json加密
*
* @param request
* @param tokenID
* @param time
* @param channel
* @return
* @throws IOException
*/
private
Request
encrypt
(
Request
request
,
String
tokenID
,
long
time
,
String
channel
)
throws
IOException
{
private
Request
encrypt
(
Request
request
,
String
tokenID
,
long
time
,
String
channel
)
throws
IOException
{
//这个是请求的url,也就是咱们前面配置的baseUrl
String
url
=
request
.
url
().
toString
();
//是否加密标识
boolean
isSign
=
true
;
if
(!
TextUtils
.
isEmpty
(
url
))
{
isSign
=
!
url
.
contains
(
"common/"
);
}
//获取请求body,只有@Body 参数的requestBody 才不会为 null
//获取请求body,只有@Body 参数的requestBody 才不会为 null
RequestBody
requestBody
=
request
.
body
();
RequestBody
requestBody
=
request
.
body
();
if
(
requestBody
!=
null
)
{
if
(
requestBody
!=
null
)
{
...
@@ -96,7 +129,7 @@ public class OkHttpInterceptor implements Interceptor {
...
@@ -96,7 +129,7 @@ public class OkHttpInterceptor implements Interceptor {
String
checkStr
=
valueStr
;
String
checkStr
=
valueStr
;
//加密
//加密
if
(
isSign
&&
!
TextUtils
.
isEmpty
(
valueStr
))
{
if
(
isSign
(
request
)
&&
!
TextUtils
.
isEmpty
(
valueStr
))
{
valueStr
=
AESUtils
.
encrypt
(
valueStr
,
aesKey
);
valueStr
=
AESUtils
.
encrypt
(
valueStr
,
aesKey
);
}
}
...
@@ -123,25 +156,62 @@ public class OkHttpInterceptor implements Interceptor {
...
@@ -123,25 +156,62 @@ public class OkHttpInterceptor implements Interceptor {
return
request
;
return
request
;
}
}
// json解密
// private Response decrypt(Response response) throws IOException {
/**
// if (response.isSuccessful()) {
* json解密
// //the response data
*
// ResponseBody body = response.body();
* @param response
// BufferedSource source = body.source();
* @return
// source.request(Long.MAX_VALUE); // Buffer the entire body.
* @throws IOException
// Buffer buffer = source.buffer();
*/
// Charset charset = Charset.defaultCharset();
private
Response
decrypt
(
Response
response
)
throws
IOException
{
// MediaType contentType = body.contentType();
if
(
response
.
isSuccessful
()
&&
isSign
(
response
.
request
()))
{
// if (contentType != null) {
//the response data
// charset = contentType.charset(charset);
ResponseBody
body
=
response
.
body
();
// }
BufferedSource
source
=
body
.
source
();
// String string = buffer.clone().readString(charset);
source
.
request
(
Long
.
MAX_VALUE
);
// Buffer the entire body.
// //解密方法,需要自己去实现
Buffer
buffer
=
source
.
buffer
();
// String bodyString = AESUtils.decrypt(string, aesKey);
Charset
charset
=
Charset
.
defaultCharset
();
// ResponseBody responseBody = ResponseBody.create(contentType, bodyString);
MediaType
contentType
=
body
.
contentType
();
// response = response.newBuilder().body(responseBody).build();
if
(
contentType
!=
null
)
{
// }
charset
=
contentType
.
charset
(
charset
);
// return response;
}
// }
String
rspString
=
buffer
.
clone
().
readString
(
charset
);
// 解密
try
{
JSONObject
json
=
new
JSONObject
(
rspString
);
if
(!
json
.
isNull
(
"data"
))
{
Object
data
=
json
.
get
(
"data"
);
rspString
=
AESUtils
.
detrypt
(
data
.
toString
(),
aesKey
);
JSONObject
jsonArray
=
new
JSONObject
(
rspString
);
json
.
put
(
"data"
,
jsonArray
);
rspString
=
json
.
toString
();
// rspString = json.toString().replace("\\", "");
}
}
catch
(
Exception
e
)
{
LogUtil
.
d
(
"OkHttpInterceptor"
,
"json解密失败。url:"
+
response
.
request
().
url
().
toString
()
+
"\n\n 响应报文:"
+
buffer
.
clone
().
readString
(
charset
));
TrackManager
.
getInstance
().
reportErrornterface
(
response
.
request
().
url
().
toString
(),
buffer
.
clone
().
readString
(
charset
));
e
.
printStackTrace
();
}
ResponseBody
responseBody
=
ResponseBody
.
create
(
contentType
,
rspString
);
response
=
response
.
newBuilder
().
body
(
responseBody
).
build
();
}
return
response
;
}
/**
* 是否加/解密 - 接口非common都加/解密
*
* @param request
* @return true=加/解密
*/
private
boolean
isSign
(
Request
request
)
{
String
url
=
request
.
url
().
toString
();
//是否加密标识
boolean
isSign
=
true
;
if
(!
TextUtils
.
isEmpty
(
url
))
{
isSign
=
!
url
.
contains
(
"common/"
);
}
return
isSign
;
}
}
}
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