feat(API): 支持新版吧内搜索
This commit is contained in:
parent
d7f19e2f1e
commit
d99f723cbc
|
|
@ -3,27 +3,12 @@ package com.huanchengfly.tieba.post.api
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.body.MyMultipartBody
|
import com.huanchengfly.tieba.post.api.retrofit.body.MyMultipartBody
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
import okio.Buffer
|
import okio.Buffer
|
||||||
import java.io.UnsupportedEncodingException
|
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
|
||||||
fun String.urlEncode(): String {
|
fun String.urlEncode(): String = runCatching { URLEncoder.encode(this, "UTF-8") }.getOrDefault(this)
|
||||||
return try {
|
|
||||||
URLEncoder.encode(this, "UTF-8")
|
|
||||||
} catch (e: UnsupportedEncodingException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun String.urlDecode(): String {
|
fun String.urlDecode(): String = runCatching { URLDecoder.decode(this, "UTF-8") }.getOrDefault(this)
|
||||||
return try {
|
|
||||||
URLDecoder.decode(this, "UTF-8")
|
|
||||||
} catch (e: UnsupportedEncodingException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FormBody.containsEncodedName(name: String): Boolean {
|
fun FormBody.containsEncodedName(name: String): Boolean {
|
||||||
repeat(size) {
|
repeat(size) {
|
||||||
|
|
@ -49,7 +34,7 @@ fun FormBody.raw() =
|
||||||
}.toString()
|
}.toString()
|
||||||
|
|
||||||
fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
|
fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
|
||||||
val nameAndValue = ArrayList<String>()
|
val nameAndValue = mutableListOf<String>()
|
||||||
repeat(size) {
|
repeat(size) {
|
||||||
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
|
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +43,7 @@ fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FormBody.sortedRaw(separator: Boolean = true): String {
|
fun FormBody.sortedRaw(separator: Boolean = true): String {
|
||||||
val nameAndValue = ArrayList<String>()
|
val nameAndValue = mutableListOf<String>()
|
||||||
repeat(size) {
|
repeat(size) {
|
||||||
nameAndValue.add("${name(it)}=${value(it)}")
|
nameAndValue.add("${name(it)}=${value(it)}")
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +101,7 @@ fun MyMultipartBody.newBuilder(): MyMultipartBody.Builder =
|
||||||
|
|
||||||
fun MyMultipartBody.sort(): MyMultipartBody {
|
fun MyMultipartBody.sort(): MyMultipartBody {
|
||||||
val builder = newBuilder()
|
val builder = newBuilder()
|
||||||
var fileParts = mutableListOf<MyMultipartBody.Part>()
|
val fileParts = mutableListOf<MyMultipartBody.Part>()
|
||||||
parts.forEach {
|
parts.forEach {
|
||||||
if (it.fileName() != null) {
|
if (it.fileName() != null) {
|
||||||
fileParts.add(it)
|
fileParts.add(it)
|
||||||
|
|
|
||||||
|
|
@ -947,6 +947,27 @@ interface ITiebaApi {
|
||||||
sort: Int,
|
sort: Int,
|
||||||
): Flow<SearchThreadBean>
|
): 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 接口)
|
* 上传图片(web 接口)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ import com.huanchengfly.tieba.post.models.MyInfoBean
|
||||||
import com.huanchengfly.tieba.post.models.PhotoInfoBean
|
import com.huanchengfly.tieba.post.models.PhotoInfoBean
|
||||||
import com.huanchengfly.tieba.post.toJson
|
import com.huanchengfly.tieba.post.toJson
|
||||||
import com.huanchengfly.tieba.post.utils.AccountUtil
|
import com.huanchengfly.tieba.post.utils.AccountUtil
|
||||||
|
import com.huanchengfly.tieba.post.utils.CuidUtils
|
||||||
import com.huanchengfly.tieba.post.utils.ImageUtil
|
import com.huanchengfly.tieba.post.utils.ImageUtil
|
||||||
import kotlinx.coroutines.Deferred
|
import kotlinx.coroutines.Deferred
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
@ -671,6 +672,28 @@ object MixedTiebaApiImpl : ITiebaApi {
|
||||||
sort
|
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=×tamp=${System.currentTimeMillis()}&_client_version=${ClientVersion.TIEBA_V12.version}&_client_type=2"
|
||||||
|
)
|
||||||
|
|
||||||
override fun webUploadPic(photoInfoBean: PhotoInfoBean): Call<WebUploadPicBean> {
|
override fun webUploadPic(photoInfoBean: PhotoInfoBean): Call<WebUploadPicBean> {
|
||||||
var base64: String? = null
|
var base64: String? = null
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,11 @@ interface AppHybridTiebaApi {
|
||||||
@Query("pn") page: Int,
|
@Query("pn") page: Int,
|
||||||
@Query("st") sort: Int,
|
@Query("st") sort: Int,
|
||||||
@Query("tt") filter: Int = 1,
|
@Query("tt") filter: Int = 1,
|
||||||
|
@Query("rn") pageSize: Int? = null,
|
||||||
|
@Query("fname") forumName: String? = null,
|
||||||
@Query("ct") ct: Int = 1,
|
@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(),
|
@Header("Referer") referer: String = "https://tieba.baidu.com/mo/q/hybrid/search?keyword=$keyword&_webview_time=${System.currentTimeMillis()}".urlEncode(),
|
||||||
): Flow<SearchThreadBean>
|
): Flow<SearchThreadBean>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue