智慧食堂
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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