|
@@ -3,11 +3,14 @@ package spiderutil
|
|
|
|
|
|
import (
|
|
|
"crypto/md5"
|
|
|
+ "crypto/sha256"
|
|
|
"encoding/base64"
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/yuin/gopher-lua"
|
|
|
+ "io"
|
|
|
+ "math/big"
|
|
|
"math/rand"
|
|
|
"net/http"
|
|
|
"os"
|
|
@@ -177,6 +180,31 @@ func GetRandMath(num int) int {
|
|
|
return r.Intn(num)
|
|
|
}
|
|
|
|
|
|
+//对href哈希取模
|
|
|
+func HexToBigIntMod(href string) int {
|
|
|
+ //取哈希值
|
|
|
+ t := sha256.New()
|
|
|
+ io.WriteString(t, href)
|
|
|
+ hex := fmt.Sprintf("%x", t.Sum(nil))
|
|
|
+ //取模
|
|
|
+ n := new(big.Int)
|
|
|
+ n, _ = n.SetString(hex[2:], 16)
|
|
|
+ return int(n.Mod(n, big.NewInt(16)).Int64())
|
|
|
+}
|
|
|
+
|
|
|
+//求hash
|
|
|
+func HexText(href string) string {
|
|
|
+ h := sha256.New()
|
|
|
+ h.Write([]byte(href))
|
|
|
+ return fmt.Sprintf("%x", h.Sum(nil))
|
|
|
+}
|
|
|
+
|
|
|
+func HexTextByte(text []byte) string {
|
|
|
+ h := sha256.New()
|
|
|
+ h.Write(text)
|
|
|
+ return fmt.Sprintf("%x", h.Sum(nil))
|
|
|
+}
|
|
|
+
|
|
|
//判断当前时间是否是工作时间,工作时间周一至周五早7点至晚7点
|
|
|
func IsWorkTime() bool {
|
|
|
tt := time.Now()
|