htfutures_trade_controller.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package web_hook
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/common/exception"
  5. "eta/eta_mini_ht_api/controllers"
  6. orderService "eta/eta_mini_ht_api/domian/order"
  7. "eta/eta_mini_ht_api/service/product"
  8. )
  9. type HTFuturesTradeController struct {
  10. controllers.WebHookController
  11. }
  12. type ss struct {
  13. Success bool `json:"success"`
  14. User int `json:"user"`
  15. TradeOrderNo string `json:"tradeOrderNo"`
  16. }
  17. // InformPaymentResult 支付通知接口
  18. // @Summary 支付通知接口
  19. // @Description 支付通知接口
  20. // @Success 200 {object} controllers.BaseResponse
  21. // @router /v1/payment/informPaymentResult [post]
  22. func (h *HTFuturesTradeController) InformPaymentResult() {
  23. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  24. result = h.InitWrapData("同步风险等级")
  25. s := new(ss)
  26. h.GetPostParams(s)
  27. logger.Info("支付结果通知: %v", s)
  28. if s.Success {
  29. productOrder, _ := orderService.DealPayment(s.TradeOrderNo, orderService.PaySuccess)
  30. //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
  31. _ = product.OpenProduct(productOrder)
  32. } else {
  33. _, _ = orderService.DealPayment(s.TradeOrderNo, orderService.PayFail)
  34. }
  35. //htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
  36. //webhookRequest := new(WebhookRequest)
  37. //h.GetPostParams(webhookRequest)
  38. //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
  39. //if err != nil {
  40. // err = exception.NewWithException(exception.SysError, err.Error())
  41. // logger.Error("解析私钥失败: %v", err)
  42. // h.FailedResult("解析私钥失败", result)
  43. // return
  44. //}
  45. //decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
  46. //if err != nil {
  47. // err = exception.NewWithException(exception.SysError, err.Error())
  48. // logger.Error("解密请求体失败: %v", err)
  49. // h.FailedResult("解密请求体失败", result)
  50. // return
  51. //}
  52. //syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  53. //err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
  54. //if err != nil {
  55. // err = exception.NewWithException(exception.SyncRiskError, err.Error())
  56. // logger.Error("解析请求体失败: %v", err)
  57. // h.FailedResult("解析请求体失败", result)
  58. // return
  59. //}
  60. result = h.InitWrapData("支付结果应答成功")
  61. h.SuccessResult("success", nil, result)
  62. return
  63. })
  64. }
  65. // InformRefundResult 退款通知接口
  66. // @Summary 退款通知接口
  67. // @Description 退款通知接口
  68. // @Success 200 {object} controllers.BaseResponse
  69. // @router /v1/payment/informRefundResult [post]
  70. func (h *HTFuturesTradeController) InformRefundResult() {
  71. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  72. result = h.InitWrapData("同步风险等级")
  73. s := new(ss)
  74. h.GetPostParams(s)
  75. if s.Success {
  76. productOrder, RefundErr := orderService.DealRefund(s.TradeOrderNo, orderService.RefundSuccess)
  77. if RefundErr != nil {
  78. logger.Error("退款订单处理失败: %v", err)
  79. err = exception.NewWithException(exception.RefundDealFail, err.Error())
  80. h.FailedResult("退款订单处理失败", result)
  81. return
  82. }
  83. //处理退款订单
  84. _ = product.CloseProduct(productOrder)
  85. } else {
  86. _, RefundErr := orderService.DealRefund(s.TradeOrderNo, orderService.RefundFail)
  87. if RefundErr != nil {
  88. logger.Error("退款订单处理失败: %v", err)
  89. err = exception.NewWithException(exception.RefundDealFail, RefundErr.Error())
  90. h.FailedResult("退款订单处理失败", result)
  91. return
  92. }
  93. }
  94. //创建meta_info
  95. //htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
  96. //webhookRequest := new(WebhookRequest)
  97. //h.GetPostParams(webhookRequest)
  98. //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
  99. //if err != nil {
  100. // err = exception.NewWithException(exception.SysError, err.Error())
  101. // logger.Error("解析私钥失败: %v", err)
  102. // h.FailedResult("解析私钥失败", result)
  103. // return
  104. //}
  105. //decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
  106. //if err != nil {
  107. // err = exception.NewWithException(exception.SysError, err.Error())
  108. // logger.Error("解密请求体失败: %v", err)
  109. // h.FailedResult("解密请求体失败", result)
  110. // return
  111. //}
  112. //syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  113. //err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
  114. //if err != nil {
  115. // err = exception.NewWithException(exception.SyncRiskError, err.Error())
  116. // logger.Error("解析请求体失败: %v", err)
  117. // h.FailedResult("解析请求体失败", result)
  118. // return
  119. //}
  120. result = h.InitWrapData("退款结果应答成功")
  121. h.SuccessResult("success", nil, result)
  122. return
  123. })
  124. }