add 修复wskey不会定时转换问题

This commit is contained in:
ZJY 2021-09-30 10:28:42 +08:00
parent ede3c11dbf
commit 938770805c
2 changed files with 33 additions and 38 deletions

View File

@ -36,6 +36,11 @@ type StepThree struct {
Message string `json:"message"` Message string `json:"message"`
} }
type StepThree1 struct {
Code int `json:"code"`
Message string `json:"message"`
}
type Result struct { type Result struct {
Code int `json:"code"` Code int `json:"code"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
@ -205,13 +210,15 @@ func init() {
jd_token := k.(string) jd_token := k.(string)
vv := v.([]interface{}) vv := v.([]interface{})
if len(vv) >= 2 { if len(vv) >= 2 {
cookie := vv[0].(string) //cookie := vv[0].(string)
okl_token := vv[1].(string) //okl_token := vv[1].(string)
bot := vv[2].(string) bot := vv[2].(string)
uid := vv[3].(int) uid := vv[3].(int)
gid := vv[4].(int) gid := vv[4].(int)
// fmt.Println(jd_token, cookie, okl_token) // fmt.Println(jd_token, cookie, okl_token)
result, ck := CheckLogin(jd_token, cookie, okl_token) result, ck := CheckLogin(models.QQuery{
Code: 0,
}, jd_token)
// fmt.Println(result) // fmt.Println(result)
switch result { switch result {
case "成功": case "成功":
@ -294,40 +301,28 @@ func (c *LoginController) Query() {
} }
} }
func CheckLogin(token, cookie, okl_token string) (string, *models.JdCookie) { func CheckLogin(q models.QQuery, token string) (string, *models.JdCookie) {
state := time.Now().Unix() //state := time.Now().Unix()
req := httplib.Post( req := httplib.Post("https://api.kukuqaq.com/jd/cookie")
fmt.Sprintf(`https://plogin.m.jd.com/cgi-bin/m/tmauthchecktoken?&token=%s&ou_state=0&okl_token=%s`, req.Param("sig", q.Data.QqLoginQrcode.Sig)
token, req.Param("type", string(1))
okl_token,
),
)
req.Header("Referer", fmt.Sprintf(`https://plogin.m.jd.com/login/login?appid=300&returnurl=https://wqlogin2.jd.com/passport/LoginRedirect?state=%d&returnurl=//home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport`,
state),
)
req.Header("Cookie", cookie)
req.Header("Connection", "Keep-Alive")
req.Header("Content-Type", "application/x-www-form-urlencoded; Charset=UTF-8")
req.Header("Accept", "application/json, text/plain, */*")
req.Header("User-Agent", jdua())
req.Header("Host", "plogin.m.jd.com")
req.Param("lang", "chs") req.Param("redirectUrl", q.Data.RedirectURL)
req.Param("appid", "300") req.Param("state", q.Data.State)
req.Param("returnurl", fmt.Sprintf("https://wqlogin2.jd.com/passport/LoginRedirect?state=%d&returnurl=//home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action", state)) req.Param("tempCookie", q.Data.TempCookie)
req.Param("source", "wq_passport") req.Param("lSid", q.Data.LSid)
rsp, err := req.Response() rsp, err := req.Response()
if err != nil { if err != nil {
return "", nil //err.Error() return "", nil //err.Error()
} }
data, err := ioutil.ReadAll(rsp.Body) data, err := ioutil.ReadAll(rsp.Body)
sth := StepThree{} sth := StepThree1{}
err = json.Unmarshal(data, &sth) err = json.Unmarshal(data, &sth)
if err != nil { if err != nil {
return "", nil //err.Error() return "", nil //err.Error()
} }
switch sth.Errcode { switch sth.Code {
case 0: case 0:
cookies := strings.Join(rsp.Header.Values("Set-Cookie"), " ") cookies := strings.Join(rsp.Header.Values("Set-Cookie"), " ")
pt_key := FetchJdCookieValue("pt_key", cookies) pt_key := FetchJdCookieValue("pt_key", cookies)
@ -360,19 +355,19 @@ func CheckLogin(token, cookie, okl_token string) (string, *models.JdCookie) {
}() }()
JdCookieRunners.Store(token, []interface{}{pt_pin}) JdCookieRunners.Store(token, []interface{}{pt_pin})
return "成功", &ck return "成功", &ck
case 19: //Token无效请退出重试 case 500: //Token无效请退出重试
JdCookieRunners.Delete(token) JdCookieRunners.Delete(token)
return sth.Message, nil return sth.Message, nil
case 21: //Token不存在请退出重试 //case 21: //Token不存在请退出重试
JdCookieRunners.Delete(token) // JdCookieRunners.Delete(token)
return sth.Message, nil // return sth.Message, nil
case 176: //授权登录未确认 //case 176: //授权登录未确认
return sth.Message, nil // return sth.Message, nil
case 258: //务异常,请稍后重试 //case 258: //务异常,请稍后重试
return "", nil // return "", nil
case 264: //出错了,请退出重试 //case 264: //出错了,请退出重试
// JdCookieRunners.Delete(token) // // JdCookieRunners.Delete(token)
// return sth.Message, nil // // return sth.Message, nil
default: default:
JdCookieRunners.Delete(token) JdCookieRunners.Delete(token)
// fmt.Println(sth) // fmt.Println(sth)

View File

@ -10,7 +10,7 @@ func intiSky() {
c := cron.New(cron.WithSeconds()) //精确到秒 c := cron.New(cron.WithSeconds()) //精确到秒
//定时任务 //定时任务
spec := "0 0" + Config.CTime + "/12 * * ?" //cron表达式每秒一次 spec := "0 0 " + Config.CTime + "/12 * * ?" //cron表达式每秒一次
logs.Info(spec) logs.Info(spec)
if Config.Wskey { if Config.Wskey {
c.AddFunc(spec, func() { c.AddFunc(spec, func() {