callback.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. case "login": //扫码登录回调
  29. var flag bool
  30. if r.Get("code").String() == "200" {
  31. flag = true
  32. }
  33. service.JyInvoiceManager.ScanLogin <- flag
  34. default:
  35. g.Log().Infof(r.Context(), "未设置消息回调:%s", callType)
  36. }
  37. return nil
  38. }()
  39. if err != nil {
  40. g.Log().Errorf(r.Context(), "回调异常:%v", err)
  41. return
  42. }
  43. r.Response.WriteJson(g.MapStrStr{"code": "200"})
  44. }
  45. // printFilter 打印参数调试
  46. func printFilter(value url.Values) map[string][]string {
  47. var filter = []string{"pdf"} //过滤部分字段
  48. res := map[string][]string{}
  49. for key, val := range value {
  50. add := true
  51. for _, v := range filter {
  52. if key == v {
  53. add = false
  54. break
  55. }
  56. }
  57. if add {
  58. res[key] = val
  59. }
  60. }
  61. return res
  62. }