WH01243 2 years ago
parent
commit
f7770eaba0
1 changed files with 34 additions and 32 deletions
  1. 34 32
      src/qfw/util/encryptarticle.go

+ 34 - 32
src/qfw/util/encryptarticle.go

@@ -1,8 +1,8 @@
 package util
 
 import (
-	"net/url"
-	"strings"
+        "net/url"
+        "strings"
 )
 
 //正文
@@ -24,46 +24,48 @@ var ISE2 = &SimpleEncrypt{Key: "TopnetJy2021Pe"}
 
 //通用加密
 func CommonEncodeArticle(stype string, keys ...string) (id string) {
-	switch stype {
-	case "content":
-		id = BEncodeArticleId2ByCheck("A", SE, SE2, keys...)
-	case "bdprivate":
-		id = BEncodeArticleId2ByCheck("B", BSE, BSE2, keys...)
-	case "mailprivate":
-		id = BEncodeArticleId2ByCheck("C", ESE, ESE2, keys...)
-	case "indexcontent":
-		id = BEncodeArticleId2ByCheck("D", ISE, ISE2, keys...)
-	}
-	return
+        switch stype {
+        case "content":
+	      id = BEncodeArticleId2ByCheck("A", SE, SE2, keys...)
+        case "bdprivate":
+	      id = BEncodeArticleId2ByCheck("B", BSE, BSE2, keys...)
+        case "mailprivate":
+	      id = BEncodeArticleId2ByCheck("C", ESE, ESE2, keys...)
+        case "indexcontent":
+	      id = BEncodeArticleId2ByCheck("D", ISE, ISE2, keys...)
+        }
+        return
 }
 
 //通用解密
 func CommonDecodeArticle(stype string, id string) (res []string) {
-	switch stype {
-	case "content":
-		res = BDecodeArticleId2ByCheck(id, SE, SE2)
-	case "bdprivate":
-		res = BDecodeArticleId2ByCheck(id, BSE, BSE2)
-	case "mailprivate":
-		res = BDecodeArticleId2ByCheck(id, ESE, ESE2)
-	case "indexcontent":
-		res = BDecodeArticleId2ByCheck(id, ISE, ISE2)
-	}
-	return
+        switch stype {
+        case "content":
+	      res = BDecodeArticleId2ByCheck(id, SE, SE2)
+        case "bdprivate":
+	      res = BDecodeArticleId2ByCheck(id, BSE, BSE2)
+        case "mailprivate":
+	      res = BDecodeArticleId2ByCheck(id, ESE, ESE2)
+        case "indexcontent":
+	      res = BDecodeArticleId2ByCheck(id, ISE, ISE2)
+        case "advancedProject":
+	      res = BDecodeArticleId2ByCheck(id, SE, SE2)
+        }
+        return
 }
 
 //短地址加密,二次加密带校验和
 func BEncodeArticleId2ByCheck(h string, s1, s2 *SimpleEncrypt, keys ...string) string {
-	kstr := strings.Join(keys, ",")
-	kstr = s1.EncodeStringByCheck(kstr)
-	return url.QueryEscape(h + GetLetterRandom(2) + s2.EncodeStringByCheck(kstr))
+        kstr := strings.Join(keys, ",")
+        kstr = s1.EncodeStringByCheck(kstr)
+        return url.QueryEscape(h + GetLetterRandom(2) + s2.EncodeStringByCheck(kstr))
 }
 
 //短地址解密,二次解密带校验和
 func BDecodeArticleId2ByCheck(id string, s1, s2 *SimpleEncrypt) []string {
-	if !strings.Contains(id, "+") { //新加密算法解密
-		id, _ = url.QueryUnescape(id)
-	}
-	kstr := s2.DecodeStringByCheck(id[3:])
-	return strings.Split(s1.DecodeStringByCheck(kstr), ",")
+        if !strings.Contains(id, "+") { //新加密算法解密
+	      id, _ = url.QueryUnescape(id)
+        }
+        kstr := s2.DecodeStringByCheck(id[3:])
+        return strings.Split(s1.DecodeStringByCheck(kstr), ",")
 }