package web_hook import ( logger "eta/eta_mini_ht_api/common/component/log" "eta/eta_mini_ht_api/common/exception" "eta/eta_mini_ht_api/controllers" orderService "eta/eta_mini_ht_api/domian/order" "eta/eta_mini_ht_api/service/product" ) type HTFuturesTradeController struct { controllers.WebHookController } type ss struct { Success bool `json:"success"` User int `json:"user"` TradeOrderNo string `json:"tradeOrderNo"` } // InformPaymentResult 支付通知接口 // @Summary 支付通知接口 // @Description 支付通知接口 // @Success 200 {object} controllers.BaseResponse // @router /v1/payment/informPaymentResult [post] func (h *HTFuturesTradeController) InformPaymentResult() { controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) { result = h.InitWrapData("同步风险等级") s := new(ss) h.GetPostParams(s) logger.Info("支付结果通知: %v", s) if s.Success { productOrder, _ := orderService.DealPayment(s.TradeOrderNo, orderService.PaySuccess) //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey()) _ = product.OpenProduct(productOrder) } else { _, _ = orderService.DealPayment(s.TradeOrderNo, orderService.PayFail) } //htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig) //webhookRequest := new(WebhookRequest) //h.GetPostParams(webhookRequest) //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey()) //if err != nil { // err = exception.NewWithException(exception.SysError, err.Error()) // logger.Error("解析私钥失败: %v", err) // h.FailedResult("解析私钥失败", result) // return //} //decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data) //if err != nil { // err = exception.NewWithException(exception.SysError, err.Error()) // logger.Error("解密请求体失败: %v", err) // h.FailedResult("解密请求体失败", result) // return //} //syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq) //err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq) //if err != nil { // err = exception.NewWithException(exception.SyncRiskError, err.Error()) // logger.Error("解析请求体失败: %v", err) // h.FailedResult("解析请求体失败", result) // return //} result = h.InitWrapData("支付结果应答成功") h.SuccessResult("success", nil, result) return }) } // InformRefundResult 退款通知接口 // @Summary 退款通知接口 // @Description 退款通知接口 // @Success 200 {object} controllers.BaseResponse // @router /v1/payment/informRefundResult [post] func (h *HTFuturesTradeController) InformRefundResult() { controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) { result = h.InitWrapData("同步风险等级") s := new(ss) h.GetPostParams(s) if s.Success { productOrder, RefundErr := orderService.DealRefund(s.TradeOrderNo, orderService.RefundSuccess) if RefundErr != nil { logger.Error("退款订单处理失败: %v", err) err = exception.NewWithException(exception.RefundDealFail, err.Error()) h.FailedResult("退款订单处理失败", result) return } //处理退款订单 _ = product.CloseProduct(productOrder) } else { _, RefundErr := orderService.DealRefund(s.TradeOrderNo, orderService.RefundFail) if RefundErr != nil { logger.Error("退款订单处理失败: %v", err) err = exception.NewWithException(exception.RefundDealFail, RefundErr.Error()) h.FailedResult("退款订单处理失败", result) return } } //创建meta_info //htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig) //webhookRequest := new(WebhookRequest) //h.GetPostParams(webhookRequest) //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey()) //if err != nil { // err = exception.NewWithException(exception.SysError, err.Error()) // logger.Error("解析私钥失败: %v", err) // h.FailedResult("解析私钥失败", result) // return //} //decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data) //if err != nil { // err = exception.NewWithException(exception.SysError, err.Error()) // logger.Error("解密请求体失败: %v", err) // h.FailedResult("解密请求体失败", result) // return //} //syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq) //err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq) //if err != nil { // err = exception.NewWithException(exception.SyncRiskError, err.Error()) // logger.Error("解析请求体失败: %v", err) // h.FailedResult("解析请求体失败", result) // return //} result = h.InitWrapData("退款结果应答成功") h.SuccessResult("success", nil, result) return }) }