parent
bff2d327b2
commit
738fb2fe33
|
|
@ -2,10 +2,23 @@ import org.gradle.kotlin.dsl.api
|
|||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("com.batiao.batiaosdkbuilder") version "1.0.398"
|
||||
alias(libs.plugins.compose.compiler)
|
||||
kotlin("plugin.serialization") version "2.3.0"
|
||||
}
|
||||
|
||||
batiaoSdkConfig {
|
||||
// 业务 API 显式挂载 SignInterceptor;全局注入会修改图片/WGT 等下载 URL。
|
||||
// BatiaoUnimp 自带 SignInterceptor,不依赖全局注入。
|
||||
enableHttpAuth = false
|
||||
unimp = true
|
||||
// 与 weiquan-android 一致,只在用户同意隐私协议后初始化。
|
||||
applicationHookMethod = "initializeBatiaoAfterConsent"
|
||||
sdkVersion = "1.0.398"
|
||||
prop("signKey", "xn08hYoizXhZ1zHP8DVqfCm2yHxPmhil")
|
||||
prop("decodeKey", "e4rOtnF8tJjtHO7ecZeJHN1rapED5ImB")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.img.rabbit"
|
||||
compileSdk = 37
|
||||
|
|
@ -49,7 +62,8 @@ android {
|
|||
}
|
||||
|
||||
ndk {
|
||||
abiFilters.addAll(listOf("arm64-v8a", "x86_64", "x86", "armeabi-v7a"))
|
||||
// Batiao 1.0.398 仅提供 arm64-v8a 的原生库。
|
||||
abiFilters.add("arm64-v8a")
|
||||
}
|
||||
|
||||
// 仅保留基础占位符,渠道相关的移至下方 flavor 处理
|
||||
|
|
@ -256,4 +270,4 @@ dependencies {
|
|||
implementation(libs.androidx.webkit) //4.45版本之后 必须集成,用来支持暗黑模式
|
||||
implementation(libs.androidx.legacy.support.v4)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.lang.Exception
|
|||
|
||||
class BaseApplication : Application() {
|
||||
private val TAG = "BaseApplication"
|
||||
private var batiaoInitialized = false
|
||||
private var uniAppInitialized = false
|
||||
private var uniAppOaid: String? = null
|
||||
|
||||
|
|
@ -57,9 +58,14 @@ class BaseApplication : Application() {
|
|||
/**
|
||||
* 隐私同意即可初始化
|
||||
*/
|
||||
@Synchronized
|
||||
fun initThirdParty(){
|
||||
//需要在隐私框架下才能处理的逻辑
|
||||
if(PreferenceUtil.getAgreement()){
|
||||
if (!batiaoInitialized) {
|
||||
initializeBatiaoAfterConsent()
|
||||
batiaoInitialized = true
|
||||
}
|
||||
Log.i(TAG, "用户已同意隐私政策,开始初始化第三方服务")
|
||||
// 初始化网络状态监控
|
||||
NetworkMonitor.initialize(this)
|
||||
|
|
@ -72,6 +78,10 @@ class BaseApplication : Application() {
|
|||
}
|
||||
}
|
||||
|
||||
// Batiao 构建插件只向此方法注入初始化,调用前必须检查隐私协议。
|
||||
private fun initializeBatiaoAfterConsent() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化友盟
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -100,21 +100,23 @@ fun HomeBanner(
|
|||
) { onClick(item) },
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.BottomCenter)
|
||||
// 下方内容有 18dp 的圆角重叠区,圆点放在其上方。
|
||||
.padding(bottom = 30.dp)
|
||||
.background(Color.Black.copy(alpha = 0.15f), CircleShape)
|
||||
.padding(horizontal = 8.dp, vertical = 6.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) {
|
||||
repeat(count) { index ->
|
||||
Box(
|
||||
modifier = Modifier.size(6.dp).background(
|
||||
if (pagerState.currentPage % count == index) Color.White else Color.White.copy(alpha = 0.45f),
|
||||
CircleShape,
|
||||
if (count > 1) {
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.BottomCenter)
|
||||
// 下方内容有 18dp 的圆角重叠区,圆点放在其上方。
|
||||
.padding(bottom = 30.dp)
|
||||
.background(Color.Black.copy(alpha = 0.15f), CircleShape)
|
||||
.padding(horizontal = 8.dp, vertical = 6.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) {
|
||||
repeat(count) { index ->
|
||||
Box(
|
||||
modifier = Modifier.size(6.dp).background(
|
||||
if (pagerState.currentPage % count == index) Color.White else Color.White.copy(alpha = 0.45f),
|
||||
CircleShape,
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
package com.img.rabbit.provider.api
|
||||
|
||||
import com.batiao.batiaosdk.SignInterceptor
|
||||
import com.img.rabbit.BuildConfig
|
||||
import com.img.rabbit.config.Constants
|
||||
import com.img.rabbit.provider.utils.HeaderInterceptor
|
||||
import com.img.rabbit.provider.utils.RequestInterceptor
|
||||
import com.img.rabbit.provider.utils.ResponseInterceptor
|
||||
import com.img.rabbit.provider.utils.getUnsafeOkHttpClient
|
||||
import com.img.rabbit.viewmodel.`interface`.ServiceVo
|
||||
|
|
@ -33,12 +33,13 @@ object ApiManager {
|
|||
}
|
||||
|
||||
if (!::retrofit.isInitialized) {
|
||||
val client = OkHttpClient().newBuilder()
|
||||
// 仅业务 API 使用 Batiao 签名和解密,资源下载保持原始 URL。
|
||||
val client = OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(20, TimeUnit.SECONDS)
|
||||
.writeTimeout(20, TimeUnit.SECONDS)
|
||||
.addInterceptor(RequestInterceptor())
|
||||
.addInterceptor(HeaderInterceptor())
|
||||
.addInterceptor(SignInterceptor)
|
||||
.build()
|
||||
|
||||
retrofit = Retrofit.Builder()
|
||||
|
|
@ -54,8 +55,8 @@ object ApiManager {
|
|||
.readTimeout(20, TimeUnit.SECONDS)
|
||||
.writeTimeout(20, TimeUnit.SECONDS)
|
||||
.addInterceptor(HeaderInterceptor())
|
||||
.addInterceptor(RequestInterceptor())
|
||||
.addInterceptor(ResponseInterceptor())
|
||||
.addInterceptor(SignInterceptor)
|
||||
.build()
|
||||
|
||||
unsafeRetrofit = Retrofit.Builder()
|
||||
|
|
@ -107,4 +108,4 @@ object ApiManager {
|
|||
// 重新初始化
|
||||
initialize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,85 +1,26 @@
|
|||
package com.img.rabbit.provider.utils
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import com.img.rabbit.BuildConfig
|
||||
import com.img.rabbit.config.Constants
|
||||
import com.img.rabbit.utils.AESpkcs7paddingUtil
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import org.json.JSONObject
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.charset.UnsupportedCharsetException
|
||||
|
||||
|
||||
/**
|
||||
* 解密数据
|
||||
*/
|
||||
/** 签名和解密由 Batiao SDK 处理,此处仅保留业务接口的 HTTP 400 兼容。 */
|
||||
class ResponseInterceptor : Interceptor {
|
||||
private val TAG = "Decode"
|
||||
private val baseUrl = (if (BuildConfig.DEBUG) Constants.DEBUG_BASE_URL else Constants.RELEASE_BASE_URL).toHttpUrl()
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
val url = request.url
|
||||
val apiPath = String.format("%s", url)
|
||||
val baseUrl = if (BuildConfig.DEBUG) {
|
||||
Constants.DEBUG_BASE_URL
|
||||
} else {
|
||||
Constants.RELEASE_BASE_URL
|
||||
}
|
||||
//如果请求的不是服务端的接口则不用加密
|
||||
if (!apiPath.startsWith(baseUrl)) {
|
||||
return chain.proceed(request)
|
||||
}
|
||||
val response = chain.proceed(request)
|
||||
var charset = Charset.forName("UTF-8")
|
||||
val contentType = response.header("Content-Type")
|
||||
if (contentType != null && contentType.contains("application/json")) {
|
||||
val responseBody = response.body
|
||||
val source = responseBody.source()
|
||||
source.request(Long.MAX_VALUE)
|
||||
val buffer = source.buffer
|
||||
val mediaType = responseBody.contentType()
|
||||
if (mediaType != null) {
|
||||
try {
|
||||
charset = mediaType.charset(Charset.forName("UTF-8"))
|
||||
} catch (e: UnsupportedCharsetException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
val respBody = buffer.clone().readString(charset!!)
|
||||
Log.w(TAG, "response=${respBody}")
|
||||
if (TextUtils.isEmpty(respBody)) {
|
||||
val responseCode = if (response.code == 400) 200 else response.code //兼容某些接口400的情况
|
||||
return response.newBuilder().code(responseCode).body(responseBody).build()
|
||||
}
|
||||
|
||||
val isEncrypt = JSONObject(respBody).optBoolean("encrypt")
|
||||
Log.w(TAG, "是否需要解密:$isEncrypt")
|
||||
if (!isEncrypt) { //如果不需要加密 直接返回
|
||||
Log.w(TAG, "response=${response.body}")
|
||||
val responseCode = if (response.code == 400) 200 else response.code //兼容某些接口400的情况
|
||||
return response.newBuilder().code(responseCode).body(responseBody).build()
|
||||
}
|
||||
val decrybody = JSONObject(respBody).optString("data")
|
||||
Log.w(TAG, "Json解析后的字符串为---->$decrybody")
|
||||
var decryString: String?
|
||||
try {
|
||||
decryString = AESpkcs7paddingUtil.decryptNormal(decrybody, Constants.AESDecrypt)
|
||||
Log.w("ResponseInterceptor", "解密后返回的字符串为---->$decryString")
|
||||
|
||||
//这里可以通过code处理token过去过期的情况
|
||||
//val decCode = JSONObject(decryString).optInt("code")
|
||||
|
||||
//返回新创建的response
|
||||
val responseCode = if (response.code == 400 && decrybody != null) 200 else response.code //兼容某些接口400的情况
|
||||
return response.newBuilder().code(responseCode).body(decryString.toResponseBody("text/plain".toMediaType())).build()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
val isBackend = request.url.scheme == baseUrl.scheme &&
|
||||
request.url.host == baseUrl.host && request.url.port == baseUrl.port
|
||||
return if (isBackend && response.code == 400 &&
|
||||
response.header("Content-Type").orEmpty().contains("application/json", ignoreCase = true)
|
||||
) {
|
||||
response.newBuilder().code(200).build()
|
||||
} else {
|
||||
response
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.content.pm.PackageManager
|
||||
import android.text.TextUtils
|
||||
import com.alibaba.fastjson.JSON
|
||||
import com.batiao.batiaosdk.PackageSpliter
|
||||
import com.bytedance.hume.readapk.HumeSDK
|
||||
import com.img.rabbit.BuildConfig
|
||||
import com.img.rabbit.utils.appwalle.ChannelReader
|
||||
|
|
@ -37,7 +38,8 @@ object ChannelUtils {
|
|||
if (!TextUtils.isEmpty(juliang)) {
|
||||
return juliang
|
||||
}
|
||||
return channel(context)
|
||||
// 保留 Rabbit 的渠道命名和 manifest 兜底,优先读取 Batiao 分包渠道。
|
||||
return PackageSpliter.getBatiaoChannel(channel(context))
|
||||
}
|
||||
|
||||
private fun channel(context: Context): String {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import com.batiao.batiaosdk.unimp.BatiaoUnimp
|
||||
import com.github.gzuliyujiang.oaid.DeviceIdentifier
|
||||
import com.img.rabbit.BuildConfig
|
||||
import com.img.rabbit.bean.request.ReportKey
|
||||
|
|
@ -83,6 +84,7 @@ object UniAppUtils {
|
|||
if (isBusy(uniMpId)) return false
|
||||
return try {
|
||||
val mp = _uniMpFlow.value[uniMpId] ?: return false
|
||||
refreshUniMpHeaders()
|
||||
if ((mp.isRuning || mp.isRunning) && mp.showUniMP()) {
|
||||
mp.sendUniMPEvent("jump", pagePath)
|
||||
true
|
||||
|
|
@ -298,21 +300,32 @@ object UniAppUtils {
|
|||
UniMPOpenConfiguration().apply {
|
||||
path = pagePath
|
||||
splashClass = if (uniType == "alipay") UniMPAlipaySplashView::class.java else UniMPWxSplashView::class.java
|
||||
extraData.put("x-token", PreferenceUtil.getXToken().orEmpty())
|
||||
extraData.put("x-version", getAppVersionName().orEmpty())
|
||||
extraData.put("x-platform", "android")
|
||||
extraData.put("x-device-id", DeviceIdentifier.getAndroidID(applicationContext))
|
||||
extraData.put("x-mobile-brand", android.os.Build.BRAND)
|
||||
extraData.put("x-mobile-model", android.os.Build.MODEL)
|
||||
extraData.put("x-channel", ChannelUtils.getChannel(applicationContext))
|
||||
extraData.put("x-package", BuildConfig.APPLICATION_ID)
|
||||
extraData.put("x-click-id", ChannelUtils.getBdVid(applicationContext))
|
||||
// 同时保留 extraData,兼容尚未使用 Batiao 网络桥接的旧版小程序。
|
||||
refreshUniMpHeaders().forEach { (key, value) -> extraData.put(key, value) }
|
||||
extraData.put("host", "${Constants.RELEASE_BASE_URL.trimEnd('/')}/")
|
||||
extraData.put("decrypt", Constants.AESDecrypt)
|
||||
extraData.put("encrypt", Constants.Signature)
|
||||
extraData.put("isCombo", "ok")
|
||||
}
|
||||
|
||||
private fun refreshUniMpHeaders(): Map<String, String> {
|
||||
val headers = linkedMapOf(
|
||||
"x-token" to PreferenceUtil.getXToken().orEmpty(),
|
||||
"x-version" to getAppVersionName().orEmpty(),
|
||||
"x-platform" to "android",
|
||||
"x-device-id" to DeviceIdentifier.getAndroidID(applicationContext).orEmpty(),
|
||||
"x-mobile-brand" to android.os.Build.BRAND,
|
||||
"x-mobile-model" to android.os.Build.MODEL,
|
||||
"x-channel" to ChannelUtils.getChannel(applicationContext),
|
||||
"x-package" to BuildConfig.APPLICATION_ID,
|
||||
"x-click-id" to ChannelUtils.getBdVid(applicationContext).orEmpty(),
|
||||
"x-base-version" to getAppVersionName().orEmpty(),
|
||||
"x-app-id" to Constants.AppId,
|
||||
)
|
||||
BatiaoUnimp.setHeaders(headers)
|
||||
return headers
|
||||
}
|
||||
|
||||
fun startUniPay(api: IWXAPI, weixinMpOriId: String, outTradeNo: String) {
|
||||
val request = WXLaunchMiniProgram.Req().apply {
|
||||
userName = weixinMpOriId
|
||||
|
|
|
|||
|
|
@ -1,5 +1,23 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = "batiao"
|
||||
url = uri("http://proxy.local:7777/repository/maven-releases/")
|
||||
isAllowInsecureProtocol = true
|
||||
content { includeGroup("com.batiao") }
|
||||
credentials {
|
||||
val local = java.util.Properties().apply {
|
||||
val propertiesFile = file("local.properties")
|
||||
if (propertiesFile.exists()) propertiesFile.inputStream().use { load(it) }
|
||||
}
|
||||
username = providers.gradleProperty("BATIAO_MAVEN_USERNAME")
|
||||
.orElse(providers.environmentVariable("BATIAO_MAVEN_USERNAME"))
|
||||
.orNull ?: local.getProperty("BATIAO_MAVEN_USERNAME")
|
||||
password = providers.gradleProperty("BATIAO_MAVEN_PASSWORD")
|
||||
.orElse(providers.environmentVariable("BATIAO_MAVEN_PASSWORD"))
|
||||
.orNull ?: local.getProperty("BATIAO_MAVEN_PASSWORD")
|
||||
}
|
||||
}
|
||||
google {
|
||||
content {
|
||||
includeGroupByRegex("com\\.android.*")
|
||||
|
|
@ -14,11 +32,36 @@ pluginManagement {
|
|||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id == "com.batiao.batiaosdkbuilder") {
|
||||
useModule("com.batiao:batiao-sdk-builder:${requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Suppress("UnstableApiUsage")
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
maven {
|
||||
name = "batiao"
|
||||
url = uri("http://proxy.local:7777/repository/maven-releases/")
|
||||
isAllowInsecureProtocol = true
|
||||
content { includeGroup("com.batiao") }
|
||||
credentials {
|
||||
val local = java.util.Properties().apply {
|
||||
val propertiesFile = file("local.properties")
|
||||
if (propertiesFile.exists()) propertiesFile.inputStream().use { load(it) }
|
||||
}
|
||||
username = providers.gradleProperty("BATIAO_MAVEN_USERNAME")
|
||||
.orElse(providers.environmentVariable("BATIAO_MAVEN_USERNAME"))
|
||||
.orNull ?: local.getProperty("BATIAO_MAVEN_USERNAME")
|
||||
password = providers.gradleProperty("BATIAO_MAVEN_PASSWORD")
|
||||
.orElse(providers.environmentVariable("BATIAO_MAVEN_PASSWORD"))
|
||||
.orNull ?: local.getProperty("BATIAO_MAVEN_PASSWORD")
|
||||
}
|
||||
}
|
||||
google()
|
||||
mavenCentral()
|
||||
flatDir {
|
||||
|
|
|
|||
Loading…
Reference in New Issue