Files
fanqie-go/internal/fqapi/category_front.go
T
chenxin 6981148727 🔧 chore: 初始化番茄小说 API 项目结构
新增项目基础框架,包含核心 API 实现、算法模块、HTTP 处理器等完整功能模块
2026-08-28 15:22:22 +08:00

45 lines
1.0 KiB
Go

package fqapi
import (
"fanqie/internal/common"
"fmt"
)
var categoryFrontLogger = common.NewLogger("category_front", "INFO", "")
// HandleCategoryFront 处理获取分类列表
func HandleCategoryFront(tab interface{}) (string, error) {
tabInt := ParseIntParam(tab, 0)
reqURL := BuildURL(
"https://reading.snssdk.com/reading/bookapi/new_category/front/v/",
fmt.Sprintf("new_category_tab=%d", tabInt),
fmt.Sprintf("update_version_code=%s", "58932"),
"distinct_style=1",
)
resp, err := GorgonRequest(reqURL, map[string]interface{}{
"method": "GET",
"headers": map[string]string{
"User-Agent": "com.dragon.read",
},
})
if err != nil {
categoryFrontLogger.Error(fmt.Sprintf("获取分类列表失败: %v", err))
return BuildErrorResponse("请求失败"), err
}
respJSON, err := resp.JSON()
if err != nil {
return BuildErrorResponse("解析响应失败"), err
}
if code, ok := respJSON["code"].(float64); ok && code == 0 {
return resp.Text, nil
}
return BuildErrorResponse("获取失败"), nil
}