123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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
- })
- }
|