package fqapi import ( "fanqie/internal/common" "fmt" ) var categoryLandingLogger = common.NewLogger("category_landing", "INFO", "") // HandleCategoryLanding 处理获取分类详情,分类详情短缓存 10 分钟 func HandleCategoryLanding(categoryID, offset, wordNumber, bookStatus, sortBy interface{}) (string, error) { return withCache(fmt.Sprintf("category_landing_%v_%v_%v_%v_%v", categoryID, offset, wordNumber, bookStatus, sortBy), 600, func() (string, error) { return fetchCategoryLanding(categoryID, offset, wordNumber, bookStatus, sortBy) }) } func fetchCategoryLanding(categoryID, offset, wordNumber, bookStatus, sortBy interface{}) (string, error) { // 参数转换 categoryIDInt := ParseIntParam(categoryID, 0) offsetInt := ParseIntParam(offset, 0) wordNumberInt := ParseIntParam(wordNumber, 0) bookStatusInt := ParseIntParam(bookStatus, 0) sortByInt := ParseIntParam(sortBy, 0) if categoryIDInt == 0 { return BuildErrorResponseWithCode(100144, "参数错误"), nil } reqURL := BuildURL( "https://reading.snssdk.com/reading/bookapi/new_category/landing/v/", fmt.Sprintf("category_id=%d", categoryIDInt), fmt.Sprintf("limit=%d", 20), fmt.Sprintf("offset=%d", offsetInt), fmt.Sprintf("word_number=%d", wordNumberInt), fmt.Sprintf("book_status=%d", bookStatusInt), fmt.Sprintf("sort_by=%d", sortByInt), ) resp, err := GorgonRequest(reqURL, map[string]interface{}{ "method": "GET", "headers": map[string]string{ "User-Agent": "com.dragon.read", }, }) if err != nil { categoryLandingLogger.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 reencodeUnwrapped(resp.Text), nil } return BuildErrorResponse("获取失败"), nil }