|
@@ -3,8 +3,10 @@ package util
|
|
import (
|
|
import (
|
|
MC "app.yhyue.com/moapp/jybase/common"
|
|
MC "app.yhyue.com/moapp/jybase/common"
|
|
ME "app.yhyue.com/moapp/jybase/encrypt"
|
|
ME "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/fsw"
|
|
"crypto/rand"
|
|
"crypto/rand"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "errors"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
@@ -14,6 +16,7 @@ import (
|
|
"math/big"
|
|
"math/big"
|
|
"net/http"
|
|
"net/http"
|
|
"net/url"
|
|
"net/url"
|
|
|
|
+ "reflect"
|
|
"regexp"
|
|
"regexp"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
@@ -241,7 +244,7 @@ func IndustryFormat(industry, subScopeClass string) (newIndustry string) {
|
|
}
|
|
}
|
|
|
|
|
|
// SearchListFormat 格式化数据
|
|
// SearchListFormat 格式化数据
|
|
-func SearchListFormat(industry string, repl *[]map[string]interface{}, b bool) (list []*bxcore.SearchList) {
|
|
|
|
|
|
+func SearchListFormat(userid, industry string, repl *[]map[string]interface{}, b bool) (list []*bxcore.SearchList) {
|
|
for _, v := range *repl {
|
|
for _, v := range *repl {
|
|
var searchList = &bxcore.SearchList{}
|
|
var searchList = &bxcore.SearchList{}
|
|
//正文
|
|
//正文
|
|
@@ -254,6 +257,9 @@ func SearchListFormat(industry string, repl *[]map[string]interface{}, b bool) (
|
|
}
|
|
}
|
|
searchList.Detail = detail
|
|
searchList.Detail = detail
|
|
}
|
|
}
|
|
|
|
+ if userid == "" {
|
|
|
|
+ v = Filter(v)
|
|
|
|
+ }
|
|
searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"])) //ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"])) //加密信息id
|
|
searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"])) //ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"])) //加密信息id
|
|
searchList.Area = MC.ObjToString(v["area"]) //地区
|
|
searchList.Area = MC.ObjToString(v["area"]) //地区
|
|
searchList.AreaUrl = IC.LabelMap[searchList.Area].Url //地区分类链接
|
|
searchList.AreaUrl = IC.LabelMap[searchList.Area].Url //地区分类链接
|
|
@@ -359,3 +365,88 @@ func GetPublishTime(y, m int, publishTime string) string {
|
|
}
|
|
}
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 未登录用户进行数据过滤
|
|
|
|
+func Filter(obj map[string]interface{}) map[string]interface{} {
|
|
|
|
+ detail := fmt.Sprint(obj["detail"])
|
|
|
|
+ mosaicText := IC.C.DetailMosaicTxt
|
|
|
|
+ for k, _ := range obj {
|
|
|
|
+ needMosaic := MC.StructToMapMore(IC.C.NeedMosaic)
|
|
|
|
+ if ok, _ := needMosaic[k].(bool); ok {
|
|
|
|
+ if MC.ObjToString(obj[k]) != "" {
|
|
|
|
+ detail = strings.ReplaceAll(detail, MC.ObjToString(obj[k]), mosaicText)
|
|
|
|
+ //敏感词过滤
|
|
|
|
+ }
|
|
|
|
+ if k == "winnerMap" {
|
|
|
|
+ winnerMap, _ := obj[k].(map[string]interface{})
|
|
|
|
+ mosaicMap := map[string]interface{}{}
|
|
|
|
+ for i := 0; i < len(winnerMap); i++ {
|
|
|
|
+ mosaicMap[mosaicText] = mosaicText
|
|
|
|
+ }
|
|
|
|
+ obj["winnerMap"] = mosaicMap
|
|
|
|
+ } else {
|
|
|
|
+ obj[k] = mosaicText
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //数字打码
|
|
|
|
+ detail = RegDetail(detail)
|
|
|
|
+ detail = fsw.Repl(detail)
|
|
|
|
+ obj["detail"] = detail
|
|
|
|
+ return obj
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 分段匹配数字打码
|
|
|
|
+func RegDetail(html string) string {
|
|
|
|
+ mosaicText := IC.C.DetailMosaicTxt
|
|
|
|
+ reg := regexp.MustCompile("<[^<>]{1,1000}>") //分段正则
|
|
|
|
+ s := reg.FindAllStringIndex(html, -1) //全文匹配分段
|
|
|
|
+ if len(s) > 0 { //走分段替换
|
|
|
|
+ arr := []string{}
|
|
|
|
+ index := 0
|
|
|
|
+ for _, v := range s {
|
|
|
|
+ if len(v) == 2 {
|
|
|
|
+ // log.Println(html[index:v[0]])
|
|
|
|
+ txt, _ := ReplaceStringByRegex(html[index:v[0]], "[0-9]+", mosaicText)
|
|
|
|
+ arr = append(arr, txt) //替换
|
|
|
|
+ arr = append(arr, html[v[0]:v[1]])
|
|
|
|
+ index = v[1]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return strings.Join(arr, "")
|
|
|
|
+ }
|
|
|
|
+ return ""
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func ReplaceStringByRegex(str, rule, replace string) (string, error) {
|
|
|
|
+ reg, err := regexp.Compile(rule)
|
|
|
|
+ if reg == nil || err != nil {
|
|
|
|
+ return "", errors.New("正则MustCompile错误:" + err.Error())
|
|
|
|
+ }
|
|
|
|
+ return reg.ReplaceAllString(str, replace), nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func Bind(data interface{}, ret interface{}) error {
|
|
|
|
+ v := reflect.ValueOf(ret)
|
|
|
|
+ if v.Kind() != reflect.Ptr {
|
|
|
|
+ return fmt.Errorf("ptr input ret needed as type as input type %s", v.Kind())
|
|
|
|
+ }
|
|
|
|
+ havdata := false
|
|
|
|
+ var bk interface{}
|
|
|
|
+ if v.Elem().Kind() == reflect.Slice {
|
|
|
|
+ t := reflect.Zero(reflect.TypeOf(v.Elem().Interface()))
|
|
|
|
+ bk = v.Elem().Interface()
|
|
|
|
+ v.Elem().Set(t)
|
|
|
|
+ havdata = true
|
|
|
|
+ }
|
|
|
|
+ _data, _ := json.MarshalIndent(data, "", " ")
|
|
|
|
+ err := json.Unmarshal(_data, ret)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ if havdata {
|
|
|
|
+ v.Elem().Set(reflect.ValueOf(bk))
|
|
|
|
+ }
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|