From 67c846b4e7b5ee4649a9f1fdd0bf712a9acd9b80 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Fri, 5 Jan 2024 14:55:34 +0800 Subject: [PATCH 1/4] update --- consume/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consume/init.go b/consume/init.go index 2af1b54..c680002 100644 --- a/consume/init.go +++ b/consume/init.go @@ -74,7 +74,7 @@ func initConsumes() { //////////////////////////////////////// V2 ///////////////////////////////////////////////////// //jobs[consumeMd.SupplyCloudChainFenxiaoNewChangeFunName] = SupplyCloudChainFenxiaoNewChangeConsume - //////////////////////////////////////// V3 ///////////////////////////////////////////////////// + //////////////////////////////////////// // V3 // ///////////////////////////////////////////////////// jobs[consumeMd.MallAddSupplyGoodsFunName] = MallAddSupplyGoodsConsume } From 62f5e0f787811ee805f1786ca5529d5638e09a18 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Fri, 5 Jan 2024 15:28:15 +0800 Subject: [PATCH 2/4] update --- consume/mall_add_supply_goods.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consume/mall_add_supply_goods.go b/consume/mall_add_supply_goods.go index 9325ff2..7e42f7c 100644 --- a/consume/mall_add_supply_goods.go +++ b/consume/mall_add_supply_goods.go @@ -25,7 +25,7 @@ func MallAddSupplyGoodsConsume(queue md.MqQueue) { } defer ch.Release() //2、取出数据进行消费 - ch.Qos(1) + ch.Qos(10) delivery := ch.Consume(queue.Name, false) var res amqp.Delivery From cd7a79e6b3aebd05229bedd16ef2af81e3f995a6 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Mon, 8 Jan 2024 12:29:52 +0800 Subject: [PATCH 3/4] update --- app/utils/convert.go | 2 +- consume/init.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/utils/convert.go b/app/utils/convert.go index 04cab78..677eda5 100644 --- a/app/utils/convert.go +++ b/app/utils/convert.go @@ -140,7 +140,7 @@ func AnyToString(raw interface{}) string { case bool: return strconv.FormatBool(i) } - return fmt.Sprintf("%#v", raw) + return fmt.Sprintf("%+v", raw) } func AnyToFloat64(raw interface{}) float64 { diff --git a/consume/init.go b/consume/init.go index c680002..cd29daf 100644 --- a/consume/init.go +++ b/consume/init.go @@ -72,10 +72,10 @@ func initConsumes() { //jobs[consumeMd.CloudIssuanceMsgCallBackFunName] = CloudIssuanceMsgCallBackConsume //////////////////////////////////////// V2 ///////////////////////////////////////////////////// - //jobs[consumeMd.SupplyCloudChainFenxiaoNewChangeFunName] = SupplyCloudChainFenxiaoNewChangeConsume + jobs[consumeMd.SupplyCloudChainFenxiaoNewChangeFunName] = SupplyCloudChainFenxiaoNewChangeConsume //////////////////////////////////////// // V3 // ///////////////////////////////////////////////////// - jobs[consumeMd.MallAddSupplyGoodsFunName] = MallAddSupplyGoodsConsume + //jobs[consumeMd.MallAddSupplyGoodsFunName] = MallAddSupplyGoodsConsume } From f3435c10d69e233109d274335127cef21a8310f8 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Mon, 15 Jan 2024 15:32:26 +0800 Subject: [PATCH 4/4] update --- app/utils/aes/aes_utils.go | 76 +++++++++++++++++++ consume/init.go | 4 +- consume/mall_add_supply_goods.go | 13 +++- .../supply_cloud_chain_fenxiao_new_change.go | 6 +- etc/cfg.yml | 8 +- 5 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 app/utils/aes/aes_utils.go diff --git a/app/utils/aes/aes_utils.go b/app/utils/aes/aes_utils.go new file mode 100644 index 0000000..902d7f9 --- /dev/null +++ b/app/utils/aes/aes_utils.go @@ -0,0 +1,76 @@ +package aes + +import ( + "bytes" + "crypto/aes" + "encoding/base64" +) + +const AesKey = "zhiyingos@qq.com" + +// 加密 +func AesEncryptByECB(key, data string) string { + // 判断key长度 + keyLenMap := map[int]struct{}{16: {}, 24: {}, 32: {}} + if _, ok := keyLenMap[len(key)]; !ok { + panic("key长度必须是 16、24、32 其中一个") + } + // 密钥和待加密数据转成[]byte + originByte := []byte(data) + keyByte := []byte(key) + // 创建密码组,长度只能是16、24、32 字节 + block, _ := aes.NewCipher(keyByte) + // 获取密钥长度 + blockSize := block.BlockSize() + // 补码 + originByte = PKCS7Padding(originByte, blockSize) + // 创建保存加密变量 + encryptResult := make([]byte, len(originByte)) + // CEB是把整个明文分成若干段相同的小段,然后对每一小段进行加密 + for bs, be := 0, blockSize; bs < len(originByte); bs, be = bs+blockSize, be+blockSize { + block.Encrypt(encryptResult[bs:be], originByte[bs:be]) + } + res := base64.StdEncoding.EncodeToString(encryptResult) + return res +} + +// 补码 +func PKCS7Padding(originByte []byte, blockSize int) []byte { + // 计算补码长度 + padding := blockSize - len(originByte)%blockSize + // 生成补码 + padText := bytes.Repeat([]byte{byte(padding)}, padding) + // 追加补码 + return append(originByte, padText...) +} + +// 解密 +func AesDecryptByECB(key, data string) string { + // 判断key长度 + keyLenMap := map[int]struct{}{16: {}, 24: {}, 32: {}} + if _, ok := keyLenMap[len(key)]; !ok { + panic("key长度必须是 16、24、32 其中一个") + } + // 反解密码base64 + originByte, _ := base64.StdEncoding.DecodeString(data) + // 密钥和待加密数据转成[]byte + keyByte := []byte(key) + // 创建密码组,长度只能是16、24、32字节 + block, _ := aes.NewCipher(keyByte) + // 获取密钥长度 + blockSize := block.BlockSize() + // 创建保存解密变量 + decrypted := make([]byte, len(originByte)) + for bs, be := 0, blockSize; bs < len(originByte); bs, be = bs+blockSize, be+blockSize { + block.Decrypt(decrypted[bs:be], originByte[bs:be]) + } + // 解码 + return string(PKCS7UNPadding(decrypted)) +} + +// 解码 +func PKCS7UNPadding(originDataByte []byte) []byte { + length := len(originDataByte) + unpadding := int(originDataByte[length-1]) + return originDataByte[:(length - unpadding)] +} diff --git a/consume/init.go b/consume/init.go index cd29daf..c680002 100644 --- a/consume/init.go +++ b/consume/init.go @@ -72,10 +72,10 @@ func initConsumes() { //jobs[consumeMd.CloudIssuanceMsgCallBackFunName] = CloudIssuanceMsgCallBackConsume //////////////////////////////////////// V2 ///////////////////////////////////////////////////// - jobs[consumeMd.SupplyCloudChainFenxiaoNewChangeFunName] = SupplyCloudChainFenxiaoNewChangeConsume + //jobs[consumeMd.SupplyCloudChainFenxiaoNewChangeFunName] = SupplyCloudChainFenxiaoNewChangeConsume //////////////////////////////////////// // V3 // ///////////////////////////////////////////////////// - //jobs[consumeMd.MallAddSupplyGoodsFunName] = MallAddSupplyGoodsConsume + jobs[consumeMd.MallAddSupplyGoodsFunName] = MallAddSupplyGoodsConsume } diff --git a/consume/mall_add_supply_goods.go b/consume/mall_add_supply_goods.go index 7e42f7c..09514f1 100644 --- a/consume/mall_add_supply_goods.go +++ b/consume/mall_add_supply_goods.go @@ -2,6 +2,7 @@ package consume import ( svc2 "applet/app/svc" + "applet/app/utils/aes" "applet/app/utils/logx" "applet/consume/md" md3 "applet/mall/md" @@ -24,6 +25,9 @@ func MallAddSupplyGoodsConsume(queue md.MqQueue) { return } defer ch.Release() + + //1、将自己绑定到交换机上 + ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) //2、取出数据进行消费 ch.Qos(10) delivery := ch.Consume(queue.Name, false) @@ -47,7 +51,14 @@ func MallAddSupplyGoodsConsume(queue md.MqQueue) { } func handleMallAddSupplyGoodsConsume(msgData []byte) error { + var msg map[string]string + err := json.Unmarshal(msgData, &msg) + if err != nil { + panic(err) + } + //解析mq中queue的数据结构体 + strs := aes.AesDecryptByECB(aes.AesKey, msg["aes_data"]) var pushStuct struct { Args struct { GoodsInfo []*md3.OfficialGoods `json:"goods_info"` @@ -55,7 +66,7 @@ func handleMallAddSupplyGoodsConsume(msgData []byte) error { } `json:"args"` Mid string `json:"mid"` } - err := json.Unmarshal(msgData, &pushStuct) + err = json.Unmarshal([]byte(strs), &pushStuct) if err != nil { panic(err) } diff --git a/consume/supply_cloud_chain_fenxiao_new_change.go b/consume/supply_cloud_chain_fenxiao_new_change.go index 4eac55b..8630b31 100644 --- a/consume/supply_cloud_chain_fenxiao_new_change.go +++ b/consume/supply_cloud_chain_fenxiao_new_change.go @@ -17,6 +17,7 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/streadway/amqp" + "strconv" "strings" "time" ) @@ -191,6 +192,8 @@ func handleSupplyCloudChainFenxiaoNewChangeConsume(msgData []byte) error { utils.FilePutContents("cloudChainGoods", utils.SerializeStr(cloudChainGoods)) for _, id := range ids { + var req md2.AddGoodsReq + if cloudChainGoods[id] == nil { continue } @@ -203,9 +206,8 @@ func handleSupplyCloudChainFenxiaoNewChangeConsume(msgData []byte) error { continue } if getV2 { - continue + req.Base.GoodsId = strconv.FormatInt(goods.GoodsId, 10) } - var req md2.AddGoodsReq req.Base.GoodsType = 1 req.Base.CloudChainGoodsId = id req.Base.SaleState = enum.MallGoodsSaleStateOnShelf diff --git a/etc/cfg.yml b/etc/cfg.yml index 9bee1ce..dd7856a 100644 --- a/etc/cfg.yml +++ b/etc/cfg.yml @@ -29,10 +29,10 @@ wxapplet_filepath: # 连接官网数据库获取db mapping db: - host: 'zhios123.rwlb.rds.aliyuncs.com:3306' - name: 'zyos_website' - user: 'canal' - psw: 'canal' + host: '119.23.182.117:3306' + name: 'zyso_website_back' + user: 'root' + psw: 'Fnuo123com@' show_log: true max_lifetime: 30 max_open_conns: 100