callback.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controller
  2. import (
  3. "ElectronicInvoice/internal/service"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "github.com/gogf/gf/v2/net/ghttp"
  6. "strings"
  7. )
  8. // CallBack 回调
  9. func CallBack(r *ghttp.Request) {
  10. err := func() error {
  11. callType := r.Get("calltype").String()
  12. if g.Cfg().MustGet(r.Context(), "reqDebug", false).Bool() {
  13. g.Log().Infof(r.Context(), "%s\ncallType: %s\ncallBack: %s", strings.Repeat("=", 50), callType, string(r.GetBody()))
  14. }
  15. switch callType {
  16. case "userQuit": //用户退出登录
  17. g.Log().Info(r.Context(), "长在线退出登录")
  18. case "Invoicing": //开发票回调
  19. return service.InvoicingCallBackLogic(r)
  20. case "InvoicingAll": //批量开票
  21. g.Log().Info(r.Context(), "用户退出登录")
  22. case "Offset":
  23. g.Log().Info(r.Context(), "开红票:%s")
  24. case "livenessDetection":
  25. g.Log().Info(r.Context(), "活体认证:%s")
  26. default:
  27. g.Log().Infof(r.Context(), "未设置消息回调:%s", callType)
  28. }
  29. return nil
  30. }()
  31. if err != nil {
  32. g.Log().Errorf(r.Context(), "回调异常:%v", err)
  33. return
  34. }
  35. r.Response.WriteJson(g.MapStrStr{"code": "200"})
  36. }
  37. //callbak = logging