package hdl import ( "applet/app/admin/lib/validate" "applet/app/customer/md" "applet/app/customer/svc" "applet/app/db" "applet/app/e" "applet/app/enum" utils2 "applet/app/utils" "encoding/json" "fmt" "github.com/gin-gonic/gin" "github.com/wechatpay-apiv3/wechatpay-go/utils" ) func AlipayJsApiCallBack(c *gin.Context) { data := svc.CheckAllCallbackParams(c) if data == nil { e.OutErr(c, e.ERR_INVALID_ARGS) return } c.Set("callback", data) args, ok := data.(*md.AliPayCallback) if !ok { fmt.Println("反射ok失败") e.OutErr(c, e.ERR_INVALID_ARGS, "反射失败") return } if args.GmtRefund != "" { //TODO::退款通知不需要处理 c.String(200, "success") return } _, err := svc.DealCentralKitchenForSchoolOrderCallBack(args.OutTradeNo, args.TradeStatus) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } //TODO::此处需要直接输出 success,避免支付宝重复回调 //c.Header("Content-Type", "text/html; charset=utf-8") c.String(200, "success") } func WxJsApiCallBack(c *gin.Context) { var req md.WxCallback err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } sysCfgDb := db.SysCfgDb{} sysCfgDb.Set() sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchApiV3Key) //TODO::进行解密 decryptString, err := utils.DecryptAES256GCM(sysCfg[enum.WxSpMchApiV3Key], req.Resource.AssociatedData, req.Resource.Nonce, req.Resource.Ciphertext) if err != nil { e.OutErr(c, e.ERR, "解密失败") return } fmt.Println(">>>>>>>>>>", decryptString) var resp md.WxPayCallback err = json.Unmarshal([]byte(decryptString), &resp) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } utils2.FilePutContents("WxJsApiCallBack", utils2.SerializeStr(resp)) _, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return } func WxRefundApiCallBack(c *gin.Context) { var req md.WxCallback err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } sysCfgDb := db.SysCfgDb{} sysCfgDb.Set() sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchApiV3Key) //TODO::进行解密 decryptString, err := utils.DecryptAES256GCM(sysCfg[enum.WxSpMchApiV3Key], req.Resource.AssociatedData, req.Resource.Nonce, req.Resource.Ciphertext) if err != nil { e.OutErr(c, e.ERR, "解密失败") return } fmt.Println(">>>>>>>>>>WxRefundApiCallBack<<<<<<<<<", decryptString) utils2.FilePutContents("WxRefundApiCallBack", decryptString) //var resp md.WxPayCallback //err = json.Unmarshal([]byte(decryptString), &resp) //if err != nil { // e.OutErr(c, e.ERR, err.Error()) // return //} // //_, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx(resp.OutTradeNo, resp.TransactionId, resp.TradeState) //if err != nil { // e.OutErr(c, e.ERR, err.Error()) // return //} e.OutSuc(c, "success", nil) return }