From 5adeee3cadc42508e400212b158ac26a4729bdd4 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:07:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E6=9E=81=E9=80=9F?= =?UTF-8?q?=E7=89=88=20API=20=E8=A7=84=E9=81=BF=E7=82=B9=E8=B5=9E=E9=A3=8E?= =?UTF-8?q?=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/api/HttpConstant.kt | 21 ++++++++++++-- .../tieba/post/api/interfaces/ITiebaApi.kt | 5 ++-- .../api/interfaces/impls/MixedTiebaApiImpl.kt | 10 ++++--- .../post/api/retrofit/RetrofitTiebaApi.kt | 28 +++++++++++++++++++ .../api/retrofit/interfaces/MiniTiebaApi.kt | 15 ++++++++++ .../threadlist/ForumThreadListViewModel.kt | 2 ++ .../main/explore/concern/ConcernViewModel.kt | 2 +- .../personalized/PersonalizedViewModel.kt | 2 +- .../tieba/post/ui/page/thread/ThreadPage.kt | 1 + .../post/ui/page/thread/ThreadViewModel.kt | 6 +++- 10 files changed, 81 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/HttpConstant.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/HttpConstant.kt index fe3f34c2..67573603 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/HttpConstant.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/HttpConstant.kt @@ -54,22 +54,39 @@ object Header { object Param { + const val ACTIVE_TIMESTAMP = "active_timestamp" + const val ANDROID_ID = "android_id" + const val BAIDU_ID = "baiduid" const val BDUSS = "BDUSS" + const val BRAND = "brand" const val CLIENT_VERSION = "_client_version" const val CLIENT_TYPE = "_client_type" const val CLIENT_ID = "_client_id" const val PHONE_IMEI = "_phone_imei" + const val CMODE = "cmode" const val CUID = "cuid" const val CUID_GALAXY2 = "cuid_galaxy2" const val CUID_GALAXY3 = "c3_aid" const val OAID = "oaid" const val CUID_GID = "cuid_gid" + const val EVENT_DAY = "event_day" + const val EXTRA = "extra" + const val FIRST_INSTALL_TIME = "first_install_time" const val FROM = "from" - const val NET_TYPE = "net_type" + const val FRAMEWORK_VER = "framework_ver" + const val IS_TEENAGER = "is_teenager" + const val LAST_UPDATE_TIME = "last_update_time" + const val MAC = "mac" const val MODEL = "model" + const val NET_TYPE = "net_type" const val OS_VERSION = "_os_version" - const val TIMESTAMP = "timestamp" + const val SAMPLE_ID = "sample_id" + const val SDK_VER = "sdk_ver" const val SIGN = "sign" + const val START_SCHEME = "start_scheme" + const val START_TYPE = "start_type" const val SUBAPP_TYPE = "subapp_type" const val STOKEN = "stoken" + const val SWAN_GAME_VER = "swan_game_ver" + const val TIMESTAMP = "timestamp" } \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt index 188f642e..633af35c 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt @@ -96,9 +96,10 @@ interface ITiebaApi { */ fun opAgreeFlow( threadId: String, + postId: String, opType: Int, - postId: String? = null, - isSubPost: Boolean = false, + objType: Int, + agreeType: Int = 2, ): Flow /** diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt index 6cce2906..325a3e1b 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt @@ -160,15 +160,17 @@ object MixedTiebaApiImpl : ITiebaApi { override fun opAgreeFlow( threadId: String, + postId: String, opType: Int, - postId: String?, - isSubPost: Boolean + objType: Int, + agreeType: Int, ): Flow = - RetrofitTiebaApi.OFFICIAL_TIEBA_API.agreeFlow( + RetrofitTiebaApi.MINI_TIEBA_API.opAgreeFlow( threadId, postId, opType = opType, - objType = if (postId == null) 3 else if (isSubPost) 2 else 1 + objType = objType, + agreeType = agreeType ) override fun disagreeFlow( diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/RetrofitTiebaApi.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/RetrofitTiebaApi.kt index a61605cf..bdcdf4e5 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/RetrofitTiebaApi.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/RetrofitTiebaApi.kt @@ -28,6 +28,7 @@ import com.huanchengfly.tieba.post.api.retrofit.interfaces.OfficialTiebaApi import com.huanchengfly.tieba.post.api.retrofit.interfaces.WebTiebaApi import com.huanchengfly.tieba.post.toJson import com.huanchengfly.tieba.post.utils.AccountUtil +import com.huanchengfly.tieba.post.utils.CacheUtil.base64Encode import com.huanchengfly.tieba.post.utils.ClientUtils import com.huanchengfly.tieba.post.utils.CuidUtils import com.huanchengfly.tieba.post.utils.MobileInfoUtil @@ -37,6 +38,9 @@ import okhttp3.Interceptor import okhttp3.OkHttpClient import retrofit2.Retrofit import retrofit2.converter.wire.WireConverterFactory +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale import java.util.concurrent.TimeUnit import kotlin.math.roundToInt @@ -128,6 +132,7 @@ object RetrofitTiebaApi { "http://c.tieba.baidu.com/", CommonHeaderInterceptor( Header.USER_AGENT to { "bdtb for Android 12.25.1.0" }, + Header.COOKIE to { "CUID=${CuidUtils.getNewCuid()};ka=open;TBBRAND=${Build.MODEL};BAIDUID=${ClientUtils.baiduId};" }, Header.CUID to { CuidUtils.getNewCuid() }, Header.CUID_GALAXY2 to { CuidUtils.getNewCuid() }, Header.CUID_GID to { "" }, @@ -137,10 +142,33 @@ object RetrofitTiebaApi { "client_logid" to { "$initTime" } ), defaultCommonParamInterceptor + CommonParamInterceptor( + Param.ACTIVE_TIMESTAMP to { ClientUtils.activeTimestamp.toString() }, + Param.ANDROID_ID to { base64Encode(UIDUtil.getAndroidId("000")) }, + Param.BAIDU_ID to { ClientUtils.baiduId }, + Param.BRAND to { Build.BRAND }, + Param.CMODE to { "1" }, Param.CUID to { CuidUtils.getNewCuid() }, Param.CUID_GALAXY2 to { CuidUtils.getNewCuid() }, Param.CUID_GID to { "" }, + Param.EVENT_DAY to { + SimpleDateFormat("yyyyMdd", Locale.getDefault()).format( + Date( + System.currentTimeMillis() + ) + ) + }, + Param.EXTRA to { "" }, + Param.FIRST_INSTALL_TIME to { App.Config.appFirstInstallTime.toString() }, + Param.FRAMEWORK_VER to { "3340042" }, Param.FROM to { "tieba" }, + Param.IS_TEENAGER to { "0" }, + Param.LAST_UPDATE_TIME to { App.Config.appLastUpdateTime.toString() }, + Param.MAC to { "02:00:00:00:00:00" }, + Param.SAMPLE_ID to { ClientUtils.sampleId }, + Param.SDK_VER to { "2.34.0" }, + Param.START_SCHEME to { "" }, + Param.START_TYPE to { "1" }, + Param.SWAN_GAME_VER to { "1038000" }, Param.CLIENT_VERSION to { "12.25.1.0" }, Param.CUID_GALAXY3 to { UIDUtil.getAid() }, Param.OAID to { OAID().toJson() }, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt index 9d7cfde8..b168747e 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt @@ -107,6 +107,21 @@ interface MiniTiebaApi { @Field("stoken") stoken: String = AccountUtil.getSToken()!! ): Call + @Headers("${Header.FORCE_LOGIN}: ${Header.FORCE_LOGIN_TRUE}") + @POST("/c/c/agree/opAgree") + @FormUrlEncoded + fun opAgreeFlow( + @Field("thread_id") threadId: String, + @Field("post_id") postId: String, + @Field("agree_type") agreeType: Int = 2, + @Field("obj_type") objType: Int = 3, + @Field("op_type") opType: Int = 0, + @retrofit2.http.Header("client_user_token") client_user_token: String? = AccountUtil.getUid(), + @Field("cuid_gid") cuid_gid: String = "", + @Field("tbs") tbs: String = AccountUtil.getLoginInfo()!!.tbs, + @Field("stoken") stoken: String = AccountUtil.getSToken()!! + ): Flow + @Headers("${Header.FORCE_LOGIN}: ${Header.FORCE_LOGIN_TRUE}") @POST("/c/c/agree/opAgree") @FormUrlEncoded diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt index 3fcad583..8a6bd787 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt @@ -205,7 +205,9 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType private fun ForumThreadListUiIntent.Agree.producePartialChange(): Flow = TiebaApi.getInstance().opAgreeFlow( threadId.toString(), + postId.toString(), hasAgree, + objType = 3 ).map { ForumThreadListPartialChange.Agree.Success( threadId, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt index 1f73a2d8..d10102a3 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/concern/ConcernViewModel.kt @@ -79,7 +79,7 @@ class ConcernViewModel @Inject constructor() : private fun ConcernUiIntent.Agree.producePartialChange(): Flow = TiebaApi.getInstance().opAgreeFlow( - threadId.toString(), hasAgree + threadId.toString(), postId.toString(), hasAgree, objType = 3 ).map { ConcernPartialChange.Agree.Success(threadId, hasAgree xor 1) } .catch { emit(ConcernPartialChange.Agree.Failure(threadId, hasAgree, it)) } .onStart { emit(ConcernPartialChange.Agree.Start(threadId, hasAgree xor 1)) } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt index ab69549b..f699dc75 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt @@ -115,7 +115,7 @@ class PersonalizedViewModel @Inject constructor() : private fun PersonalizedUiIntent.Agree.producePartialChange(): Flow = TiebaApi.getInstance().opAgreeFlow( - threadId.toString(), hasAgree, + threadId.toString(), postId.toString(), hasAgree, objType = 3 ).map { PersonalizedPartialChange.Agree.Success( threadId, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt index 09f82f2d..99bc4055 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt @@ -1061,6 +1061,7 @@ fun ThreadPage( if (firstPostId != 0L) viewModel.send( ThreadUiIntent.AgreeThread( threadId, + firstPostId, !hasThreadAgreed ) ) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadViewModel.kt index fe136811..a359e4f4 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadViewModel.kt @@ -359,7 +359,9 @@ class ThreadViewModel @Inject constructor() : TiebaApi.getInstance() .opAgreeFlow( threadId.toString(), + postId.toString(), opType = if (agree) 0 else 1, + objType = 3 ) .map { ThreadPartialChange.AgreeThread.Success( @@ -381,8 +383,9 @@ class ThreadViewModel @Inject constructor() : TiebaApi.getInstance() .opAgreeFlow( threadId.toString(), - if (agree) 0 else 1, postId.toString(), + if (agree) 0 else 1, + objType = 1 ) .map { ThreadPartialChange.AgreePost.Success( @@ -469,6 +472,7 @@ sealed interface ThreadUiIntent : UiIntent { data class AgreeThread( val threadId: Long, + val postId: Long, val agree: Boolean ) : ThreadUiIntent