Эх сурвалжийг харах

公共方法里新增detail取hash方法

maxiaoshan 2 жил өмнө
parent
commit
9b2cf39cb4
1 өөрчлөгдсөн 11 нэмэгдсэн , 0 устгасан
  1. 11 0
      src/spiderutil/util.go

+ 11 - 0
src/spiderutil/util.go

@@ -16,9 +16,13 @@ import (
 	"net/http"
 	"os"
 	"qfw/util"
+	"regexp"
 	"time"
 )
 
+var Reg = regexp.MustCompile("[^0-9A-Za-z\u4e00-\u9fa5]+")
+var Filter = regexp.MustCompile("<[^>]*?>|[\\s\u3000\u2003\u00a0]")
+
 //time.AfterFunc 加锁
 
 func TimeAfterFunc(td time.Duration, f func(), ch chan bool) {
@@ -206,6 +210,13 @@ func HexTextByte(text []byte) string {
 	return fmt.Sprintf("%x", h.Sum(nil))
 }
 
+func ShaDetail(con string) string {
+	h := sha256.New()
+	con = Reg.ReplaceAllString(Filter.ReplaceAllString(con, ""), "")
+	h.Write([]byte(con))
+	return fmt.Sprintf("%x", h.Sum(nil))
+}
+
 //判断当前时间是否是工作时间,工作时间周一至周五早7点至晚7点
 func IsWorkTime() bool {
 	tt := time.Now()