From 3c550761d66f5756a85fd62e6205a84bafe702cb Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 27 Aug 2023 15:58:37 +0800 Subject: [PATCH 1/7] decrypt --- worker/common/haha.go | 76 ++++++++++++++++++++++++++++++++++ worker/haha/haha_sync_order.go | 7 +++- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 worker/common/haha.go diff --git a/worker/common/haha.go b/worker/common/haha.go new file mode 100644 index 0000000..f107fef --- /dev/null +++ b/worker/common/haha.go @@ -0,0 +1,76 @@ +package common + +import ( + "crypto/aes" + "crypto/cipher" + "encoding/base64" + "github.com/gogf/gf/v2/crypto/gmd5" + "strings" +) + +// 假设p()就是md5 +func p(data string) []byte { + return []byte(gmd5.MustEncryptString(data)) +} + +//func p(hexStr string) []byte { +// bytes, _ := hex.DecodeString(hexStr) +// return bytes +//} + +func Encrypt(plaintext string, keyPrefix string) (string, error) { + + // 生成key和iv + key := p(keyPrefix + "piaofan@123") + iv := p(keyPrefix + "piaofan@456")[:16] + + // plaintext to bytes + plaintextBytes := []byte(plaintext) + + // 创建AES加密器 + block, err := aes.NewCipher(key) + if err != nil { + return "", err + } + + // 初始化CBC模式 + stream := cipher.NewCBCEncrypter(block, iv) + + // 加密 + ciphertext := make([]byte, len(plaintextBytes)) + stream.CryptBlocks(ciphertext, plaintextBytes) + + // 返回base64编码的ciphertext + return base64.StdEncoding.EncodeToString(ciphertext), nil + +} + +func Decrypt(base64Ciphertext string, keyPrefix string) (string, error) { + // base64解码ciphertext + ciphertext, err := base64.StdEncoding.DecodeString(base64Ciphertext) + if err != nil { + return "", err + } + + // 生成key和iv + key := p(keyPrefix + "piaofan@123") + iv := p(keyPrefix + "piaofan@456")[:16] + + //g.Log().Infof(context.Background(), "key: %s", gconv.String(key)) + + // 创建AES解密器 + block, err := aes.NewCipher(key) + if err != nil { + return "", err + } + + // 初始化CBC模式 + stream := cipher.NewCBCDecrypter(block, iv) + + // 解密 + plaintext := make([]byte, len(ciphertext)) + stream.CryptBlocks(plaintext, ciphertext) + + return strings.TrimSpace(string(plaintext)), nil + +} diff --git a/worker/haha/haha_sync_order.go b/worker/haha/haha_sync_order.go index 79de0a6..cd3050a 100644 --- a/worker/haha/haha_sync_order.go +++ b/worker/haha/haha_sync_order.go @@ -67,7 +67,12 @@ func (s *SyncOrder) run() { return } - datas := cast.ToSlice(result["data"]) + cipherText := cast.ToSlice(result["data"]) + datas, err := common.Decrypt(cipherText, s.token) + if err != nil { + log.Errorf("common.Decrypt error :%s", err.Error()) + return + } for _, d := range datas { data := cast.ToStringMap(d) From 3bd14f83822e8269047aea4856abe861115a4855 Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 27 Aug 2023 16:15:29 +0800 Subject: [PATCH 2/7] import --- go.mod | 7 +++++-- worker/haha/haha_sync_order.go | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index c2d7630..6c05cf3 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( github.com/go-co-op/gocron v1.19.0 + github.com/gogf/gf/v2 v2.5.2 github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/mitchellh/mapstructure v1.5.0 github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 @@ -37,10 +38,12 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect + go.opentelemetry.io/otel v1.14.0 // indirect + go.opentelemetry.io/otel/trace v1.14.0 // indirect golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.3.0 // indirect - golang.org/x/text v0.5.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/worker/haha/haha_sync_order.go b/worker/haha/haha_sync_order.go index cd3050a..c7a80c4 100644 --- a/worker/haha/haha_sync_order.go +++ b/worker/haha/haha_sync_order.go @@ -5,6 +5,7 @@ import ( "encoding/json" "film/base/util" "film/model" + "film/worker/common" "fmt" "github.com/go-co-op/gocron" log "github.com/sirupsen/logrus" From a0c9011d1cdbb68aa4897237f63826a2f21e995b Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 27 Aug 2023 16:17:32 +0800 Subject: [PATCH 3/7] fixbug --- worker/haha/haha_sync_order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/haha/haha_sync_order.go b/worker/haha/haha_sync_order.go index c7a80c4..a783fc4 100644 --- a/worker/haha/haha_sync_order.go +++ b/worker/haha/haha_sync_order.go @@ -68,7 +68,7 @@ func (s *SyncOrder) run() { return } - cipherText := cast.ToSlice(result["data"]) + cipherText := cast.ToString(result["data"]) datas, err := common.Decrypt(cipherText, s.token) if err != nil { log.Errorf("common.Decrypt error :%s", err.Error()) From e105d859388395a3dea1d6ece95dafa0609e3a82 Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 27 Aug 2023 16:40:12 +0800 Subject: [PATCH 4/7] User-Agent --- conf/haha.json | 2 +- worker/haha/haha_sync_order.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/haha.json b/conf/haha.json index 2c508ca..f9c5898 100644 --- a/conf/haha.json +++ b/conf/haha.json @@ -1,4 +1,4 @@ { - "token": "50ce0f30643185a4d0662c61245ea4a1", + "token": "711ed95e483af1e8d61705c9c894a5b2", "syncInterval": 10 } \ No newline at end of file diff --git a/worker/haha/haha_sync_order.go b/worker/haha/haha_sync_order.go index a783fc4..6b208e6 100644 --- a/worker/haha/haha_sync_order.go +++ b/worker/haha/haha_sync_order.go @@ -147,6 +147,7 @@ func (s *SyncOrder) httpPost(requestUrl string) ([]byte, error) { return nil, err } req.Header.Set("token", s.token) + req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36") resp, err := client.Do(req) if err != nil { From f1b590f676d041b01b9c67cf987b3c1a463d2ebe Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 27 Aug 2023 16:53:12 +0800 Subject: [PATCH 5/7] https://hahapiao.cn/api/Synchro/pcToList --- worker/haha/haha_sync_order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/haha/haha_sync_order.go b/worker/haha/haha_sync_order.go index 6b208e6..d2c2a21 100644 --- a/worker/haha/haha_sync_order.go +++ b/worker/haha/haha_sync_order.go @@ -52,7 +52,7 @@ func (s *SyncOrder) Sync() { } func (s *SyncOrder) run() { - orderUrl := "https://hahapiao.cn/api/Synchro/toList" + orderUrl := "https://hahapiao.cn/api/Synchro/pcToList" body, err := s.httpPost(orderUrl) if err != nil { log.Errorf("syncOrder error : %s", err.Error()) From aff454cda3615e20685d4530847defc791e2adba Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 27 Aug 2023 17:09:57 +0800 Subject: [PATCH 6/7] slice --- worker/haha/haha_sync_order.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/worker/haha/haha_sync_order.go b/worker/haha/haha_sync_order.go index d2c2a21..a657dc0 100644 --- a/worker/haha/haha_sync_order.go +++ b/worker/haha/haha_sync_order.go @@ -69,13 +69,17 @@ func (s *SyncOrder) run() { } cipherText := cast.ToString(result["data"]) - datas, err := common.Decrypt(cipherText, s.token) + originText, err := common.Decrypt(cipherText, s.token) if err != nil { log.Errorf("common.Decrypt error :%s", err.Error()) return } - - for _, d := range datas { + var arrs []interface{} + if err := json.Unmarshal([]byte(originText), arrs); err != nil { + log.Errorf("json.Unmarsha error :%s", err.Error()) + return + } + for _, d := range arrs { data := cast.ToStringMap(d) id := cast.ToInt64(data["id"]) order, err := model.GetOrder(id) From b77d70dcf429f0b3729bc30835d08943d8520d4b Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 27 Aug 2023 17:15:08 +0800 Subject: [PATCH 7/7] arrs --- worker/haha/haha_sync_order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/haha/haha_sync_order.go b/worker/haha/haha_sync_order.go index a657dc0..caa2aa6 100644 --- a/worker/haha/haha_sync_order.go +++ b/worker/haha/haha_sync_order.go @@ -75,7 +75,7 @@ func (s *SyncOrder) run() { return } var arrs []interface{} - if err := json.Unmarshal([]byte(originText), arrs); err != nil { + if err := json.Unmarshal([]byte(originText), &arrs); err != nil { log.Errorf("json.Unmarsha error :%s", err.Error()) return }