From fdbacbe83e3fa7f4c97b09b387067a775bf427ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 18 Apr 2022 19:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E4=BA=AC=E4=B8=9C=E4=BA=8C?= =?UTF-8?q?=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/jdslogin/jds_qrcode.go | 164 +++++++++--------- business/jxstore/misc/misc.go | 7 +- 2 files changed, 81 insertions(+), 90 deletions(-) diff --git a/business/jxcallback/scheduler/jdslogin/jds_qrcode.go b/business/jxcallback/scheduler/jdslogin/jds_qrcode.go index 4e7c4f29f..b3ea1b538 100644 --- a/business/jxcallback/scheduler/jdslogin/jds_qrcode.go +++ b/business/jxcallback/scheduler/jdslogin/jds_qrcode.go @@ -1,91 +1,83 @@ package jdslogin -import ( - "fmt" - "git.rosy.net.cn/baseapi" - "git.rosy.net.cn/jx-callback/business/model/dao" - "github.com/tebeka/selenium" - "github.com/tebeka/selenium/chrome" -) - // RefreshQRCode Creat By 2022/04/18 // RefreshQRCode Author By Hang xu // RefreshQRCode 用于爬取京东的二维码链接 并持久化进入数据库中 -func RefreshQRCode() (retval string, err error) { - baseapi.SugarLogger.Debug("BEGIN JD SHOP QRCODE SPIDER---------------------------------------------------") - const ( - seleniumPath = `/usr/bin/chromedriver` - port = 9515 - ) - opts := []selenium.ServiceOption{} - - selenium.SetDebug(true) - - service, err := selenium.NewChromeDriverService(seleniumPath, port, opts...) - if nil != err { - fmt.Println("start a chromedriver service falid", err.Error()) - return - } - ////server关闭之后,chrome窗口也会关闭 - defer service.Stop() - //链接本地的浏览器 chrome - caps := selenium.Capabilities{ - //"browserName": "/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev", - "browserName": "/opt/google/chrome", - } - //禁止图片加载,加快渲染速度 - imagCaps := map[string]interface{}{ - "profile.managed_default_content_settings.images": 2, - } - chromeCaps := chrome.Capabilities{ - Prefs: imagCaps, - Path: "/opt/google/chrome", - Args: []string{ - //静默执行请求 - "--headless", // 设置Chrome无头模式,在linux下运行,需要设置这个参数,否则会报错 - "--no-sandbox", - "--user-agent=Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36", // 模拟user-agent,防反爬 - "--Host=porder.shop.jd.com", - "--Connection=keep-alive", - }, - } - //以上是设置浏览器参数 - caps.AddChrome(chromeCaps) - - url := "https://porder.shop.jd.com/order/orderlist/allOrders" - w_b1, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port)) - if err != nil { - fmt.Println("connect to the webDriver faild", err.Error()) - return - } - - err = w_b1.Get(url) - pageSource, err := w_b1.PageSource() - baseapi.SugarLogger.Debug("pageSource", pageSource) - qr, err := w_b1.FindElement("id", "js-login-qrcode") - qrStr, err := qr.GetAttribute("src") - baseapi.SugarLogger.Debug("qrStr:", qrStr) //当前qrcode sample:https://passport.shop.jd.com/login/json/qrcode_show.action?_timeStr=165026591404449b823cc58684d948d0e0ca8351adf64 - // 进行存库操作 - // save to database 存入 new_config表中 - db := dao.GetDB() - txDB, _ := dao.Begin(db) - defer func() { - if r := recover(); r != nil { - dao.Rollback(db, txDB) - panic(r) - } - }() - configList, err := dao.QueryConfigs(db, "jdsQRcode", "Cookie", "") - if err != nil { - dao.Rollback(db, txDB) - return "", err - } - if _, err = dao.UpdateEntityLogically(db, configList[0], map[string]interface{}{ - "Value": qrStr, - }, "", nil); err != nil { - dao.Rollback(db, txDB) - return "", err - } - baseapi.SugarLogger.Debug("THE JD SHOP QRCODE SPIDER THE END---------------------------------------------") - return "", nil -} +//func RefreshQRCode() (retval string, err error) { +// baseapi.SugarLogger.Debug("BEGIN JD SHOP QRCODE SPIDER---------------------------------------------------") +// const ( +// seleniumPath = `/usr/bin/chromedriver` +// port = 9515 +// ) +// opts := []selenium.ServiceOption{} +// +// selenium.SetDebug(true) +// +// service, err := selenium.NewChromeDriverService(seleniumPath, port, opts...) +// if nil != err { +// fmt.Println("start a chromedriver service falid", err.Error()) +// return +// } +// ////server关闭之后,chrome窗口也会关闭 +// defer service.Stop() +// //链接本地的浏览器 chrome +// caps := selenium.Capabilities{ +// //"browserName": "/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev", +// "browserName": "/opt/google/chrome", +// } +// //禁止图片加载,加快渲染速度 +// imagCaps := map[string]interface{}{ +// "profile.managed_default_content_settings.images": 2, +// } +// chromeCaps := chrome.Capabilities{ +// Prefs: imagCaps, +// Path: "/opt/google/chrome", +// Args: []string{ +// //静默执行请求 +// "--headless", // 设置Chrome无头模式,在linux下运行,需要设置这个参数,否则会报错 +// "--no-sandbox", +// "--user-agent=Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36", // 模拟user-agent,防反爬 +// "--Host=porder.shop.jd.com", +// "--Connection=keep-alive", +// }, +// } +// //以上是设置浏览器参数 +// caps.AddChrome(chromeCaps) +// +// url := "https://porder.shop.jd.com/order/orderlist/allOrders" +// w_b1, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port)) +// if err != nil { +// fmt.Println("connect to the webDriver faild", err.Error()) +// return +// } +// +// err = w_b1.Get(url) +// pageSource, err := w_b1.PageSource() +// baseapi.SugarLogger.Debug("pageSource", pageSource) +// qr, err := w_b1.FindElement("id", "js-login-qrcode") +// qrStr, err := qr.GetAttribute("src") +// baseapi.SugarLogger.Debug("qrStr:", qrStr) //当前qrcode sample:https://passport.shop.jd.com/login/json/qrcode_show.action?_timeStr=165026591404449b823cc58684d948d0e0ca8351adf64 +// // 进行存库操作 +// // save to database 存入 new_config表中 +// db := dao.GetDB() +// txDB, _ := dao.Begin(db) +// defer func() { +// if r := recover(); r != nil { +// dao.Rollback(db, txDB) +// panic(r) +// } +// }() +// configList, err := dao.QueryConfigs(db, "jdsQRcode", "Cookie", "") +// if err != nil { +// dao.Rollback(db, txDB) +// return "", err +// } +// if _, err = dao.UpdateEntityLogically(db, configList[0], map[string]interface{}{ +// "Value": qrStr, +// }, "", nil); err != nil { +// dao.Rollback(db, txDB) +// return "", err +// } +// baseapi.SugarLogger.Debug("THE JD SHOP QRCODE SPIDER THE END---------------------------------------------") +// return "", nil +//} diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index dce9d047b..5f6c1ba88 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -2,7 +2,6 @@ package misc import ( "fmt" - "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/jdslogin" "git.rosy.net.cn/jx-callback/business/partner/delivery" "sync" "time" @@ -352,9 +351,9 @@ func Init() { /* ScheduleTimerFuncByInterval(func() { jcq.JCQSchedule() }, 10*time.Second, 10*time.Second)*/ - ScheduleTimerFuncByInterval(func() { - jdslogin.RefreshQRCode() - }, 10*time.Second, 10*time.Minute) + //ScheduleTimerFuncByInterval(func() { + // jdslogin.RefreshQRCode() + //}, 10*time.Second, 10*time.Minute) ScheduleTimerFunc("AutoSaleStoreSku", func() { cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false) }, autoSaleStoreSkuTimeList)