From 5563025551ab07222754c62df997b5342b980cb6 Mon Sep 17 00:00:00 2001 From: ZJY <764763903@qq.com> Date: Wed, 15 Sep 2021 00:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/login.go | 48 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/controllers/login.go b/controllers/login.go index 5ef591b..5854671 100644 --- a/controllers/login.go +++ b/controllers/login.go @@ -35,6 +35,12 @@ type StepThree struct { Message string `json:"message"` } +type Result struct { + Code int `json:"code"` + Data interface{} `json:"data"` + Message string `json:"message"` +} + var JdCookieRunners sync.Map var jdua = models.GetUserAgent @@ -360,21 +366,55 @@ func (c *LoginController) CkLogin() { } if ptKey != "" && ptPin != "" { if models.CookieOK(ck) { + query := ck.Query() + result := Result{ + Data: query, + Code: 0, + } + if !models.HasPin(ptPin) { models.NewJdCookie(ck) - c.Ctx.WriteString(fmt.Sprintf("添加成功")) + result.Message = fmt.Sprintf("添加成功") + jsons, errs := json.Marshal(result) //转换成JSON返回的是byte[] + if errs != nil { + fmt.Println(errs.Error()) + } + c.Ctx.WriteString(string(jsons)) } else if !models.HasKey(ptKey) { ck, _ := models.GetJdCookie(ptPin) ck.InPool(ptKey) - c.Ctx.WriteString(fmt.Sprintf("更新成功")) + result.Message = fmt.Sprintf("更新成功") + jsons, errs := json.Marshal(result) //转换成JSON返回的是byte[] + if errs != nil { + fmt.Println(errs.Error()) + } + c.Ctx.WriteString(string(jsons)) } } else { - c.Ctx.WriteString("CK过期") + result := Result{ + Data: "null", + Code: 1, + Message: "CK过期", + } + jsons, errs := json.Marshal(result) //转换成JSON返回的是byte[] + if errs != nil { + fmt.Println(errs.Error()) + } + c.Ctx.WriteString(string(jsons)) } } } - c.Ctx.WriteString("ck格式错误") + result := Result{ + Data: "null", + Code: 2, + Message: "ck格式错误", + } + jsons, errs := json.Marshal(result) //转换成JSON返回的是byte[] + if errs != nil { + fmt.Println(errs.Error()) + } + c.Ctx.WriteString(string(jsons)) //if strings.Contains(ck,"pt_key") { // ptKey := FetchJdCookieValue("pt_key", msg)