测试更新WsKey

This commit is contained in:
ZJY 2021-09-04 07:39:58 +08:00
parent 2ef5f7c07d
commit 76bc7235cc
2 changed files with 15 additions and 36 deletions

View File

@ -110,16 +110,23 @@ var handleMessage = func(msgs ...interface{}) interface{} {
ck1.Telegram = sender.UserID
}
if nck, err := GetJdCookie(ck1.PtPin); err == nil {
if nck.WsKey == "" || len(nck.WsKey) == 0 {
nck.InPoolWskey(ck1.WsKey)
msg := fmt.Sprintf("写入WsKey%s", ck1.PtPin)
(&JdCookie{}).Push(msg)
logs.Info(msg)
if len(nck.PtPin) == 0 {
if nck.WsKey == "" || len(nck.WsKey) == 0 {
nck.Updates(JdCookie{
WsKey: ck1.WsKey,
})
msg := fmt.Sprintf("写入WsKey%s", ck1.PtPin)
(&JdCookie{}).Push(msg)
logs.Info(msg)
} else {
msg := fmt.Sprintf("重复写入")
(&JdCookie{}).Push(msg)
logs.Info(msg)
}
} else {
msg := fmt.Sprintf("重复写入")
(&JdCookie{}).Push(msg)
logs.Info(msg)
}
}
}

View File

@ -2,7 +2,6 @@ package models
import (
"fmt"
"github.com/beego/beego/v2/adapter/logs"
"strings"
"time"
@ -195,33 +194,6 @@ func (ck *JdCookie) Update(column string, value interface{}) {
}
}
func (ck *JdCookie) InPoolWskey(ws_key string) error {
if ck.ID != 0 {
date := Date()
tx := db.Begin()
jp := &JdCookiePool{}
logs.Info(ck.PtPin)
logs.Info(ws_key)
if tx.Where(fmt.Sprintf("%s = '%s'", PtPin, ck.PtPin)).First(jp).Error == nil {
return tx.Rollback().Error
}
if err := tx.Create(&JdCookiePool{
PtPin: ck.PtPin,
WsKey: ck.WsKey,
CreateAt: date,
}).Error; err != nil {
tx.Rollback()
return err
}
tx.Model(ck).Updates(map[string]interface{}{
Available: True,
WsKey: ws_key,
})
return tx.Commit().Error
}
return nil
}
func (ck *JdCookie) InPool(pt_key string) error {
if ck.ID != 0 {
date := Date()