From ccad4c05f75e58da03a1f9dbd3c2393a0415e304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <357099073@qq.com> Date: Mon, 13 Apr 2026 09:24:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E5=8F=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/api_getcard.go | 207 +++++++++++++++++++++++++++++++++++++ routers/api/api.go | 4 + 2 files changed, 211 insertions(+) create mode 100644 controllers/api_getcard.go diff --git a/controllers/api_getcard.go b/controllers/api_getcard.go new file mode 100644 index 0000000..6597ab9 --- /dev/null +++ b/controllers/api_getcard.go @@ -0,0 +1,207 @@ +package controllers + +import ( + "fmt" + "time" + + "server/models" + + "github.com/beego/beego/v2/client/orm" + beego "github.com/beego/beego/v2/server/web" +) + +// ApiGetCardController 对外提卡接口(无需登录) +// GET /api/getcard?type=xianyu&module=cursor +type ApiGetCardController struct { + beego.Controller +} + +// validPlatformTypes 支持的来源平台 +var validPlatformTypes = map[string]bool{ + "xianyu": true, + "pinduoduo": true, + "jingdong": true, + "douyin": true, + "local": true, +} + +// validModules 支持的号池模块 +var validModules = map[string]bool{ + "cursor": true, + "windsurf": true, + "krio": true, +} + +func (c *ApiGetCardController) cardErr(httpStatus, code int, msg string) { + c.Ctx.Output.SetStatus(httpStatus) + c.Data["json"] = map[string]interface{}{"code": code, "msg": msg} + _ = c.ServeJSON() +} + +func (c *ApiGetCardController) cardOK(data interface{}) { + c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data} + _ = c.ServeJSON() +} + +// GetCard 提取一张卡(不可重复提取) +// GET /api/getcard?type=xianyu&module=cursor&data_type=tk +// +// 参数: +// - type (必填) 来源平台:xianyu / taobao / pinduoduo / jingdong / local +// - module (必填) 号池模块:cursor / windsurf / krio +// - data_type (可选) 账号类型:account / tk / account_tk,不传则取任意未提取的 +func (c *ApiGetCardController) GetCard() { + platform := c.GetString("type") + module := c.GetString("module") + dataType := c.GetString("data_type") + + // 参数校验 + if platform == "" { + c.cardErr(400, 400, "缺少参数 type(来源平台)") + return + } + if !validPlatformTypes[platform] { + c.cardErr(400, 400, fmt.Sprintf("不支持的平台类型: %s,支持: xianyu/taobao/pinduoduo/jingdong/local", platform)) + return + } + if module == "" { + c.cardErr(400, 400, "缺少参数 module(号池模块)") + return + } + if !validModules[module] { + c.cardErr(400, 400, fmt.Sprintf("不支持的模块: %s,支持: cursor/windsurf/krio", module)) + return + } + if dataType != "" && !isValidPoolType(dataType) { + c.cardErr(400, 400, "data_type 不合法,支持: account/tk/account_tk") + return + } + + now := time.Now() + + switch module { + case "cursor": + c.extractCursor(platform, dataType, now) + case "windsurf": + c.extractWindsurf(platform, dataType, now) + case "krio": + c.extractKrio(platform, dataType, now) + } +} + +func (c *ApiGetCardController) extractCursor(platform, dataType string, now time.Time) { + var row models.PlatformAccountPoolCursor + qs := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)). + Filter("is_extracted", 0). + Filter("delete_time__isnull", true) + if dataType != "" { + qs = qs.Filter("data_type", dataType) + } + if err := qs.OrderBy("id").One(&row); err != nil { + if err == orm.ErrNoRows { + c.cardErr(404, 404, "暂无可用卡密") + } else { + c.cardErr(500, 500, "查询失败") + } + return + } + _, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)). + Filter("id", row.ID). + Update(map[string]interface{}{ + "is_extracted": 1, + "extracted_time": now, + "extracted_platform": platform, + }) + if err != nil { + c.cardErr(500, 500, "提取失败") + return + } + c.cardOK(buildCardResult(&row.Account, &row.Password, row.Token, row.DataType)) +} + +func (c *ApiGetCardController) extractWindsurf(platform, dataType string, now time.Time) { + var row models.PlatformAccountPoolWindsurf + qs := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)). + Filter("is_extracted", 0). + Filter("delete_time__isnull", true) + if dataType != "" { + qs = qs.Filter("data_type", dataType) + } + if err := qs.OrderBy("id").One(&row); err != nil { + if err == orm.ErrNoRows { + c.cardErr(404, 404, "暂无可用卡密") + } else { + c.cardErr(500, 500, "查询失败") + } + return + } + _, err := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)). + Filter("id", row.ID). + Update(map[string]interface{}{ + "is_extracted": 1, + "extracted_time": now, + "extracted_platform": platform, + }) + if err != nil { + c.cardErr(500, 500, "提取失败") + return + } + c.cardOK(buildCardResult(&row.Account, &row.Password, row.Token, row.DataType)) +} + +func (c *ApiGetCardController) extractKrio(platform, dataType string, now time.Time) { + var row models.PlatformAccountPoolKiro + qs := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)). + Filter("is_extracted", 0). + Filter("delete_time__isnull", true) + if dataType != "" { + qs = qs.Filter("data_type", dataType) + } + if err := qs.OrderBy("id").One(&row); err != nil { + if err == orm.ErrNoRows { + c.cardErr(404, 404, "暂无可用卡密") + } else { + c.cardErr(500, 500, "查询失败") + } + return + } + _, err := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)). + Filter("id", row.ID). + Update(map[string]interface{}{ + "is_extracted": 1, + "extracted_time": now, + "extracted_platform": platform, + }) + if err != nil { + c.cardErr(500, 500, "提取失败") + return + } + c.cardOK(buildCardResult(&row.Account, &row.Password, row.Token, row.DataType)) +} + +// buildCardResult 根据账号类型组装返回数据 +func buildCardResult(account, password *string, token string, dataType string) map[string]interface{} { + result := map[string]interface{}{ + "type": dataType, + } + acc := "" + pwd := "" + if account != nil { + acc = *account + } + if password != nil { + pwd = *password + } + switch dataType { + case "account": + result["account"] = acc + result["password"] = pwd + case "tk": + result["token"] = token + case "account_tk": + result["account"] = acc + result["password"] = pwd + result["token"] = token + } + return result +} diff --git a/routers/api/api.go b/routers/api/api.go index 9667675..1ebffd7 100644 --- a/routers/api/api.go +++ b/routers/api/api.go @@ -10,4 +10,8 @@ import ( func Register() { // 客户端检查更新(无需登录) beego.Router("/api/softwareupgrade/check", &controllers.ApiSoftwareUpgradeController{}, "get:Check") + + // 对外提卡接口(无需登录) + // GET /api/getcard?type=xianyu&module=cursor&data_type=tk + beego.Router("/api/getcard", &controllers.ApiGetCardController{}, "get:GetCard") }