mirror of http://gitlab.batiao8.com/yic/film.git
This commit is contained in:
commit
9ba0f49a31
7
go.mod
7
go.mod
|
@ -4,6 +4,7 @@ go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-co-op/gocron v1.19.0
|
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/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
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/jwalterweatherman v1.1.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/subosito/gotenv v1.4.2 // 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/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
||||||
golang.org/x/sync v0.1.0 // indirect
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
golang.org/x/sys v0.3.0 // indirect
|
golang.org/x/sys v0.10.0 // indirect
|
||||||
golang.org/x/text v0.5.0 // indirect
|
golang.org/x/text v0.11.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"film/base/util"
|
"film/base/util"
|
||||||
"film/model"
|
"film/model"
|
||||||
|
"film/worker/common"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-co-op/gocron"
|
"github.com/go-co-op/gocron"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -51,7 +52,7 @@ func (s *SyncOrder) Sync() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SyncOrder) run() {
|
func (s *SyncOrder) run() {
|
||||||
orderUrl := "https://hahapiao.cn/api/Synchro/toList"
|
orderUrl := "https://hahapiao.cn/api/Synchro/pcToList"
|
||||||
body, err := s.httpPost(orderUrl)
|
body, err := s.httpPost(orderUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("syncOrder error : %s", err.Error())
|
log.Errorf("syncOrder error : %s", err.Error())
|
||||||
|
@ -67,9 +68,18 @@ func (s *SyncOrder) run() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
datas := cast.ToSlice(result["data"])
|
cipherText := cast.ToString(result["data"])
|
||||||
|
originText, err := common.Decrypt(cipherText, s.token)
|
||||||
for _, d := range datas {
|
if err != nil {
|
||||||
|
log.Errorf("common.Decrypt error :%s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
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)
|
data := cast.ToStringMap(d)
|
||||||
id := cast.ToInt64(data["id"])
|
id := cast.ToInt64(data["id"])
|
||||||
order, err := model.GetOrder(id)
|
order, err := model.GetOrder(id)
|
||||||
|
@ -141,6 +151,7 @@ func (s *SyncOrder) httpPost(requestUrl string) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Set("token", s.token)
|
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)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue