1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package encrypt
- import (
- "app.yhyue.com/moapp/jybase/common"
- "net/url"
- "strings"
- )
- // 正文
- var SE = &SimpleEncrypt{Key: "topnet2015topnet2015"}
- var SE2 = &SimpleEncrypt{Key: "2017jianyu"}
- var SE3 = &SimpleEncrypt{Key: "entservice"}
- // 百度
- var BSE = &SimpleEncrypt{Key: "HNtopnet2017jy"}
- var BSE2 = &SimpleEncrypt{Key: "TOP2017jianyu"}
- // 订阅推送邮件
- var ESE = &SimpleEncrypt{Key: "PEjy2018topnet"}
- var ESE2 = &SimpleEncrypt{Key: "TopnetJy2018Pe"}
- // 首页
- var ISE = &SimpleEncrypt{Key: "Indexjy2021topnet"}
- var ISE2 = &SimpleEncrypt{Key: "TopnetJy2021Pe"}
- // 通用加密
- func CommonEncodeArticle(stype string, keys ...string) (id string) {
- switch stype {
- case "content", "yyszb":
- 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", "bdcontent", "yyszb":
- 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)
- case "entservice":
- res = []string{SE3.DecodeString(id)}
- }
- return
- }
- // 短地址加密,二次加密带校验和
- func BEncodeArticleId2ByCheck(h string, s1, s2 *SimpleEncrypt, keys ...string) string {
- kstr := strings.Join(keys, ",")
- kstr = s1.EncodeStringByCheck(kstr)
- return url.QueryEscape(h + common.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), ",")
- }
|