From 26ce00178232236a3974459bf412d0b93845241b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= Date: Thu, 27 Jan 2022 12:34:49 +0800 Subject: [PATCH] :sparkler: add ocr for 189 --- bootstrap/setting.go | 8 ++++++++ conf/var.go | 1 + drivers/189/189.go | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/bootstrap/setting.go b/bootstrap/setting.go index f0c3c05c..fa236f2f 100644 --- a/bootstrap/setting.go +++ b/bootstrap/setting.go @@ -219,6 +219,14 @@ func InitSettings() { Access: model.PUBLIC, Group: model.FRONT, }, + { + Key: "ocr api", + Value: "https://api.xhofe.top/ocr/file/json", + Description: "Used to identify verification codes", + Type: "string", + Access: model.PRIVATE, + Group: model.BACK, + }, } for i, _ := range settings { v := settings[i] diff --git a/conf/var.go b/conf/var.go index a391ca4e..a1d72440 100644 --- a/conf/var.go +++ b/conf/var.go @@ -78,6 +78,7 @@ var ( "check parent folder", "check down link", "WebDAV username", "WebDAV password", "Visitor WebDAV username", "Visitor WebDAV password", "default page size", "load type", + "ocr api", } ) diff --git a/drivers/189/189.go b/drivers/189/189.go index edc086bb..724f0fc5 100644 --- a/drivers/189/189.go +++ b/drivers/189/189.go @@ -153,6 +153,29 @@ func (driver Cloud189) Login(account *model.Account) error { vCodeRS := "" if vCodeID != "" { // need ValidateCode + log.Debugf("try to identify verification codes") + timeStamp := strconv.FormatInt(time.Now().UnixNano()/1e6, 10) + u := "https://open.e.189.cn/api/logbox/oauth2/picCaptcha.do?token=" + vCodeID + timeStamp + imgRes, err := client.R().SetHeaders(map[string]string{ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/76.0", + "Referer": "https://open.e.pan.cn/", + "Sec-Fetch-Dest": "image", + "Sec-Fetch-Mode": "no-cors", + "Sec-Fetch-Site": "same-origin", + }).Get(u) + if err != nil { + return err + } + vRes, err := client.R().SetMultipartField( + "image", "validateCode.png", "image/png", bytes.NewReader(imgRes.Body())). + Post(conf.GetStr("ocr api")) + if err != nil { + return err + } + if jsoniter.Get(vRes.Body(), "status").ToInt() != 200 { + return errors.New("ocr error:" + jsoniter.Get(vRes.Body(), "msg").ToString()) + } + vCodeRS = jsoniter.Get(vRes.Body(), "result").ToString() } userRsa := RsaEncode([]byte(account.Username), jRsakey) passwordRsa := RsaEncode([]byte(account.Password), jRsakey)