屏蔽京东二维码
This commit is contained in:
@@ -1,91 +1,83 @@
|
|||||||
package jdslogin
|
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 Creat By 2022/04/18
|
||||||
// RefreshQRCode Author By Hang xu
|
// RefreshQRCode Author By Hang xu
|
||||||
// RefreshQRCode 用于爬取京东的二维码链接 并持久化进入数据库中
|
// RefreshQRCode 用于爬取京东的二维码链接 并持久化进入数据库中
|
||||||
func RefreshQRCode() (retval string, err error) {
|
//func RefreshQRCode() (retval string, err error) {
|
||||||
baseapi.SugarLogger.Debug("BEGIN JD SHOP QRCODE SPIDER---------------------------------------------------")
|
// baseapi.SugarLogger.Debug("BEGIN JD SHOP QRCODE SPIDER---------------------------------------------------")
|
||||||
const (
|
// const (
|
||||||
seleniumPath = `/usr/bin/chromedriver`
|
// seleniumPath = `/usr/bin/chromedriver`
|
||||||
port = 9515
|
// port = 9515
|
||||||
)
|
// )
|
||||||
opts := []selenium.ServiceOption{}
|
// opts := []selenium.ServiceOption{}
|
||||||
|
//
|
||||||
selenium.SetDebug(true)
|
// selenium.SetDebug(true)
|
||||||
|
//
|
||||||
service, err := selenium.NewChromeDriverService(seleniumPath, port, opts...)
|
// service, err := selenium.NewChromeDriverService(seleniumPath, port, opts...)
|
||||||
if nil != err {
|
// if nil != err {
|
||||||
fmt.Println("start a chromedriver service falid", err.Error())
|
// fmt.Println("start a chromedriver service falid", err.Error())
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
////server关闭之后,chrome窗口也会关闭
|
// ////server关闭之后,chrome窗口也会关闭
|
||||||
defer service.Stop()
|
// defer service.Stop()
|
||||||
//链接本地的浏览器 chrome
|
// //链接本地的浏览器 chrome
|
||||||
caps := selenium.Capabilities{
|
// caps := selenium.Capabilities{
|
||||||
//"browserName": "/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev",
|
// //"browserName": "/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev",
|
||||||
"browserName": "/opt/google/chrome",
|
// "browserName": "/opt/google/chrome",
|
||||||
}
|
// }
|
||||||
//禁止图片加载,加快渲染速度
|
// //禁止图片加载,加快渲染速度
|
||||||
imagCaps := map[string]interface{}{
|
// imagCaps := map[string]interface{}{
|
||||||
"profile.managed_default_content_settings.images": 2,
|
// "profile.managed_default_content_settings.images": 2,
|
||||||
}
|
// }
|
||||||
chromeCaps := chrome.Capabilities{
|
// chromeCaps := chrome.Capabilities{
|
||||||
Prefs: imagCaps,
|
// Prefs: imagCaps,
|
||||||
Path: "/opt/google/chrome",
|
// Path: "/opt/google/chrome",
|
||||||
Args: []string{
|
// Args: []string{
|
||||||
//静默执行请求
|
// //静默执行请求
|
||||||
"--headless", // 设置Chrome无头模式,在linux下运行,需要设置这个参数,否则会报错
|
// "--headless", // 设置Chrome无头模式,在linux下运行,需要设置这个参数,否则会报错
|
||||||
"--no-sandbox",
|
// "--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,防反爬
|
// "--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",
|
// "--Host=porder.shop.jd.com",
|
||||||
"--Connection=keep-alive",
|
// "--Connection=keep-alive",
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
//以上是设置浏览器参数
|
// //以上是设置浏览器参数
|
||||||
caps.AddChrome(chromeCaps)
|
// caps.AddChrome(chromeCaps)
|
||||||
|
//
|
||||||
url := "https://porder.shop.jd.com/order/orderlist/allOrders"
|
// url := "https://porder.shop.jd.com/order/orderlist/allOrders"
|
||||||
w_b1, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
|
// w_b1, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
fmt.Println("connect to the webDriver faild", err.Error())
|
// fmt.Println("connect to the webDriver faild", err.Error())
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
err = w_b1.Get(url)
|
// err = w_b1.Get(url)
|
||||||
pageSource, err := w_b1.PageSource()
|
// pageSource, err := w_b1.PageSource()
|
||||||
baseapi.SugarLogger.Debug("pageSource", pageSource)
|
// baseapi.SugarLogger.Debug("pageSource", pageSource)
|
||||||
qr, err := w_b1.FindElement("id", "js-login-qrcode")
|
// qr, err := w_b1.FindElement("id", "js-login-qrcode")
|
||||||
qrStr, err := qr.GetAttribute("src")
|
// qrStr, err := qr.GetAttribute("src")
|
||||||
baseapi.SugarLogger.Debug("qrStr:", qrStr) //当前qrcode sample:https://passport.shop.jd.com/login/json/qrcode_show.action?_timeStr=165026591404449b823cc58684d948d0e0ca8351adf64
|
// baseapi.SugarLogger.Debug("qrStr:", qrStr) //当前qrcode sample:https://passport.shop.jd.com/login/json/qrcode_show.action?_timeStr=165026591404449b823cc58684d948d0e0ca8351adf64
|
||||||
// 进行存库操作
|
// // 进行存库操作
|
||||||
// save to database 存入 new_config表中
|
// // save to database 存入 new_config表中
|
||||||
db := dao.GetDB()
|
// db := dao.GetDB()
|
||||||
txDB, _ := dao.Begin(db)
|
// txDB, _ := dao.Begin(db)
|
||||||
defer func() {
|
// defer func() {
|
||||||
if r := recover(); r != nil {
|
// if r := recover(); r != nil {
|
||||||
dao.Rollback(db, txDB)
|
// dao.Rollback(db, txDB)
|
||||||
panic(r)
|
// panic(r)
|
||||||
}
|
// }
|
||||||
}()
|
// }()
|
||||||
configList, err := dao.QueryConfigs(db, "jdsQRcode", "Cookie", "")
|
// configList, err := dao.QueryConfigs(db, "jdsQRcode", "Cookie", "")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
dao.Rollback(db, txDB)
|
// dao.Rollback(db, txDB)
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
// }
|
||||||
if _, err = dao.UpdateEntityLogically(db, configList[0], map[string]interface{}{
|
// if _, err = dao.UpdateEntityLogically(db, configList[0], map[string]interface{}{
|
||||||
"Value": qrStr,
|
// "Value": qrStr,
|
||||||
}, "", nil); err != nil {
|
// }, "", nil); err != nil {
|
||||||
dao.Rollback(db, txDB)
|
// dao.Rollback(db, txDB)
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
// }
|
||||||
baseapi.SugarLogger.Debug("THE JD SHOP QRCODE SPIDER THE END---------------------------------------------")
|
// baseapi.SugarLogger.Debug("THE JD SHOP QRCODE SPIDER THE END---------------------------------------------")
|
||||||
return "", nil
|
// return "", nil
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package misc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/jdslogin"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -352,9 +351,9 @@ func Init() {
|
|||||||
/* ScheduleTimerFuncByInterval(func() {
|
/* ScheduleTimerFuncByInterval(func() {
|
||||||
jcq.JCQSchedule()
|
jcq.JCQSchedule()
|
||||||
}, 10*time.Second, 10*time.Second)*/
|
}, 10*time.Second, 10*time.Second)*/
|
||||||
ScheduleTimerFuncByInterval(func() {
|
//ScheduleTimerFuncByInterval(func() {
|
||||||
jdslogin.RefreshQRCode()
|
// jdslogin.RefreshQRCode()
|
||||||
}, 10*time.Second, 10*time.Minute)
|
//}, 10*time.Second, 10*time.Minute)
|
||||||
ScheduleTimerFunc("AutoSaleStoreSku", func() {
|
ScheduleTimerFunc("AutoSaleStoreSku", func() {
|
||||||
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
||||||
}, autoSaleStoreSkuTimeList)
|
}, autoSaleStoreSkuTimeList)
|
||||||
|
|||||||
Reference in New Issue
Block a user