智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.0 KiB

  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. "applet/app/customer/md"
  5. "applet/app/customer/svc"
  6. "applet/app/db"
  7. "applet/app/e"
  8. "applet/app/enum"
  9. utils2 "applet/app/utils"
  10. "encoding/json"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "github.com/wechatpay-apiv3/wechatpay-go/utils"
  14. )
  15. func AlipayJsApiCallBack(c *gin.Context) {
  16. data := svc.CheckAllCallbackParams(c)
  17. if data == nil {
  18. e.OutErr(c, e.ERR_INVALID_ARGS)
  19. return
  20. }
  21. c.Set("callback", data)
  22. args, ok := data.(*md.AliPayCallback)
  23. if !ok {
  24. fmt.Println("反射ok失败")
  25. e.OutErr(c, e.ERR_INVALID_ARGS, "反射失败")
  26. return
  27. }
  28. if args.GmtRefund != "" {
  29. //TODO::退款通知不需要处理
  30. c.String(200, "success")
  31. return
  32. }
  33. _, err := svc.DealCentralKitchenForSchoolOrderCallBack(args.OutTradeNo, args.TradeStatus)
  34. if err != nil {
  35. e.OutErr(c, e.ERR, err.Error())
  36. return
  37. }
  38. //TODO::此处需要直接输出 success,避免支付宝重复回调
  39. //c.Header("Content-Type", "text/html; charset=utf-8")
  40. c.String(200, "success")
  41. }
  42. func WxJsApiCallBack(c *gin.Context) {
  43. var req md.WxCallback
  44. err := c.ShouldBindJSON(&req)
  45. if err != nil {
  46. err = validate.HandleValidateErr(err)
  47. err1 := err.(e.E)
  48. e.OutErr(c, err1.Code, err1.Error())
  49. return
  50. }
  51. sysCfgDb := db.SysCfgDb{}
  52. sysCfgDb.Set()
  53. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchApiV3Key)
  54. //TODO::进行解密
  55. decryptString, err := utils.DecryptAES256GCM(sysCfg[enum.WxSpMchApiV3Key], req.Resource.AssociatedData, req.Resource.Nonce, req.Resource.Ciphertext)
  56. if err != nil {
  57. e.OutErr(c, e.ERR, "解密失败")
  58. return
  59. }
  60. fmt.Println(">>>>>>>>>>", decryptString)
  61. var resp md.WxPayCallback
  62. err = json.Unmarshal([]byte(decryptString), &resp)
  63. if err != nil {
  64. e.OutErr(c, e.ERR, err.Error())
  65. return
  66. }
  67. _, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState)
  68. if err != nil {
  69. e.OutErr(c, e.ERR, err.Error())
  70. return
  71. }
  72. e.OutSuc(c, "success", nil)
  73. return
  74. }
  75. func WxRefundApiCallBack(c *gin.Context) {
  76. var req md.WxCallback
  77. err := c.ShouldBindJSON(&req)
  78. if err != nil {
  79. err = validate.HandleValidateErr(err)
  80. err1 := err.(e.E)
  81. e.OutErr(c, err1.Code, err1.Error())
  82. return
  83. }
  84. sysCfgDb := db.SysCfgDb{}
  85. sysCfgDb.Set()
  86. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchApiV3Key)
  87. //TODO::进行解密
  88. decryptString, err := utils.DecryptAES256GCM(sysCfg[enum.WxSpMchApiV3Key], req.Resource.AssociatedData, req.Resource.Nonce, req.Resource.Ciphertext)
  89. if err != nil {
  90. e.OutErr(c, e.ERR, "解密失败")
  91. return
  92. }
  93. fmt.Println(">>>>>>>>>>WxRefundApiCallBack<<<<<<<<<", decryptString)
  94. utils2.FilePutContents("WxRefundApiCallBack", decryptString)
  95. //var resp md.WxPayCallback
  96. //err = json.Unmarshal([]byte(decryptString), &resp)
  97. //if err != nil {
  98. // e.OutErr(c, e.ERR, err.Error())
  99. // return
  100. //}
  101. //
  102. //_, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState)
  103. //if err != nil {
  104. // e.OutErr(c, e.ERR, err.Error())
  105. // return
  106. //}
  107. e.OutSuc(c, "success", nil)
  108. return
  109. }