|
@@ -12,6 +12,7 @@ import (
|
|
|
"os"
|
|
|
"qfw/util"
|
|
|
"spiderutil"
|
|
|
+ "sync/atomic"
|
|
|
"time"
|
|
|
|
|
|
"github.com/imroc/req"
|
|
@@ -26,9 +27,12 @@ type CodeService struct {
|
|
|
proto.GetCodeServer
|
|
|
}
|
|
|
|
|
|
+var PyTimes int64
|
|
|
+
|
|
|
//server
|
|
|
func main() {
|
|
|
util.Debug("port", spiderutil.Config.ServerPort)
|
|
|
+ go CountPyTimes() //统计使用超级鹰次数
|
|
|
lis, err := net.Listen("tcp", spiderutil.Config.ServerPort)
|
|
|
if err != nil {
|
|
|
util.Debug("failed to listen: ", err)
|
|
@@ -164,6 +168,7 @@ func getCodeByPay(path, stype, head, cookie string) (code string, respheader htt
|
|
|
json.Unmarshal([]byte(cookie), &cookies)
|
|
|
}
|
|
|
for times := 1; times <= 2; times++ { //重试三次
|
|
|
+ atomic.AddInt64(&PyTimes, 1)
|
|
|
if times > 1 { //重试第2次开始,使用代理ip
|
|
|
proxyIp := spiderutil.GetProxyAddr(spiderutil.Config.ProxyAddr, spiderutil.Config.ProxyAuthor) //获取代理地址
|
|
|
util.Debug("proxy:", proxyIp)
|
|
@@ -235,6 +240,24 @@ func savefile(url string, resp *req.Response) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func CountPyTimes() {
|
|
|
+ go func() {
|
|
|
+ for {
|
|
|
+ if time.Now().Hour() == 0 {
|
|
|
+ util.Debug("当天共使用超级鹰次数:", PyTimes)
|
|
|
+ PyTimes = 0
|
|
|
+ time.Sleep(1 * time.Hour)
|
|
|
+ } else {
|
|
|
+ time.Sleep(10 * time.Minute)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ for {
|
|
|
+ time.Sleep(1 * time.Minute)
|
|
|
+ util.Debug("当前使用超级鹰次数:", PyTimes)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//func main() {
|
|
|
// log.Println(util.Config)
|
|
|
// conn, err := grpc.Dial("127.0.0.1"+util.Config.Port, grpc.WithInsecure())
|