智慧食堂
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.

hdl_call_back.go 3.1 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. utils2.FilePutContents("WxJsApiCallBack", utils2.SerializeStr(resp))
  68. _, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState)
  69. if err != nil {
  70. e.OutErr(c, e.ERR, err.Error())
  71. return
  72. }
  73. e.OutSuc(c, "success", nil)
  74. return
  75. }
  76. func WxRefundApiCallBack(c *gin.Context) {
  77. var req md.WxCallback
  78. err := c.ShouldBindJSON(&req)
  79. if err != nil {
  80. err = validate.HandleValidateErr(err)
  81. err1 := err.(e.E)
  82. e.OutErr(c, err1.Code, err1.Error())
  83. return
  84. }
  85. sysCfgDb := db.SysCfgDb{}
  86. sysCfgDb.Set()
  87. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchApiV3Key)
  88. //TODO::进行解密
  89. decryptString, err := utils.DecryptAES256GCM(sysCfg[enum.WxSpMchApiV3Key], req.Resource.AssociatedData, req.Resource.Nonce, req.Resource.Ciphertext)
  90. if err != nil {
  91. e.OutErr(c, e.ERR, "解密失败")
  92. return
  93. }
  94. fmt.Println(">>>>>>>>>>WxRefundApiCallBack<<<<<<<<<", decryptString)
  95. utils2.FilePutContents("WxRefundApiCallBack", decryptString)
  96. //var resp md.WxPayCallback
  97. //err = json.Unmarshal([]byte(decryptString), &resp)
  98. //if err != nil {
  99. // e.OutErr(c, e.ERR, err.Error())
  100. // return
  101. //}
  102. //
  103. //_, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState)
  104. //if err != nil {
  105. // e.OutErr(c, e.ERR, err.Error())
  106. // return
  107. //}
  108. e.OutSuc(c, "success", nil)
  109. return
  110. }