From 01a7c60d45fd28eba392a426325403305a2d71e0 Mon Sep 17 00:00:00 2001 From: "qiyunfanbo126.com" <815699> Date: Mon, 30 Sep 2024 17:58:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=93=81=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/controllers/front/OrderController.go | 1 + app/http/entities/front/Youchu.go | 2 ++ app/services/OrderService.go | 2 ++ app/utils/util.go | 9 +++++++++ config/config.go | 1 + 5 files changed, 15 insertions(+) diff --git a/app/http/controllers/front/OrderController.go b/app/http/controllers/front/OrderController.go index d3d3961..0738bed 100644 --- a/app/http/controllers/front/OrderController.go +++ b/app/http/controllers/front/OrderController.go @@ -24,6 +24,7 @@ func CreateOrder(c *gin.Context) { controllers.HandCodeRes(c, nil, errorcode.NotLogin) return } + code, data := services.CreateOrderService(userId, request.ProductId) controllers.HandCodeRes(c, data, code) } diff --git a/app/http/entities/front/Youchu.go b/app/http/entities/front/Youchu.go index 2ca2816..f35a0f4 100644 --- a/app/http/entities/front/Youchu.go +++ b/app/http/entities/front/Youchu.go @@ -65,6 +65,8 @@ type OrderQuery struct { type InsertOrderResponse struct { OrderNo string `json:"order_no"` NotifyUrl string `json:"notify_url"` + Sign string `json:"sign"` + PlainText string `json:"plain_text"` } type YouChuOrderQueryResponse struct { diff --git a/app/services/OrderService.go b/app/services/OrderService.go index 1049956..28dcbdc 100644 --- a/app/services/OrderService.go +++ b/app/services/OrderService.go @@ -90,6 +90,8 @@ func CreateOrderService(userId int, productId int) (code int, data front.InsertO } } + data.PlainText = config.GetConf().YouChu.MchtNo + order.OrderNo + order.Price + data.Sign = utils.HmacSha256To16(config.GetConf().YouChu.MchtNo, data.PlainText) data.OrderNo = order.OrderNo data.NotifyUrl = config.GetConf().YouChu.NotifyUrl return errorcode.Success, data diff --git a/app/utils/util.go b/app/utils/util.go index 0ccdc7e..20ff6a8 100644 --- a/app/utils/util.go +++ b/app/utils/util.go @@ -2,6 +2,7 @@ package utils import ( "context" + "crypto/hmac" "crypto/md5" "crypto/rand" "crypto/sha256" @@ -508,3 +509,11 @@ func DownloadBill(xmlString string, key int) { } w.Flush() } + +func HmacSha256To16(key string, data string) string { + mac := hmac.New(sha256.New, []byte(key)) + _, _ = mac.Write([]byte(data)) + encode := mac.Sum(nil) + + return hex.EncodeToString(encode) +} diff --git a/config/config.go b/config/config.go index 86d01fd..995a225 100644 --- a/config/config.go +++ b/config/config.go @@ -53,6 +53,7 @@ type YouChuConfig struct { SopPublicKey string //服开公钥 SopPrivateKey string //服开私钥 FileHost string + Sha string } type YouChuCallBack struct {