Commit 672b2865 authored by yinjiacheng's avatar yinjiacheng

update TowerPro通用配置数据获取迁移到BGeneralBusiness组件

parent 60eb2874
......@@ -32,6 +32,10 @@ class AppConfig {
const val TowerProXBridUpgradePlatformId = 32 // XBrid版本升级
const val TowerProPlatform = "Android"
// Tower Api域名定义
const val TowerApiDomainTest = "http://open-tower-api.test.int.yidian-inc.com:8222"
const val TowerApiDomainPro = "https://open-tower-api.go2yd.com"
// TowerPro 通用配置模块
const val TowerApiEnvTest = 0 // 测试环境
const val TowerApiEnvPro = 2 // 外网-正式环境
......
package com.yidian.bcommon.http
import com.google.gson.reflect.TypeToken
import com.yidian.bcommon.app.YdBaseApplication
import com.yidian.bcommon.constant.RunConfig
import com.yidian.bcommon.constant.AppConfig
import com.yidian.bcommon.http.bean.CommitFeedbackBean
import com.yidian.bcommon.http.bean.GetCommonConfigBean
import com.yidian.bcommon.http.bean.GetKSYunObjectIdBean
import com.yidian.bcommon.http.bean.GetKSYunTokenBean
import com.yidian.bcommon.http.callback.ICommitFeedbackCallback
import com.yidian.bcommon.http.callback.IGetCommonConfigCallback
import com.yidian.bcommon.http.callback.IGetKSYunObjectIdCallback
import com.yidian.http.ServiceFactory
import com.yidian.utils.ToastUtil
/**
* author: yinjiacheng
......@@ -21,82 +11,10 @@ import com.yidian.utils.ToastUtil
*/
object CommonDataSource {
// Tower-Api 域名
private val domainTowerApi by lazy {
if (RunConfig.TOWER_API_ENV == AppConfig.TowerApiEnvTest) {
CommonService.SCHEME_HTTP + CommonService.DOMAIN_TOWER_API_TEST
} else {
CommonService.SCHEME_HTTPS + CommonService.DOMAIN_TOWER_API_PRO
}
}
private val towerApi by lazy {
ServiceFactory.getInstance().createService(CommonService::class.java, domainTowerApi)
}
private val ydJiraApi by lazy {
ServiceFactory.getInstance().createService(CommonService::class.java, CommonService.SCHEME_HTTPS + CommonService.DOMAIN_YD_JIRA)
}
// 301 获取金山云token接口
fun getKSYunToken(requestParams: HashMap<String, String?>): HttpResult<GetKSYunTokenBean.Response>? {
val timeStamp = System.currentTimeMillis()
val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
val res: HttpResult<Any?>? = ServiceFactory.getInstance().createService(CommonService::class.java)
.getKSYunToken(publicParamsMap, privateParamsMap)
.execute().body()
if (res?.code == 0) {
return HttpParamsUtils.rsaDecryptResult(res, object : TypeToken<GetKSYunTokenBean.Response>() {}.type)
} else {
val decodeResult = HttpResult<GetKSYunTokenBean.Response>()
decodeResult.code = res?.code!!
decodeResult.reason = res.reason
decodeResult.status = res.status
ToastUtil.showToast(YdBaseApplication.context, res.reason)
}
return null
}
// 302 获取金山云ObjectId和Bucket接口
fun getKSYunObjectId(apiCallback: IGetKSYunObjectIdCallback, requestParams: HashMap<String, String?>) {
val timeStamp = System.currentTimeMillis()
val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
ServiceFactory.getInstance().createService(CommonService::class.java)
.getKSYunObjectId(publicParamsMap, privateParamsMap)
.compose(TransformUtil.defaultSchedulers())
.subscribe(object : HttpResultSubscriber<GetKSYunObjectIdBean.Response>() {
override fun onSuccess(result: HttpResult<GetKSYunObjectIdBean.Response>?) {
apiCallback.getKSYunObjectIdSuccess(result?.result)
}
override fun onFailure(result: HttpResult<GetKSYunObjectIdBean.Response>?) {
apiCallback.getKSYunObjectIdFailure(result?.reason)
}
})
}
// TowerPro 获取配置数据
fun getCommonConfig(apiCallback: IGetCommonConfigCallback, requestParams: HashMap<String, String>) {
towerApi
.getCommonConfig(requestParams)
.compose(TransformUtil.defaultSchedulers())
.subscribe(object : HttpResultObserver<GetCommonConfigBean.GetCommonConfigResponse>() {
override fun onSuccess(result: HttpResult<GetCommonConfigBean.GetCommonConfigResponse>?) {
apiCallback.getCommonConfigSuccess(result?.result)
}
override fun onFailure(result: HttpResult<GetCommonConfigBean.GetCommonConfigResponse>?) {
apiCallback.getCommonConfigFailure(result?.status)
}
override fun onNetworkFailure(result: HttpResult<GetCommonConfigBean.GetCommonConfigResponse>?) {
apiCallback.getCommonConfigFailure(result?.status)
}
})
}
// 用户反馈提交
fun commitFeedback(apiCallback: ICommitFeedbackCallback, requestParams: CommitFeedbackBean.CommitFeedbackRequest) {
ydJiraApi
......
package com.yidian.bcommon.http
import com.yidian.bcommon.http.bean.CommitFeedbackBean
import com.yidian.bcommon.http.bean.GetCommonConfigBean
import io.reactivex.rxjava3.core.Observable
import retrofit2.Call
import retrofit2.http.*
import retrofit2.http.Body
import retrofit2.http.Headers
import retrofit2.http.POST
/**
* author: yinjiacheng
......@@ -17,33 +17,13 @@ interface CommonService {
const val SCHEME_HTTP = "http://"
const val SCHEME_HTTPS = "https://"
// Tower Api域名定义
const val DOMAIN_TOWER_API_TEST = "open-tower-api.test.int.yidian-inc.com:8222"
const val DOMAIN_TOWER_API_PRO = "open-tower-api.go2yd.com"
// 一点jira域名定义
const val DOMAIN_YD_JIRA = "hub.go2yd.com"
// tower-api 获取配置数据
private const val getCommonConfig = "/api/resource"
// 用户反馈提交
private const val commitFeedback = "/feedback/save"
}
@Headers("Content-Type: application/json")
@POST(URLs.getKSYunToken)
fun getKSYunToken(@QueryMap commonParams: Map<String, String>, @Body requestParams: Map<String, String?>): Call<HttpResult<Any?>>
@GET(URLs.getKSYunObjectId)
fun getKSYunObjectId(
@QueryMap commonParams: Map<String, String>,
@QueryMap requestParams: Map<String, String?>
): Observable<HttpResult<Any?>>
@GET(getCommonConfig)
fun getCommonConfig(@QueryMap requestParams: Map<String, String>): Observable<HttpResult<GetCommonConfigBean.GetCommonConfigResponse>>
@Headers("Content-Type: application/json")
@POST(commitFeedback)
fun commitFeedback(@Body requestParams: CommitFeedbackBean.CommitFeedbackRequest): Observable<HttpResult<CommitFeedbackBean.CommitFeedbackResponse>>
......
......@@ -47,9 +47,11 @@ object BCommonManager {
*/
fun getUid(): String? {
var userId: String? = null
ZapTicket(ZapServiceNameConstants.ClientInfoService).withAction(ZapServiceActionConstants.ActionGetUserInfo).onResult {
userId = (it.result as JSONObject).optString("userId")
}.ship()
if (JudgeClientUtils.judgeClient(YdBaseApplication.context.packageName) == ClientType.MERCHANT_C) {
ZapTicket(ZapServiceNameConstants.ClientInfoService).withAction(ZapServiceActionConstants.ActionGetUserInfo).onResult {
userId = (it.result as JSONObject).optString("userId")
}.ship()
}
return userId
}
......
......@@ -45,5 +45,8 @@ class ZapServiceActionConstants {
// 延迟初始化
const val ActionLazyInit = "lazyInit"
// 获取TowerPro通用配置数据
const val ActionGetTowerProCommonConfig = "getTowerProCommonConfig"
}
}
package com.yidian.bcommon.utils
import android.content.Context
import android.util.Log
import com.google.gson.Gson
import com.ksyun.ks3.exception.Ks3Error
import com.ksyun.ks3.model.acl.CannedAccessControlList
import com.ksyun.ks3.services.AuthListener
import com.ksyun.ks3.services.Ks3Client
import com.ksyun.ks3.services.Ks3ClientConfiguration
import com.ksyun.ks3.services.handler.PutObjectACLResponseHandler
import com.ksyun.ks3.services.handler.PutObjectResponseHandler
import com.ksyun.ks3.services.request.PutObjectRequest
import com.yidian.bcommon.app.YdBaseApplication
import com.yidian.bcommon.http.CommonDataSource
import com.yidian.bcommon.http.bean.GetKSYunObjectIdBean
import com.yidian.bcommon.http.callback.IGetKSYunObjectIdCallback
import com.yidian.utils.MD5Util
import com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import cz.msebera.android.httpclient.Header
import java.io.File
/**
* author: yinjiacheng
* date: 5/20/21 11:08 AM
* description: 金山云存储
*/
class KS3Core private constructor(val context: Context) : AuthListener {
private val client by lazy { Ks3Client(this, context) }
private val gson by lazy { Gson() }
private val putObjectResponseHandler by lazy {
object : PutObjectResponseHandler() {
override fun onTaskProgress(progress: Double) {
// work thread
}
override fun onTaskFailure(
statesCode: Int,
error: Ks3Error?,
responceHeaders: Array<out Header>?,
response: String?,
throwable: Throwable?
) {
Log.e(
TAG,
"put object fail:, errorMsg: ${error?.errorMessage}"
)
}
override fun onTaskSuccess(statesCode: Int, responceHeaders: Array<out Header>?) {
Log.d(TAG, "put object success.")
}
override fun onTaskStart() {
}
override fun onTaskFinish() {
}
override fun onTaskCancel() {
}
}
}
private val putObjectACLResponseHandler by lazy {
object : PutObjectACLResponseHandler() {
override fun onSuccess(statesCode: Int, responceHeaders: Array<out Header>?) {
Log.d(TAG, "put object acl success.")
}
override fun onFailure(
statesCode: Int,
error: Ks3Error?,
responceHeaders: Array<out Header>?,
response: String?,
throwable: Throwable?
) {
Log.e(TAG, "put object acl fail:, errorMsg: ${error?.errorMessage}")
}
}
}
companion object {
const val TAG = "KS3Core"
const val DEFAULT_BUCKET_NAME = "bp-yidian"
const val DEFAULT_END_POINT = "ks3-cn-beijing.ksyun.com"
const val VIDEO_SUFFIX = ".mp4"
const val IMAGE_SUFFIX = ".jpg"
val INSTANCE: KS3Core by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
KS3Core(context = YdBaseApplication.context)
}
}
init {
setupClient()
}
/**
* 配置金山云client
*/
private fun setupClient() {
client.setConfiguration(Ks3ClientConfiguration.getDefaultConfiguration())
client.setEndpoint(DEFAULT_END_POINT)
}
/**
* 文件上传
* @param path 本地文件全路径
* @param type 文件类型
* @param scenario 业务场景
*/
fun uploadObject(
path: String,
type: ObjectType,
scenario: ScenarioType,
listener: OnKS3TaskListener
) {
CommonDataSource.getKSYunObjectId(object : IGetKSYunObjectIdCallback {
override fun getKSYunObjectIdSuccess(result: GetKSYunObjectIdBean.Response?) {
Log.d(
TAG,
"request getKSYun objectId success, objectId: ${result?.objectId}, bucket: ${result?.bucket}"
)
// 执行金山云上传
val request = PutObjectRequest(
result?.bucket,
result?.objectId + getObjectKeySuffix(type),
File(path)
)
request.cannedAcl = CannedAccessControlList.Private
client.putObject(
request,
KS3CorePutObjectResponseHandler(
result?.bucket,
result?.objectId + getObjectKeySuffix(type),
listener
)
)
}
override fun getKSYunObjectIdFailure(message: String?) {
Log.e(TAG, "request get KSYun objectId fail, message: $message")
}
}, hashMapOf(Pair("scenario", scenario.scenario)))
}
/**
* 文件上传
* @param path 本地文件全路径
* @param scenario 业务场景
*/
fun uploadObject(path: String, scenario: ScenarioType, listener: OnKS3TaskListener) {
CommonDataSource.getKSYunObjectId(object : IGetKSYunObjectIdCallback {
override fun getKSYunObjectIdSuccess(result: GetKSYunObjectIdBean.Response?) {
Log.d(
TAG,
"request getKSYun objectId success, objectId: ${result?.objectId}, bucket: ${result?.bucket}"
)
// 执行金山云上传
val request = PutObjectRequest(result?.bucket, result?.objectId, File(path))
request.cannedAcl = CannedAccessControlList.Private
client.putObject(
request,
KS3CorePutObjectResponseHandler(result?.bucket, result?.objectId, listener)
)
}
override fun getKSYunObjectIdFailure(message: String?) {
Log.e(TAG, "request get KSYun objectId fail, message: $message")
}
}, hashMapOf(Pair("scenario", scenario.scenario)))
}
/**
* 文件上传
* @param file 文件实体
* @param scenario 业务场景
*/
fun uploadObject(file: File, scenario: ScenarioType, listener: OnKS3TaskListener) {
CommonDataSource.getKSYunObjectId(object : IGetKSYunObjectIdCallback {
override fun getKSYunObjectIdSuccess(result: GetKSYunObjectIdBean.Response?) {
Log.d(
TAG,
"request getKSYun objectId success, objectId: ${result?.objectId}, bucket: ${result?.bucket}"
)
// 执行金山云上传
val request = PutObjectRequest(result?.bucket, result?.objectId, file)
request.cannedAcl = CannedAccessControlList.Private
client.putObject(
request,
KS3CorePutObjectResponseHandler(result?.bucket, result?.objectId, listener)
)
}
override fun getKSYunObjectIdFailure(message: String?) {
Log.e(TAG, "request get KSYun objectId fail, message: $message")
}
}, hashMapOf(Pair("scenario", scenario.scenario)))
}
/**
* 文件上传
* @param file 文件实体
* @param type 文件类型
* @param scenario 业务场景
*/
fun uploadObject(
file: File,
type: ObjectType,
scenario: ScenarioType,
listener: OnKS3TaskListener
) {
CommonDataSource.getKSYunObjectId(object : IGetKSYunObjectIdCallback {
override fun getKSYunObjectIdSuccess(result: GetKSYunObjectIdBean.Response?) {
Log.d(
TAG,
"request getKSYun objectId success, objectId: ${result?.objectId}, bucket: ${result?.bucket}"
)
// 执行金山云上传
val request = PutObjectRequest(
result?.bucket,
result?.objectId + getObjectKeySuffix(type),
file
)
request.cannedAcl = CannedAccessControlList.Private
client.putObject(
request,
KS3CorePutObjectResponseHandler(
result?.bucket,
result?.objectId + getObjectKeySuffix(type),
listener
)
)
}
override fun getKSYunObjectIdFailure(message: String?) {
Log.e(TAG, "request get KSYun objectId fail, message: $message")
}
}, hashMapOf(Pair("scenario", scenario.scenario)))
}
/**
* 获取ObjectKey后缀
*/
private fun getObjectKeySuffix(type: ObjectType): String {
return when (type) {
ObjectType.IMAGE -> IMAGE_SUFFIX
ObjectType.VIDEO -> VIDEO_SUFFIX
}
}
/**
* 本地生成ObjectKey
* 作为Object在云空间的唯一标识
*/
private fun getLocalObjectKey(name: String, type: ObjectType): String {
return MD5Util.md5Encrypt32Upper(name + FtDeviceFingerManager.getDeviceFinger()) +
if (type == ObjectType.VIDEO) VIDEO_SUFFIX else IMAGE_SUFFIX
}
/**
* 调用金山云API后 SDK会回调此函数用于获取必要参数向AppServer请求token
*/
override fun onCalculateAuth(
httpMethod: String,
contentType: String,
date: String,
contentMD5: String,
resource: String,
headers: String
): String? {
// 此处由APP端向业务服务器发送post请求返回Token
// 该回调方法运行在非主线程
Log.d(
TAG,
"KSYun calculate auth, httpMethod: $httpMethod, contentType: $contentType, date: $date, contentMD5: $contentMD5, resource: $resource, headers: $headers"
)
val requestParams = HashMap<String, String?>()
requestParams["http_method"] = httpMethod
requestParams["date"] = date
requestParams["resource"] = resource
requestParams["content_md5"] = contentMD5
requestParams["content_type"] = contentType
requestParams["headers"] = headers
return CommonDataSource.getKSYunToken(requestParams)?.result?.token
}
/**
* 业务监听
*/
interface OnKS3TaskListener {
fun onTaskStart()
fun onTaskProgress(progress: Double)
fun onTaskFinish()
fun onTaskCancel()
fun onTaskSuccess(bucket: String?, objectKey: String?)
fun onTaskFailure(statesCode: Int, message: String?)
}
/**
* 上传对象的类型
*/
enum class ObjectType {
VIDEO, IMAGE
}
/**
* 业务场景的类型
*/
enum class ScenarioType(val scenario: String) {
// 身份证
ID_CARD("id_card"),
// 活体数据
ALIVE_DETECT("living_data"),
// 营业执照
BUSINESS_LICENSE("business_license"),
// 商品
COMMODITY("goods")
}
/**
* 金山云object上传handler
*/
class KS3CorePutObjectResponseHandler(
private val bucket: String?,
private val objectKey: String?,
val listener: OnKS3TaskListener
) : PutObjectResponseHandler() {
override fun onTaskProgress(progress: Double) {
// work thread
listener.onTaskProgress(progress)
}
override fun onTaskFailure(
statesCode: Int,
error: Ks3Error?,
responceHeaders: Array<out Header>?,
response: String?,
throwable: Throwable?
) {
Log.e(
TAG,
"put object fail:, errorMsg: ${error?.errorMessage}"
)
listener.onTaskFailure(statesCode, error?.errorMessage)
}
override fun onTaskSuccess(statesCode: Int, responceHeaders: Array<out Header>?) {
Log.d(TAG, "put object success.")
listener.onTaskSuccess(bucket, objectKey)
}
override fun onTaskStart() {
listener.onTaskStart()
}
override fun onTaskFinish() {
listener.onTaskFinish()
}
override fun onTaskCancel() {
listener.onTaskCancel()
}
}
}
package com.yidian.bcommon.utils
import android.content.Context
/**
* 分享工具类
*/
object ShareUtils {
}
package com.yidian.bcommon.utils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.recyclerview.widget.RecyclerView
class ViewHolderUtil {
companion object{
fun RecyclerView.Adapter<out RecyclerView.ViewHolder>.createItemView(parent:ViewGroup,@LayoutRes layoutId:Int):View{
return LayoutInflater.from(parent.context).inflate(layoutId,parent,false)
}
}
}
package com.yidian.shenghuoquan.bgeneralbusiness.http
import com.yidian.bcommon.http.*
import com.yidian.bcommon.http.HttpResult
import com.yidian.bcommon.http.bean.GetCommonConfigBean
import io.reactivex.rxjava3.core.Observable
import retrofit2.http.GET
import retrofit2.http.QueryMap
......@@ -9,6 +10,7 @@ interface GeneralBusinessApiService {
private companion object {
const val sendMsgCode = "/sms/sms/send_code"
const val getCommonConfig = "/api/resource"
}
/**
......@@ -16,4 +18,10 @@ interface GeneralBusinessApiService {
*/
@GET(sendMsgCode)
fun sendMsgCode(@QueryMap commonParams: Map<String, String>, @QueryMap params: Map<String, String?>): Observable<HttpResult<Any?>>
/**
* TowerPro获取通用配置数据
*/
@GET(getCommonConfig)
fun getCommonConfig(@QueryMap requestParams: Map<String, String>): Observable<HttpResult<GetCommonConfigBean.GetCommonConfigResponse>>
}
package com.yidian.shenghuoquan.bgeneralbusiness.http
import com.yidian.bcommon.constant.AppConfig
import com.yidian.bcommon.constant.RunConfig
import com.yidian.bcommon.http.*
import com.yidian.bcommon.http.bean.GetCommonConfigBean
import com.yidian.bcommon.http.callback.IGetCommonConfigCallback
import com.yidian.http.ServiceFactory
object GeneralBusinessRemoteDataService {
private var api = ServiceFactory.getInstance().createService(GeneralBusinessApiService::class.java)
private val towerApi by lazy {
ServiceFactory.getInstance().createService(
GeneralBusinessApiService::class.java, if (RunConfig.TOWER_API_ENV == AppConfig.TowerApiEnvTest) {
AppConfig.TowerApiDomainTest
} else {
AppConfig.TowerApiDomainPro
}
)
}
// 获取短信验证码
fun sendMsgCode(requestParams: HashMap<String, String?>, callback: ((Boolean) -> Unit)? = null) {
val timeStamp = System.currentTimeMillis()
......@@ -23,4 +37,24 @@ object GeneralBusinessRemoteDataService {
}
})
}
// TowerPro 获取配置数据
fun getCommonConfig(apiCallback: IGetCommonConfigCallback, requestParams: HashMap<String, String>) {
towerApi
.getCommonConfig(requestParams)
.compose(TransformUtil.defaultSchedulers())
.subscribe(object : HttpResultObserver<GetCommonConfigBean.GetCommonConfigResponse>() {
override fun onSuccess(result: HttpResult<GetCommonConfigBean.GetCommonConfigResponse>?) {
apiCallback.getCommonConfigSuccess(result?.result)
}
override fun onFailure(result: HttpResult<GetCommonConfigBean.GetCommonConfigResponse>?) {
apiCallback.getCommonConfigFailure(result?.status)
}
override fun onNetworkFailure(result: HttpResult<GetCommonConfigBean.GetCommonConfigResponse>?) {
apiCallback.getCommonConfigFailure(result?.status)
}
})
}
}
package com.yidian.shenghuoquan.bgeneralbusiness.service
import com.google.gson.Gson
import com.yidian.bcommon.constant.AppConfig
import com.yidian.bcommon.constant.RunConfig
import com.yidian.bcommon.http.bean.GetCommonConfigBean
import com.yidian.bcommon.http.callback.IGetCommonConfigCallback
import com.yidian.bcommon.sdk.BCommonManager
import com.yidian.bcommon.services.ZapServiceActionConstants
import com.yidian.shenghuoquan.bgeneralbusiness.config.LazyInitConfig
import com.yidian.shenghuoquan.bgeneralbusiness.http.GeneralBusinessRemoteDataService
......@@ -13,14 +19,14 @@ import org.json.JSONObject
*/
class GeneralAbilityService : ZapService() {
private lateinit var resolver: ResultResolver
private val gson by lazy { Gson() }
override fun onAction(path: String, action: String, params: Any, options: Any, resolver: ResultResolver) {
this.resolver = resolver
params as JSONObject
when (action) {
ZapServiceActionConstants.ActionRequestSmsCode -> requestSmsCode(params)
ZapServiceActionConstants.ActionRequestSmsCode -> requestSmsCode(params, resolver)
ZapServiceActionConstants.ActionLazyInit -> lazyInit()
ZapServiceActionConstants.ActionGetTowerProCommonConfig -> getTowerProCommonConfig(resolver)
}
}
......@@ -33,7 +39,7 @@ class GeneralAbilityService : ZapService() {
/**
* 请求短信验证码
*/
private fun requestSmsCode(params: JSONObject) {
private fun requestSmsCode(params: JSONObject, resolver: ResultResolver) {
val mobile = params.optString("mobile")
val scene = params.optString("scene")
val paramsMap = HashMap<String, String?>()
......@@ -53,4 +59,27 @@ class GeneralAbilityService : ZapService() {
// 初始化慧眼
LazyInitConfig.initXInsight()
}
/**
* 获取TowerPro通用配置数据
*/
private fun getTowerProCommonConfig(resolver: ResultResolver) {
GeneralBusinessRemoteDataService.getCommonConfig(
object : IGetCommonConfigCallback {
override fun getCommonConfigSuccess(result: GetCommonConfigBean.GetCommonConfigResponse?) {
resolver.success(JSONObject(gson.toJson(result)))
}
override fun getCommonConfigFailure(message: String?) {
resolver.fail(-1, message, "获取配置失败,请稍后重试")
}
}, hashMapOf(
"appid" to BCommonManager.getAppId(),
"env" to RunConfig.TOWER_API_ENV.toString(),
"version" to AppConfig.TowerApiVersion,
"os" to AppConfig.TowerApiOS,
"keytag" to BCommonManager.getTowerProKeyTag()
)
)
}
}
......@@ -7,6 +7,8 @@ package com.yidian.shenghuoquan.bmanagercenter.constant
*/
object Constant {
const val LOG_TAG = "BManagerCenter"
const val LIFE_ACCOUNT_AUTH_TAG = "LifeAccountAuth"
// 认证类型
......
......@@ -6,16 +6,14 @@ import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshListener
import com.yidian.bcommon.base.BaseActivity
import com.yidian.bcommon.bean.HintOptionBean
import com.yidian.bcommon.bean.LifeAccountItemBean
import com.yidian.bcommon.constant.*
import com.yidian.bcommon.http.CommonDataSource
import com.yidian.bcommon.http.bean.GetCommonConfigBean
import com.yidian.bcommon.http.callback.IGetCommonConfigCallback
import com.yidian.bcommon.sdk.BCommonManager
import com.yidian.bcommon.sdk.ClientType
import com.yidian.bcommon.sdk.JudgeClientUtils
import com.yidian.bcommon.services.ZapServiceActionConstants
......@@ -44,6 +42,8 @@ import com.yidian.xpage.XPageManager
import com.yidian.yac.core.zap.ZapTicket
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.json.JSONObject
import timber.log.Timber
/**
* author: yinjiacheng
......@@ -53,7 +53,7 @@ import org.greenrobot.eventbus.ThreadMode
class MerchantCenterActivity : BaseActivity<ActivityMerchantCenterBinding>(), MerchantSwitchDialog.OnMerchantSwitchCallback,
LifeAccountLabelView.OnLifeAccountLabelCallback, MerchantCenterBottomHintDialog.OnMerchantCenterBottomHintCallback,
IAuthMerchantCheckCallback, MerchantServiceFunctionAdapter.OnItemClickListener, CommonTopBarView.OnCommonTopBarActionCallback,
OnRefreshListener, DialogInterface.OnShowListener, DialogInterface.OnDismissListener, IGetCommonConfigCallback {
OnRefreshListener, DialogInterface.OnShowListener, DialogInterface.OnDismissListener {
companion object {
const val PARAMS_LIFE_ACCOUNT_ID = "life_account_id"
......@@ -79,6 +79,8 @@ class MerchantCenterActivity : BaseActivity<ActivityMerchantCenterBinding>(), Me
*/
private lateinit var functionPermissionList: ArrayList<Int>
private val gson by lazy { Gson() }
override fun createViewBinding(): ActivityMerchantCenterBinding {
return ActivityMerchantCenterBinding.inflate(layoutInflater)
}
......@@ -418,16 +420,59 @@ class MerchantCenterActivity : BaseActivity<ActivityMerchantCenterBinding>(), Me
override fun onRefresh(refreshLayout: RefreshLayout) {
// 刷新数据
// 请求TowerPro通用配置
CommonDataSource.getCommonConfig(
this,
hashMapOf(
"appid" to BCommonManager.getAppId(),
"env" to RunConfig.TOWER_API_ENV.toString(),
"version" to AppConfig.TowerApiVersion,
"os" to AppConfig.TowerApiOS,
"keytag" to BCommonManager.getTowerProKeyTag()
)
)
ZapTicket(ZapServiceNameConstants.GeneralAbilityService).withAction(ZapServiceActionConstants.ActionGetTowerProCommonConfig)
.onResult { xResult ->
val configResult = if (xResult.code == 0) {
Timber.tag(Constant.LOG_TAG).i("get common config success, result: ${xResult.result}")
gson.fromJson((xResult.result as JSONObject).toString(), GetCommonConfigBean.GetCommonConfigResponse::class.java)
} else {
Timber.tag(Constant.LOG_TAG).e("get common config fail, message: ${xResult.mesg}")
viewBind.rlRefresh.finishRefresh(false)
return@onResult
}
// 请求生活号列表
ApiService.getLifeAccountList(object : IGetLifeAccountListCallback {
override fun getLifeAccountListSuccess(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") lifeAccountResult: ArrayList<LifeAccountItemBean.Response>?) {
viewBind.rlRefresh.finishRefresh(true)
if (lifeAccountResult?.size == 0) {
// 如果当前无生活号则退出登录
ToastUtil.showToast(this@MerchantCenterActivity, resources.getString(R.string.no_life_account))
requestLogout()
return
}
lifeAccountResult?.let {
// 切换主体入口是否展示判断
viewBind.bvTopBar.setActionVisibility(it.size > 1)
}
val lifeAccountIdList = lifeAccountResult?.map { it.life_account_id }
val curLifeAccountId = StorageUtil.getLifeAccountId()
if (lifeAccountIdList?.contains(curLifeAccountId) == false) {
// 当前选择的生活号已不存在则切换第一个生活号 目前为企业员工被解除关系会触发
// C端开店赚钱生成未认证生活号进入管理中心会触发 curLifeAccountId为null且生活号列表只有一条数据
curLifeAccount = lifeAccountResult[0]
// 更新本地存储的生活号id
StorageUtil.putLifeAccountId(lifeAccountResult[0].life_account_id)
// 刷新数据
configResult?.data?.let { refreshMerchantCenterData(lifeAccountResult[0], it) }
return
}
lifeAccountResult?.forEach {
if (curLifeAccountId == it.life_account_id) {
curLifeAccount = it
// 刷新数据
configResult?.let { configData -> refreshMerchantCenterData(it, configData.data) }
}
}
}
override fun getLifeAccountListFailure(message: String?) {
viewBind.rlRefresh.finishRefresh(false)
}
})
}.onLost {
Timber.tag(Constant.LOG_TAG).e("get common config fail, message: ${it.mesg}")
viewBind.rlRefresh.finishRefresh(false)
}.ship()
}
override fun onShow(dialog: DialogInterface?) {
......@@ -442,52 +487,6 @@ class MerchantCenterActivity : BaseActivity<ActivityMerchantCenterBinding>(), Me
viewBind.bvTopBar.setBackgroundColor(ContextCompat.getColor(this, R.color.transparent))
}
override fun getCommonConfigSuccess(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") configResult: GetCommonConfigBean.GetCommonConfigResponse?) {
// 请求生活号列表
ApiService.getLifeAccountList(object : IGetLifeAccountListCallback {
override fun getLifeAccountListSuccess(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") lifeAccountResult: ArrayList<LifeAccountItemBean.Response>?) {
viewBind.rlRefresh.finishRefresh(true)
if (lifeAccountResult?.size == 0) {
// 如果当前无生活号则退出登录
ToastUtil.showToast(this@MerchantCenterActivity, resources.getString(R.string.no_life_account))
requestLogout()
return
}
lifeAccountResult?.let {
// 切换主体入口是否展示判断
viewBind.bvTopBar.setActionVisibility(it.size > 1)
}
val lifeAccountIdList = lifeAccountResult?.map { it.life_account_id }
val curLifeAccountId = StorageUtil.getLifeAccountId()
if (lifeAccountIdList?.contains(curLifeAccountId) == false) {
// 当前选择的生活号已不存在则切换第一个生活号 目前为企业员工被解除关系会触发
// C端开店赚钱生成未认证生活号进入管理中心会触发 curLifeAccountId为null且生活号列表只有一条数据
curLifeAccount = lifeAccountResult[0]
// 更新本地存储的生活号id
StorageUtil.putLifeAccountId(lifeAccountResult[0].life_account_id)
// 刷新数据
configResult?.data?.let { refreshMerchantCenterData(lifeAccountResult[0], it) }
return
}
lifeAccountResult?.forEach {
if (curLifeAccountId == it.life_account_id) {
curLifeAccount = it
// 刷新数据
configResult?.let { configData -> refreshMerchantCenterData(it, configData.data) }
}
}
}
override fun getLifeAccountListFailure(message: String?) {
viewBind.rlRefresh.finishRefresh(false)
}
})
}
override fun getCommonConfigFailure(message: String?) {
viewBind.rlRefresh.finishRefresh(false)
}
private fun requestLogout() {
ZapTicket(ZapServiceNameConstants.SettingService).withAction(ZapServiceActionConstants.ActionLogout)
.onResult { result ->
......
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