callback.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. "net/url"
  7. "strings"
  8. )
  9. // CallBack 回调
  10. func CallBack(r *ghttp.Request) {
  11. err := func() error {
  12. callType := r.Get("calltype").String()
  13. if g.Cfg().MustGet(r.Context(), "reqDebug", false).Bool() {
  14. g.Log().Infof(r.Context(), "%s\n接口回调 信息调试\ncallType: %s\ncallBack form: %+v", strings.Repeat("=", 50), callType, printFilter(r.Request.Form))
  15. }
  16. switch callType {
  17. case "userQuit": //用户退出登录
  18. service.JyInvoiceManager.Login = false
  19. g.Log().Info(r.Context(), "长在线退出登录")
  20. case "Invoicing": //开发票回调
  21. return service.InvoicingCallBackLogic(r)
  22. case "InvoicingAll": //批量开票
  23. g.Log().Info(r.Context(), "用户退出登录")
  24. case "offset":
  25. return service.InvoicingMakeRedCallBackLogic(r)
  26. case "livenessDetection":
  27. g.Log().Info(r.Context(), "活体认证:%s")
  28. default:
  29. g.Log().Infof(r.Context(), "未设置消息回调:%s", callType)
  30. }
  31. return nil
  32. }()
  33. if err != nil {
  34. g.Log().Errorf(r.Context(), "回调异常:%v", err)
  35. return
  36. }
  37. r.Response.WriteJson(g.MapStrStr{"code": "200"})
  38. }
  39. // printFilter 打印参数调试
  40. func printFilter(value url.Values) map[string][]string {
  41. var filter = []string{"pdf"} //过滤部分字段
  42. res := map[string][]string{}
  43. for key, val := range value {
  44. add := true
  45. for _, v := range filter {
  46. if key == v {
  47. add = false
  48. break
  49. }
  50. }
  51. if add {
  52. res[key] = val
  53. }
  54. }
  55. return res
  56. }