|
@@ -4,20 +4,20 @@ import android.app.Activity
|
|
|
import android.app.Application
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
-import cn.yyxx.eyuancomm.base.SdkDrive
|
|
|
-import cn.yyxx.eyuancomm.base.entity.Function
|
|
|
-import cn.yyxx.eyuancomm.base.entity.SdkChargeInfo
|
|
|
-import cn.yyxx.eyuancomm.base.entity.SdkEvent
|
|
|
-import cn.yyxx.eyuancomm.base.entity.SdkRoleInfo
|
|
|
-import cn.yyxx.eyuancomm.base.internal.ICallback
|
|
|
-import cn.yyxx.eyuancomm.base.ui.dialog.ScaleLoadingDialog
|
|
|
-import cn.yyxx.eyuancomm.base.utils.Logger
|
|
|
-import cn.yyxx.eyuancomm.comm.entity.SdkLoginInfo
|
|
|
+import android.text.TextUtils
|
|
|
+import cn.yyxx.eyuancomm.comm.entity.*
|
|
|
+import cn.yyxx.eyuancomm.comm.entity.Function
|
|
|
+import cn.yyxx.eyuancomm.comm.internal.ICallback
|
|
|
import cn.yyxx.eyuancomm.comm.network.Host
|
|
|
import cn.yyxx.eyuancomm.comm.network.SdkRequest
|
|
|
+import cn.yyxx.eyuancomm.comm.utils.Logger
|
|
|
+import cn.yyxx.eyuancomm.comm.utils.ParamsUtils
|
|
|
+import cn.yyxx.eyuancomm.comm.widget.ScaleLoadingDialog
|
|
|
+import cn.yyxx.support.JsonUtils
|
|
|
import cn.yyxx.support.device.DeviceInfoUtils
|
|
|
import cn.yyxx.support.gaid.GAIDUtils
|
|
|
import cn.yyxx.support.msa.MsaDeviceIdsHandler
|
|
|
+import org.json.JSONObject
|
|
|
import java.util.concurrent.atomic.AtomicInteger
|
|
|
|
|
|
/**
|
|
@@ -32,19 +32,20 @@ class CommSdkImpl(context: Context) {
|
|
|
private var hasReadDeviceId = false
|
|
|
private var channelId: String = ""
|
|
|
|
|
|
- private var initDialog: ScaleLoadingDialog? = null
|
|
|
-
|
|
|
+ private var initLoadingDialog: ScaleLoadingDialog? = null
|
|
|
+ private var payLoadingDialog: ScaleLoadingDialog? = null
|
|
|
|
|
|
@Volatile
|
|
|
private var timeCount = AtomicInteger(0)
|
|
|
|
|
|
init {
|
|
|
+ channelId = ParamsUtils.getChannelId(context)
|
|
|
getSdkProxyManager(context)
|
|
|
}
|
|
|
|
|
|
private fun getSdkProxyManager(context: Context): Any? {
|
|
|
if (mSdkProxy == null) {
|
|
|
- mSdkProxy = SdkProxyManager.initSdkProxyManager(context)
|
|
|
+ mSdkProxy = SdkProxyManager.initSdkProxyManager(context, channelId)
|
|
|
}
|
|
|
return mSdkProxy
|
|
|
}
|
|
@@ -55,7 +56,7 @@ class CommSdkImpl(context: Context) {
|
|
|
fun attachBaseContext(application: Application, context: Context) {
|
|
|
Logger.initZap(application)
|
|
|
Logger.i("EYuanCommSdk attachBaseContext ...")
|
|
|
- SdkDrive.instance.initSdkDrive(application)
|
|
|
+ CommSdkDrive.instance.initSdkDrive(application)
|
|
|
initGaid(application)
|
|
|
|
|
|
if (mSdkProxy == null) {
|
|
@@ -73,7 +74,7 @@ class CommSdkImpl(context: Context) {
|
|
|
initOaid(application)
|
|
|
} else {
|
|
|
Logger.i("谷歌框架可以访问,请求gaid")
|
|
|
- SdkDrive.instance.setCommParam("device_id", GAIDUtils.getGoogleAdid())
|
|
|
+ CommSdkDrive.instance.setCommParam("device_id", GAIDUtils.getGoogleAdid())
|
|
|
hasReadDeviceId = true
|
|
|
}
|
|
|
} else {
|
|
@@ -87,10 +88,10 @@ class CommSdkImpl(context: Context) {
|
|
|
MsaDeviceIdsHandler.initMsaDeviceIds(application) { code, msg, _ ->
|
|
|
if (code == 0) {
|
|
|
Logger.e("获取oaid成功,使用oaid替代")
|
|
|
- SdkDrive.instance.setCommParam("device_id", MsaDeviceIdsHandler.oaid)
|
|
|
+ CommSdkDrive.instance.setCommParam("device_id", MsaDeviceIdsHandler.oaid)
|
|
|
} else {
|
|
|
Logger.d("获取oaid失败,msg: $msg,使用android id替代")
|
|
|
- SdkDrive.instance.setCommParam("device_id", DeviceInfoUtils.getAndroidDeviceId(application))
|
|
|
+ CommSdkDrive.instance.setCommParam("device_id", DeviceInfoUtils.getAndroidDeviceId(application))
|
|
|
}
|
|
|
hasReadDeviceId = true
|
|
|
}
|
|
@@ -127,7 +128,7 @@ class CommSdkImpl(context: Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- showInitDialog(activity)
|
|
|
+ showInitLoadingDialog(activity)
|
|
|
|
|
|
if (!hasReadDeviceId) {
|
|
|
Logger.e("还未完成deviceId加载,将延迟初始化")
|
|
@@ -158,7 +159,7 @@ class CommSdkImpl(context: Context) {
|
|
|
private fun startSdkInit(activity: Activity, isLandscape: Boolean, callback: ICallback) {
|
|
|
// 先渠道后融合,因为个别渠道需要在融合初始化接口透传数据
|
|
|
// 渠道Sdk初始化
|
|
|
- val channelInitCallback = object : ICallback {
|
|
|
+ val channelCallback = object : ICallback {
|
|
|
override fun onResult(code: Int, result: String) {
|
|
|
// 不管结果如何都不在这里回调cp
|
|
|
// 融合Sdk初始化
|
|
@@ -169,7 +170,7 @@ class CommSdkImpl(context: Context) {
|
|
|
SdkProxyManager.call(
|
|
|
Function.INITIALIZE,
|
|
|
arrayOf(Activity::class.java, Boolean::class.java, ICallback::class.java),
|
|
|
- arrayOf(activity, isLandscape, channelInitCallback)
|
|
|
+ arrayOf(activity, isLandscape, channelCallback)
|
|
|
)
|
|
|
}
|
|
|
|
|
@@ -177,9 +178,9 @@ class CommSdkImpl(context: Context) {
|
|
|
Logger.d("融合Sdk初始化...")
|
|
|
SdkRequest.instance.initSdk(activity, "") { resultInfo ->
|
|
|
hasSdkInit = resultInfo.code == 1
|
|
|
- initDialog?.apply {
|
|
|
+ initLoadingDialog?.apply {
|
|
|
dismiss()
|
|
|
- initDialog = null
|
|
|
+ initLoadingDialog = null
|
|
|
}
|
|
|
if (hasSdkInit) {
|
|
|
callback.onResult(0, "Sdk初始化成功")
|
|
@@ -203,21 +204,28 @@ class CommSdkImpl(context: Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- val loginCallback = object : ICallback {
|
|
|
+ val channelCallback = object : ICallback {
|
|
|
override fun onResult(code: Int, result: String) {
|
|
|
- callback.onResult(code, result)
|
|
|
+ if (code == 0) {
|
|
|
+ SdkRequest.instance.userVerify(activity, result) { resultInfo ->
|
|
|
+ if (resultInfo.code == 1) {
|
|
|
+ if (!TextUtils.isEmpty(resultInfo.data)) {
|
|
|
+ val jsonObject = JSONObject(resultInfo.data)
|
|
|
+ SdkLoginInfo.instance.userId = jsonObject.getString("uid")
|
|
|
+ SdkLoginInfo.instance.token = jsonObject.getString("token")
|
|
|
+ }
|
|
|
+ callback.onResult(0, SdkLoginInfo.instance.toJsonString())
|
|
|
+ } else {
|
|
|
+ callback.onResult(-1, resultInfo.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ callback.onResult(-1, result)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- SdkProxyManager.call(
|
|
|
- Function.LOGIN,
|
|
|
- arrayOf(
|
|
|
- Activity::
|
|
|
- class.java, ICallback::
|
|
|
- class.java
|
|
|
- ),
|
|
|
- arrayOf(activity, loginCallback)
|
|
|
- )
|
|
|
+ SdkProxyManager.call(Function.LOGIN, arrayOf(Activity::class.java, ICallback::class.java), arrayOf(activity, channelCallback))
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -242,10 +250,9 @@ class CommSdkImpl(context: Context) {
|
|
|
*
|
|
|
* @param activity Activity上下文
|
|
|
* @param chargeInfo 支付信息实体对象
|
|
|
- * @param isIab 是否内购
|
|
|
* @param callback 支付回调对象
|
|
|
*/
|
|
|
- fun charge(activity: Activity, chargeInfo: SdkChargeInfo, isIab: Boolean, callback: ICallback) {
|
|
|
+ fun charge(activity: Activity, chargeInfo: SdkChargeInfo, callback: ICallback) {
|
|
|
if (checkSdkProxyNull(Function.CHARGE, callback)) {
|
|
|
return
|
|
|
}
|
|
@@ -253,17 +260,56 @@ class CommSdkImpl(context: Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- val chargeCallback = object : ICallback {
|
|
|
- override fun onResult(code: Int, result: String) {
|
|
|
- callback.onResult(code, result)
|
|
|
- }
|
|
|
+ showPayLoadingDialog(activity)
|
|
|
+ // 判断渠道
|
|
|
+ if (channelId == ChannelId.YYXX) {
|
|
|
+ // 特殊渠道,先调用渠道sdk生成支付扩展参数,在请求生成订单
|
|
|
+ // 获取拿到channel_ext
|
|
|
+ SdkProxyManager.call(
|
|
|
+ Function.GET_ORDER_EXT,
|
|
|
+ arrayOf(Activity::class.java, SdkChargeInfo::class.java, ICallback::class.java),
|
|
|
+ arrayOf(activity, chargeInfo, object : ICallback {
|
|
|
+ override fun onResult(code: Int, result: String) {
|
|
|
+ if (code == 0 && !TextUtils.isEmpty(result)) {
|
|
|
+ chargeInfo.channelExt = result
|
|
|
+ doCharge(activity, chargeInfo, callback)
|
|
|
+ } else {
|
|
|
+ dimissPayLoadingDialog(activity)
|
|
|
+ callback.onResult(-1, result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ doCharge(activity, chargeInfo, callback)
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- SdkProxyManager.call(
|
|
|
- Function.CHARGE,
|
|
|
- arrayOf(Activity::class.java, SdkChargeInfo::class.java, Boolean::class.java, ICallback::class.java),
|
|
|
- arrayOf(activity, chargeInfo, isIab, chargeCallback)
|
|
|
- )
|
|
|
+ private fun doCharge(activity: Activity, chargeInfo: SdkChargeInfo, callback: ICallback) {
|
|
|
+ SdkRequest.instance.createOrder(activity, "", chargeInfo) { resultInfo ->
|
|
|
+ dimissPayLoadingDialog(activity)
|
|
|
+ if (resultInfo.code == 1 && !TextUtils.isEmpty(resultInfo.data)) {
|
|
|
+ val jsonObject = JSONObject(resultInfo.data)
|
|
|
+ chargeInfo.orderId = if (JsonUtils.hasJsonKey(jsonObject, "order_id")) {
|
|
|
+ jsonObject.getString("order_id")
|
|
|
+ } else {
|
|
|
+ ""
|
|
|
+ }
|
|
|
+ chargeInfo.channelNotifyUrl = if (JsonUtils.hasJsonKey(jsonObject, "notify_url")) {
|
|
|
+ jsonObject.getString("notify_url")
|
|
|
+ } else {
|
|
|
+ ""
|
|
|
+ }
|
|
|
+ // 调用渠道sdk支付
|
|
|
+ SdkProxyManager.call(
|
|
|
+ Function.CHARGE,
|
|
|
+ arrayOf(Activity::class.java, SdkChargeInfo::class.java, ICallback::class.java),
|
|
|
+ arrayOf(activity, chargeInfo, callback)
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ callback.onResult(-1, resultInfo.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -410,11 +456,7 @@ class CommSdkImpl(context: Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- SdkProxyManager.call(
|
|
|
- Function.ON_NEW_INTENT,
|
|
|
- arrayOf(Activity::class.java, Intent::class.java),
|
|
|
- arrayOf(activity, intent)
|
|
|
- )
|
|
|
+ SdkProxyManager.call(Function.ON_NEW_INTENT, arrayOf(Activity::class.java, Intent::class.java), arrayOf(activity, intent))
|
|
|
}
|
|
|
|
|
|
fun getCurrentUserId(): String = SdkLoginInfo.instance.userId
|
|
@@ -486,12 +528,28 @@ class CommSdkImpl(context: Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun showInitDialog(context: Context) {
|
|
|
- initDialog?.apply {
|
|
|
+ private fun showInitLoadingDialog(context: Context) {
|
|
|
+ initLoadingDialog?.apply {
|
|
|
+ dismiss()
|
|
|
+ initLoadingDialog = null
|
|
|
+ }
|
|
|
+ initLoadingDialog = ScaleLoadingDialog(context, "")
|
|
|
+ initLoadingDialog?.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showPayLoadingDialog(context: Context) {
|
|
|
+ payLoadingDialog?.apply {
|
|
|
+ dismiss()
|
|
|
+ payLoadingDialog = null
|
|
|
+ }
|
|
|
+ payLoadingDialog = ScaleLoadingDialog(context, "")
|
|
|
+ payLoadingDialog?.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun dimissPayLoadingDialog(context: Context) {
|
|
|
+ payLoadingDialog?.apply {
|
|
|
dismiss()
|
|
|
- initDialog = null
|
|
|
+ payLoadingDialog = null
|
|
|
}
|
|
|
- initDialog = ScaleLoadingDialog(context, "")
|
|
|
- initDialog?.show()
|
|
|
}
|
|
|
}
|