feat: 新版回贴 API
This commit is contained in:
parent
91893bb3b7
commit
494923ad33
|
|
@ -2,7 +2,8 @@ package com.huanchengfly.tieba.post.api
|
|||
|
||||
enum class ClientVersion(val version: String) {
|
||||
TIEBA_V11("11.10.8.6"),
|
||||
TIEBA_V12("12.25.1.0");
|
||||
TIEBA_V12("12.25.1.0"),
|
||||
TIEBA_V12_POST("12.35.1.0");
|
||||
|
||||
override fun toString(): String {
|
||||
return version
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ object Param {
|
|||
const val CUID_GALAXY3 = "c3_aid"
|
||||
const val OAID = "oaid"
|
||||
const val CUID_GID = "cuid_gid"
|
||||
const val DEVICE_SCORE = "device_score"
|
||||
const val EVENT_DAY = "event_day"
|
||||
const val EXTRA = "extra"
|
||||
const val FIRST_INSTALL_TIME = "first_install_time"
|
||||
|
|
@ -89,4 +90,5 @@ object Param {
|
|||
const val STOKEN = "stoken"
|
||||
const val SWAN_GAME_VER = "swan_game_ver"
|
||||
const val TIMESTAMP = "timestamp"
|
||||
const val Z_ID = "z_id"
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ 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.DeviceUtils
|
||||
import com.huanchengfly.tieba.post.utils.MobileInfoUtil
|
||||
import com.huanchengfly.tieba.post.utils.UIDUtil
|
||||
import com.squareup.wire.Message
|
||||
|
|
@ -32,7 +33,7 @@ fun buildProtobufRequestBody(
|
|||
return MyMultipartBody.Builder(BOUNDARY)
|
||||
.apply {
|
||||
setType(MyMultipartBody.FORM)
|
||||
if (clientVersion != ClientVersion.TIEBA_V12) {
|
||||
if (clientVersion != ClientVersion.TIEBA_V12 && clientVersion != ClientVersion.TIEBA_V12_POST) {
|
||||
addFormDataPart(Param.CLIENT_VERSION, clientVersion.version)
|
||||
}
|
||||
if (needSToken) {
|
||||
|
|
@ -68,9 +69,10 @@ fun buildAppPosInfo(): AppPosInfo {
|
|||
|
||||
fun buildCommonRequest(
|
||||
context: Context = App.INSTANCE,
|
||||
clientVersion: ClientVersion = ClientVersion.TIEBA_V11
|
||||
clientVersion: ClientVersion = ClientVersion.TIEBA_V11,
|
||||
tbs: String? = null,
|
||||
): CommonRequest = when (clientVersion) {
|
||||
ClientVersion.TIEBA_V11 ->
|
||||
ClientVersion.TIEBA_V11 -> {
|
||||
CommonRequest(
|
||||
BDUSS = AccountUtil.getBduss(),
|
||||
_client_id = ClientUtils.clientId ?: RetrofitTiebaApi.randomClientId,
|
||||
|
|
@ -94,8 +96,9 @@ fun buildCommonRequest(
|
|||
sample_id = ClientUtils.sampleId,
|
||||
stoken = AccountUtil.getSToken(),
|
||||
)
|
||||
}
|
||||
|
||||
ClientVersion.TIEBA_V12 ->
|
||||
ClientVersion.TIEBA_V12 -> {
|
||||
CommonRequest(
|
||||
BDUSS = AccountUtil.getBduss(),
|
||||
_client_id = ClientUtils.clientId ?: RetrofitTiebaApi.randomClientId,
|
||||
|
|
@ -139,6 +142,59 @@ fun buildCommonRequest(
|
|||
start_type = 1,
|
||||
stoken = AccountUtil.getSToken(),
|
||||
swan_game_ver = "1038000",
|
||||
user_agent = getUserAgent("tieba/${ClientVersion.TIEBA_V12}")
|
||||
user_agent = getUserAgent("tieba/${clientVersion.version}")
|
||||
)
|
||||
}
|
||||
|
||||
ClientVersion.TIEBA_V12_POST -> {
|
||||
CommonRequest(
|
||||
BDUSS = AccountUtil.getBduss(),
|
||||
_client_id = ClientUtils.clientId ?: RetrofitTiebaApi.randomClientId,
|
||||
_client_type = 2,
|
||||
_client_version = clientVersion.version,
|
||||
_os_version = "${Build.VERSION.SDK_INT}", // TODO
|
||||
_phone_imei = MobileInfoUtil.getIMEI(context),
|
||||
_timestamp = System.currentTimeMillis(),
|
||||
active_timestamp = ClientUtils.activeTimestamp,
|
||||
android_id = UIDUtil.getAndroidId("000"),
|
||||
applist = "",
|
||||
brand = Build.BRAND,
|
||||
c3_aid = UIDUtil.getAid(),
|
||||
cmode = 1,
|
||||
cuid = CuidUtils.getNewCuid(),
|
||||
cuid_galaxy2 = CuidUtils.getNewCuid(),
|
||||
cuid_gid = "",
|
||||
device_score = "${DeviceUtils.getDeviceScore()}",
|
||||
event_day = SimpleDateFormat("yyyyMdd", Locale.getDefault()).format(
|
||||
Date(
|
||||
System.currentTimeMillis()
|
||||
)
|
||||
),
|
||||
extra = "",
|
||||
first_install_time = App.Config.appFirstInstallTime,
|
||||
framework_ver = "3340042",
|
||||
from = "1020031h",
|
||||
is_teenager = 0,
|
||||
last_update_time = App.Config.appLastUpdateTime,
|
||||
lego_lib_version = "3.0.0",
|
||||
model = Build.MODEL,
|
||||
net_type = 1,
|
||||
oaid = App.Config.encodedOAID,
|
||||
personalized_rec_switch = 1,
|
||||
pversion = "1.0.3",
|
||||
q_type = 0,
|
||||
sample_id = ClientUtils.sampleId,
|
||||
scr_dip = App.ScreenInfo.DENSITY.toDouble(),
|
||||
scr_h = getScreenHeight(),
|
||||
scr_w = getScreenWidth(),
|
||||
sdk_ver = "2.34.0",
|
||||
start_scheme = "",
|
||||
start_type = 1,
|
||||
stoken = AccountUtil.getSToken(),
|
||||
swan_game_ver = "1038000",
|
||||
tbs = tbs,
|
||||
user_agent = getUserAgent("tieba/${clientVersion.version}"),
|
||||
z_id = AccountUtil.getAccountInfo { zid }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.huanchengfly.tieba.post.api.ForumSortType
|
|||
import com.huanchengfly.tieba.post.api.SearchThreadFilter
|
||||
import com.huanchengfly.tieba.post.api.SearchThreadOrder
|
||||
import com.huanchengfly.tieba.post.api.models.*
|
||||
import com.huanchengfly.tieba.post.api.models.protos.addPost.AddPostResponse
|
||||
import com.huanchengfly.tieba.post.api.models.protos.forumRecommend.ForumRecommendResponse
|
||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.FrsPageResponse
|
||||
import com.huanchengfly.tieba.post.api.models.protos.hotThreadList.HotThreadListResponse
|
||||
|
|
@ -1243,10 +1244,12 @@ interface ITiebaApi {
|
|||
forumId: String,
|
||||
forumName: String,
|
||||
threadId: String,
|
||||
tbs: String,
|
||||
tbs: String? = null,
|
||||
nameShow: String? = null,
|
||||
postId: String? = null,
|
||||
subPostId: String? = null,
|
||||
replyUserId: String? = null
|
||||
): Flow<AddPostBean>
|
||||
): Flow<AddPostResponse>
|
||||
|
||||
/**
|
||||
* 用户信息(Flow)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import com.huanchengfly.tieba.post.api.buildProtobufRequestBody
|
|||
import com.huanchengfly.tieba.post.api.getScreenHeight
|
||||
import com.huanchengfly.tieba.post.api.getScreenWidth
|
||||
import com.huanchengfly.tieba.post.api.interfaces.ITiebaApi
|
||||
import com.huanchengfly.tieba.post.api.models.AddPostBean
|
||||
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
||||
import com.huanchengfly.tieba.post.api.models.CheckReportBean
|
||||
import com.huanchengfly.tieba.post.api.models.CollectDataBean
|
||||
|
|
@ -49,6 +48,9 @@ import com.huanchengfly.tieba.post.api.models.UserLikeForumBean
|
|||
import com.huanchengfly.tieba.post.api.models.UserPostBean
|
||||
import com.huanchengfly.tieba.post.api.models.WebReplyResultBean
|
||||
import com.huanchengfly.tieba.post.api.models.WebUploadPicBean
|
||||
import com.huanchengfly.tieba.post.api.models.protos.addPost.AddPostRequest
|
||||
import com.huanchengfly.tieba.post.api.models.protos.addPost.AddPostRequestData
|
||||
import com.huanchengfly.tieba.post.api.models.protos.addPost.AddPostResponse
|
||||
import com.huanchengfly.tieba.post.api.models.protos.forumRecommend.ForumRecommendRequest
|
||||
import com.huanchengfly.tieba.post.api.models.protos.forumRecommend.ForumRecommendRequestData
|
||||
import com.huanchengfly.tieba.post.api.models.protos.forumRecommend.ForumRecommendResponse
|
||||
|
|
@ -996,25 +998,55 @@ object MixedTiebaApiImpl : ITiebaApi {
|
|||
forumId: String,
|
||||
forumName: String,
|
||||
threadId: String,
|
||||
tbs: String,
|
||||
tbs: String?,
|
||||
nameShow: String?,
|
||||
postId: String?,
|
||||
subPostId: String?,
|
||||
replyUserId: String?
|
||||
): Flow<AddPostBean> {
|
||||
return RetrofitTiebaApi.OFFICIAL_TIEBA_API.addPostFlow(
|
||||
content,
|
||||
forumId,
|
||||
forumName,
|
||||
tbs,
|
||||
threadId,
|
||||
quoteId = postId,
|
||||
replyUserId = replyUserId ?: if (postId == null) "null" else "",
|
||||
repostId = postId,
|
||||
is_addition = if (postId == null) null else "0",
|
||||
is_barrage = if (postId == null) "0" else null,
|
||||
is_giftpost = if (postId == null) null else "0",
|
||||
is_twzhibo_thread = if (postId == null) null else "0",
|
||||
post_from = if (postId == null) "3" else "11"
|
||||
)
|
||||
): Flow<AddPostResponse> {
|
||||
return RetrofitTiebaApi.OFFICIAL_PROTOBUF_TIEBA_POST_API
|
||||
.addPostFlow(
|
||||
buildProtobufRequestBody(
|
||||
AddPostRequest(
|
||||
AddPostRequestData(
|
||||
anonymous = "1",
|
||||
barrage_time = "0".takeIf { postId.isNullOrEmpty() },
|
||||
can_no_forum = "0",
|
||||
common = buildCommonRequest(
|
||||
clientVersion = ClientVersion.TIEBA_V12_POST,
|
||||
tbs = tbs ?: AccountUtil.getAccountInfo { this.tbs }
|
||||
),
|
||||
content = content,
|
||||
entrance_type = "0",
|
||||
fid = forumId,
|
||||
floor_num = "0".takeIf { postId.isNullOrEmpty() },
|
||||
is_ad = "0",
|
||||
is_addition = "0".takeIf { postId.isNullOrEmpty() },
|
||||
is_barrage = "0".takeIf { postId.isNullOrEmpty() },
|
||||
is_feedback = "0",
|
||||
is_giftpost = "0".takeIf { postId.isNullOrEmpty() },
|
||||
is_pictxt = "0",
|
||||
is_show_bless = 0,
|
||||
is_twzhibo_thread = "0".takeIf { postId.isNullOrEmpty() },
|
||||
name_show = nameShow ?: AccountUtil.getAccountInfo { this.nameShow }
|
||||
.orEmpty(),
|
||||
new_vcode = "1",
|
||||
post_from = if (postId.isNullOrEmpty() && subPostId.isNullOrEmpty()) "13" else if (subPostId.isNullOrEmpty()) "0" else null,
|
||||
quote_id = postId,
|
||||
reply_uid = replyUserId.takeIf { !postId.isNullOrEmpty() },
|
||||
repostid = postId,
|
||||
sub_post_id = subPostId,
|
||||
show_custom_figure = 0,
|
||||
takephoto_num = "0",
|
||||
tid = threadId,
|
||||
v_fid = "".takeIf { postId.isNullOrEmpty() },
|
||||
v_fname = "".takeIf { postId.isNullOrEmpty() },
|
||||
vcode_tag = "12",
|
||||
)
|
||||
),
|
||||
clientVersion = ClientVersion.TIEBA_V12_POST
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun userProfileFlow(uid: Long): Flow<ProfileResponse> {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ 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.DeviceUtils
|
||||
import com.huanchengfly.tieba.post.utils.MobileInfoUtil
|
||||
import com.huanchengfly.tieba.post.utils.UIDUtil
|
||||
import okhttp3.ConnectionPool
|
||||
|
|
@ -225,6 +226,65 @@ object RetrofitTiebaApi {
|
|||
)
|
||||
}
|
||||
|
||||
val OFFICIAL_PROTOBUF_TIEBA_POST_API: OfficialProtobufTiebaApi by lazy {
|
||||
createProtobufApi<OfficialProtobufTiebaApi>(
|
||||
"https://tiebac.baidu.com/",
|
||||
CommonHeaderInterceptor(
|
||||
Header.CHARSET to { "UTF-8" },
|
||||
// Header.CLIENT_TYPE to { "2" },
|
||||
Header.CLIENT_USER_TOKEN to { AccountUtil.getUid() },
|
||||
Header.COOKIE to {
|
||||
"BAIDUZID=${
|
||||
AccountUtil.getAccountInfo { zid }.orEmpty()
|
||||
};CUID=${CuidUtils.getNewCuid()};ka=open;TBBRAND=${Build.MODEL};"
|
||||
},
|
||||
Header.CUID to { CuidUtils.getNewCuid() },
|
||||
Header.CUID_GALAXY2 to { CuidUtils.getNewCuid() },
|
||||
Header.CUID_GID to { "" },
|
||||
Header.CUID_GALAXY3 to { UIDUtil.getAid() },
|
||||
Header.USER_AGENT to { getUserAgent("tieba/${ClientVersion.TIEBA_V12_POST.version}") },
|
||||
Header.X_BD_DATA_TYPE to { "protobuf" },
|
||||
),
|
||||
defaultCommonParamInterceptor - Param.OS_VERSION + CommonParamInterceptor(
|
||||
Param.CLIENT_VERSION to { ClientVersion.TIEBA_V12_POST.version },
|
||||
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.CUID_GALAXY3 to { UIDUtil.getAid() },
|
||||
Param.CMODE to { "1" },
|
||||
Param.CUID to { CuidUtils.getNewCuid() },
|
||||
Param.CUID_GALAXY2 to { CuidUtils.getNewCuid() },
|
||||
Param.CUID_GID to { "" },
|
||||
Param.DEVICE_SCORE to { "${DeviceUtils.getDeviceScore()}" },
|
||||
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" },
|
||||
"naws_game_ver" to { "1038000" },
|
||||
Param.OAID to { OAID().toJson() },
|
||||
"personalized_rec_switch" to { "1" },
|
||||
Param.SAMPLE_ID to { ClientUtils.sampleId },
|
||||
Param.SDK_VER to { "2.34.0" },
|
||||
Param.START_SCHEME to { "" },
|
||||
Param.START_TYPE to { "1" },
|
||||
Param.STOKEN to { AccountUtil.getSToken() },
|
||||
Param.Z_ID to { AccountUtil.getAccountInfo { zid }.orEmpty() },
|
||||
),
|
||||
stParamInterceptor,
|
||||
)
|
||||
}
|
||||
|
||||
val SOFIRE_API: SofireApi by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl("https://sofire.baidu.com/")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.huanchengfly.tieba.post.api.retrofit.interfaces
|
||||
|
||||
import com.huanchengfly.tieba.post.api.models.protos.addPost.AddPostResponse
|
||||
import com.huanchengfly.tieba.post.api.models.protos.forumRecommend.ForumRecommendResponse
|
||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.FrsPageResponse
|
||||
import com.huanchengfly.tieba.post.api.models.protos.hotThreadList.HotThreadListResponse
|
||||
|
|
@ -67,4 +68,9 @@ interface OfficialProtobufTiebaApi {
|
|||
fun pbFloorFlow(
|
||||
@Body body: MyMultipartBody,
|
||||
): Flow<PbFloorResponse>
|
||||
|
||||
@POST("/c/c/post/add?cmd=309731&format=protobuf")
|
||||
fun addPostFlow(
|
||||
@Body body: MyMultipartBody,
|
||||
): Flow<AddPostResponse>
|
||||
}
|
||||
|
|
@ -7,23 +7,23 @@ option java_package = "com.huanchengfly.tieba.post.api.models.protos.addPost";
|
|||
import "CommonRequest.proto";
|
||||
|
||||
message AddPostRequestData {
|
||||
CommonRequest common = 1;
|
||||
string authsid = 2;
|
||||
string sig = 3;
|
||||
string tbs = 4;
|
||||
string video_other = 5;
|
||||
string anonymous = 6;
|
||||
string can_no_forum = 7;
|
||||
string is_feedback = 8;
|
||||
string takephoto_num = 9;
|
||||
string entrance_type = 10;
|
||||
string voice_md5 = 11;
|
||||
string during_time = 12;
|
||||
string vcode = 13;
|
||||
string vcode_md5 = 14;
|
||||
string vcode_type = 15;
|
||||
string vcode_tag = 16;
|
||||
string topic_id = 17;
|
||||
CommonRequest common = 1;
|
||||
string authsid = 2;
|
||||
string sig = 3;
|
||||
string tbs = 4;
|
||||
string video_other = 5;
|
||||
string anonymous = 6;
|
||||
string can_no_forum = 7;
|
||||
string is_feedback = 8;
|
||||
string takephoto_num = 9;
|
||||
string entrance_type = 10;
|
||||
string voice_md5 = 11;
|
||||
string during_time = 12;
|
||||
string vcode = 13;
|
||||
string vcode_md5 = 14;
|
||||
string vcode_type = 15;
|
||||
string vcode_tag = 16;
|
||||
string topic_id = 17;
|
||||
string new_vcode = 18;
|
||||
string content = 19;
|
||||
optional string reply_uid = 20;
|
||||
|
|
@ -37,8 +37,8 @@ message AddPostRequestData {
|
|||
optional string v_fid = 28;
|
||||
optional string v_fname = 29;
|
||||
string kw = 30;
|
||||
string is_barrage = 31;
|
||||
string barrage_time = 32;
|
||||
optional string is_barrage = 31;
|
||||
optional string barrage_time = 32;
|
||||
string st_param = 33;
|
||||
string ptype = 34;
|
||||
string ori_ugc_nid = 35;
|
||||
|
|
@ -46,29 +46,29 @@ message AddPostRequestData {
|
|||
string ori_ugc_tid = 37;
|
||||
string ori_ugc_type = 38;
|
||||
string is_location = 39;
|
||||
string lat = 40;
|
||||
string lng = 41;
|
||||
string name = 42;
|
||||
string sn = 43;
|
||||
string from_fourm_id = 44;
|
||||
string lat = 40;
|
||||
string lng = 41;
|
||||
string name = 42;
|
||||
string sn = 43;
|
||||
string from_fourm_id = 44;
|
||||
string tid = 45;
|
||||
optional string quote_id = 46;
|
||||
string is_twzhibo_thread = 47;
|
||||
string floor_num = 48;
|
||||
optional string is_twzhibo_thread = 47;
|
||||
optional string floor_num = 48;
|
||||
optional string repostid = 49;
|
||||
string sub_post_id = 50;
|
||||
string is_ad = 51;
|
||||
string is_addition = 52;
|
||||
string is_giftpost = 53;
|
||||
string st_type = 54;
|
||||
string post_from = 55;
|
||||
string real_lat = 56;
|
||||
string real_lng = 57;
|
||||
string name_show = 58;
|
||||
string is_works = 59;
|
||||
string is_pictxt = 60;
|
||||
string is_story = 61;
|
||||
string jid = 62;
|
||||
optional string sub_post_id = 50;
|
||||
string is_ad = 51;
|
||||
optional string is_addition = 52;
|
||||
optional string is_giftpost = 53;
|
||||
string st_type = 54;
|
||||
optional string post_from = 55;
|
||||
string real_lat = 56;
|
||||
string real_lng = 57;
|
||||
string name_show = 58;
|
||||
string is_works = 59;
|
||||
string is_pictxt = 60;
|
||||
string is_story = 61;
|
||||
string jid = 62;
|
||||
string jfrom = 63;
|
||||
optional int32 show_custom_figure = 64;
|
||||
string from_category_id = 65;
|
||||
|
|
|
|||
Loading…
Reference in New Issue