🔧 chore: 初始化番茄小说 API 项目结构
新增项目基础框架,包含核心 API 实现、算法模块、HTTP 处理器等完整功能模块
This commit is contained in:
commit
6981148727
107 files changed
+12463
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package fqapi
|
||||
|
||||
import (
|
||||
"fanqie/internal/common"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
var searchLogger = common.NewLogger("search", "INFO", "")
|
||||
|
||||
// GetDeviceHeader 获取设备header(需要从外部注入)
|
||||
var GetDeviceHeader func() string
|
||||
|
||||
// HandleBookSearch 处理书籍搜索
|
||||
func HandleBookSearch(key string, offset int, tabType int) (string, error) {
|
||||
if key == "" {
|
||||
return BuildErrorResponseWithCode(1, "需要参数 key"), nil
|
||||
}
|
||||
|
||||
if tabType == 0 {
|
||||
tabType = 3
|
||||
}
|
||||
|
||||
// 编码查询关键字
|
||||
encodedKey := url.QueryEscape(key)
|
||||
|
||||
// 使用新的参数构建函数
|
||||
reqURL := BuildURL("https://reading.snssdk.com/reading/bookapi/search/tab/v/",
|
||||
fmt.Sprintf("tab_type=%d", tabType),
|
||||
"update_version_code=58932",
|
||||
"query="+encodedKey,
|
||||
fmt.Sprintf("passback=%d", offset),
|
||||
)
|
||||
|
||||
resp, err := GorgonRequest(reqURL, map[string]interface{}{
|
||||
"method": "GET",
|
||||
"headers": map[string]string{
|
||||
"User-Agent": "com.dragon.read",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
searchLogger.Error(fmt.Sprintf("搜索请求失败: %v", err))
|
||||
return BuildErrorResponseWithCode(1, "搜索请求失败"), err
|
||||
}
|
||||
|
||||
respJSON, err := resp.JSON()
|
||||
if err != nil {
|
||||
searchLogger.Error(fmt.Sprintf("解析响应失败: %v", err))
|
||||
return BuildErrorResponseWithCode(1, "解析响应失败"), err
|
||||
}
|
||||
|
||||
if code, ok := respJSON["code"].(float64); ok && code == 0 {
|
||||
return resp.Text, nil
|
||||
}
|
||||
|
||||
return BuildErrorResponseWithCode(1, "搜索失败"), nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user