From 4041b6284bc67c17859228338d4aedae97761a48 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Fri, 10 Jun 2022 11:31:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A2=84=E7=95=99=E6=96=B0=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E7=89=88=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/api/interfaces/ITiebaApi.kt | 12 ++++++++++ .../api/interfaces/impls/MixedTiebaApiImpl.kt | 7 ++++-- .../tieba/post/api/models/web/Profile.kt | 23 +++++++++++++++++++ .../api/retrofit/interfaces/WebTiebaApi.kt | 18 +++++++++++++-- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/huanchengfly/tieba/post/api/models/web/Profile.kt 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 9eab57c4..b9d20fb5 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 @@ -7,6 +7,7 @@ import com.huanchengfly.tieba.post.api.models.* import com.huanchengfly.tieba.post.api.models.web.ForumBean import com.huanchengfly.tieba.post.api.models.web.ForumHome import com.huanchengfly.tieba.post.api.models.web.HotMessageListBean +import com.huanchengfly.tieba.post.api.models.web.Profile import com.huanchengfly.tieba.post.api.retrofit.ApiResult import com.huanchengfly.tieba.post.models.DislikeBean import com.huanchengfly.tieba.post.models.MyInfoBean @@ -111,6 +112,12 @@ interface ITiebaApi { subPostId: String? ): Call + /** + * 获取首页关注吧列表(网页版接口) + * + * @param sortType 排序方式(0 = 等级排序,1 = 关注顺序) + * @param page 分页页码(从 0 开始) + */ fun forumHomeAsync( sortType: Int, page: Int = 0 @@ -172,6 +179,11 @@ interface ITiebaApi { uid: String ): Call + /** + * 用户信息(异步) + */ + fun myProfileAsync(): Deferred> + /** * 取关一个吧 * 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 617254d4..ece69c57 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 @@ -11,6 +11,7 @@ import com.huanchengfly.tieba.post.api.models.* import com.huanchengfly.tieba.post.api.models.web.ForumBean import com.huanchengfly.tieba.post.api.models.web.ForumHome import com.huanchengfly.tieba.post.api.models.web.HotMessageListBean +import com.huanchengfly.tieba.post.api.models.web.Profile import com.huanchengfly.tieba.post.api.retrofit.ApiResult import com.huanchengfly.tieba.post.api.retrofit.RetrofitTiebaApi import com.huanchengfly.tieba.post.models.DislikeBean @@ -29,6 +30,9 @@ object MixedTiebaApiImpl : ITiebaApi { override fun personalized(loadType: Int, page: Int): Call = RetrofitTiebaApi.MINI_TIEBA_API.personalized(loadType, page) + override fun myProfileAsync(): Deferred> = + RetrofitTiebaApi.WEB_TIEBA_API.myProfileAsync("json", "", "") + override fun agree( threadId: String, postId: String @@ -75,8 +79,7 @@ object MixedTiebaApiImpl : ITiebaApi { page, 20, "", - "", - AccountUtil.getCookie(BaseApplication.instance) + "" ) } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/models/web/Profile.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/models/web/Profile.kt new file mode 100644 index 00000000..f594ce06 --- /dev/null +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/models/web/Profile.kt @@ -0,0 +1,23 @@ +package com.huanchengfly.tieba.post.api.models.web + +import com.google.gson.annotations.SerializedName + +class Profile : WebBase() + +data class ProfileData( + @SerializedName("is_login") + val isLogin: Int, + val sid: String, + val user: User +) + +data class User( + val intro: String, + val name: String, + @SerializedName("name_show") + val nameShow: String, + val portrait: String, + val sex: Int, + @SerializedName("show_nickname") + val showNickName: String +) \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/WebTiebaApi.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/WebTiebaApi.kt index 25c57c5b..9632b536 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/WebTiebaApi.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/WebTiebaApi.kt @@ -41,10 +41,23 @@ interface WebTiebaApi { @Query("pn") page: Int, @Query("rn") pageSize: Int, @Query("eqid") eqid: String, - @Query("refer") refer: String, - @retrofit2.http.Header("Cookie") cookie: String? + @Query("refer") refer: String ): Deferred> + @Headers( + "${Header.FORCE_LOGIN}: ${Header.FORCE_LOGIN_TRUE}", + "${Header.REFERER}: https://tieba.baidu.com/index/tbwise/mine?source=index", + "sec-ch-ua: \".Not/A)Brand\";v=\"99\", \"Microsoft Edge\";v=\"103\", \"Chromium\";v=\"103\"", + "sec-ch-ua-mobile: ?1", + "sec-ch-ua-platform: Android" + ) + @GET("/mg/o/profile") + fun myProfileAsync( + @Query("format") format: String, + @Query("eqid") eqid: String, + @Query("refer") refer: String + ): Deferred> + @GET("/mo/q/hotMessage/main") fun hotTopicMain( @Query("topic_id") topicId: String, @@ -118,6 +131,7 @@ interface WebTiebaApi { @retrofit2.http.Header("cookie") cookie: String ): Deferred> + @GET("/mo/q/search/forum") fun searchForum( @Query("word") keyword: String