feat(API): 支持新版吧内搜索

This commit is contained in:
HuanCheng65 2024-01-28 14:16:19 +08:00
parent d7f19e2f1e
commit d99f723cbc
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
4 changed files with 53 additions and 21 deletions

View File

@ -3,27 +3,12 @@ package com.huanchengfly.tieba.post.api
import com.huanchengfly.tieba.post.api.retrofit.body.MyMultipartBody
import okhttp3.FormBody
import okio.Buffer
import java.io.UnsupportedEncodingException
import java.net.URLDecoder
import java.net.URLEncoder
fun String.urlEncode(): String {
return try {
URLEncoder.encode(this, "UTF-8")
} catch (e: UnsupportedEncodingException) {
e.printStackTrace()
this
}
}
fun String.urlEncode(): String = runCatching { URLEncoder.encode(this, "UTF-8") }.getOrDefault(this)
fun String.urlDecode(): String {
return try {
URLDecoder.decode(this, "UTF-8")
} catch (e: UnsupportedEncodingException) {
e.printStackTrace()
this
}
}
fun String.urlDecode(): String = runCatching { URLDecoder.decode(this, "UTF-8") }.getOrDefault(this)
fun FormBody.containsEncodedName(name: String): Boolean {
repeat(size) {
@ -49,7 +34,7 @@ fun FormBody.raw() =
}.toString()
fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
val nameAndValue = ArrayList<String>()
val nameAndValue = mutableListOf<String>()
repeat(size) {
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
}
@ -58,7 +43,7 @@ fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
}
fun FormBody.sortedRaw(separator: Boolean = true): String {
val nameAndValue = ArrayList<String>()
val nameAndValue = mutableListOf<String>()
repeat(size) {
nameAndValue.add("${name(it)}=${value(it)}")
}
@ -116,7 +101,7 @@ fun MyMultipartBody.newBuilder(): MyMultipartBody.Builder =
fun MyMultipartBody.sort(): MyMultipartBody {
val builder = newBuilder()
var fileParts = mutableListOf<MyMultipartBody.Part>()
val fileParts = mutableListOf<MyMultipartBody.Part>()
parts.forEach {
if (it.fileName() != null) {
fileParts.add(it)

View File

@ -947,6 +947,27 @@ interface ITiebaApi {
sort: Int,
): Flow<SearchThreadBean>
/**
* 吧内搜索
*
* @param keyword 搜索关键词
* @param forumName 搜索吧名
* @param forumId 搜索吧 ID
* @param sortType 排序模式1 = 时间倒序2 = 相关性排序
* @param filterType 过滤1 = 全部2 = 仅看主题贴
* @param page 分页页码 1 开始
* @param pageSize 每页贴数默认 20
*/
fun searchPostFlow(
keyword: String,
forumName: String,
forumId: Long,
sortType: Int = 1,
filterType: Int = 1,
page: Int = 1,
pageSize: Int = 20,
): Flow<SearchThreadBean>
/**
* 上传图片web 接口
*

View File

@ -118,6 +118,7 @@ import com.huanchengfly.tieba.post.models.MyInfoBean
import com.huanchengfly.tieba.post.models.PhotoInfoBean
import com.huanchengfly.tieba.post.toJson
import com.huanchengfly.tieba.post.utils.AccountUtil
import com.huanchengfly.tieba.post.utils.CuidUtils
import com.huanchengfly.tieba.post.utils.ImageUtil
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.flow.Flow
@ -671,6 +672,28 @@ object MixedTiebaApiImpl : ITiebaApi {
sort
)
override fun searchPostFlow(
keyword: String,
forumName: String,
forumId: Long,
sortType: Int,
filterType: Int,
page: Int,
pageSize: Int,
): Flow<SearchThreadBean> =
RetrofitTiebaApi.HYBRID_TIEBA_API.searchThreadFlow(
keyword,
page,
sortType,
filterType,
pageSize,
forumName,
ct = 2,
isUseZonghe = null,
clientVersion = ClientVersion.TIEBA_V12.version,
referer = "https://tieba.baidu.com/mo/q/hybrid-usergrow-search/searchGlobal?entryPage=frs&loadingSignal=1&forumName=${forumName.urlEncode()}&forumId=$forumId&customfullscreen=1&nonavigationbar=1&cuid=${CuidUtils.getNewCuid()}&cuid_galaxy2=${CuidUtils.getNewCuid()}&cuid_gid=&timestamp=${System.currentTimeMillis()}&_client_version=${ClientVersion.TIEBA_V12.version}&_client_type=2"
)
override fun webUploadPic(photoInfoBean: PhotoInfoBean): Call<WebUploadPicBean> {
var base64: String? = null
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {

View File

@ -34,8 +34,11 @@ interface AppHybridTiebaApi {
@Query("pn") page: Int,
@Query("st") sort: Int,
@Query("tt") filter: Int = 1,
@Query("rn") pageSize: Int? = null,
@Query("fname") forumName: String? = null,
@Query("ct") ct: Int = 1,
@Query("cv") cv: String = "99.9.101",
@Query("is_use_zonghe") isUseZonghe: Int? = 1,
@Query("cv") clientVersion: String = "99.9.101",
@Header("Referer") referer: String = "https://tieba.baidu.com/mo/q/hybrid/search?keyword=$keyword&_webview_time=${System.currentTimeMillis()}".urlEncode(),
): Flow<SearchThreadBean>