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

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