callback.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. case "quit":
  35. switch r.Get("taskType").String() {
  36. case "2": //电子发票开具
  37. service.JyInvoiceManager.ReleasePool() //可进行下次开票请求
  38. case "4": //活体认证
  39. case "5": //验证电子税局登录授权
  40. case "9": //红冲
  41. service.JyInvoiceManager.ReleasePool() //可进行下次开票请求
  42. }
  43. default:
  44. g.Log().Infof(r.Context(), "未设置消息回调:%s", callType)
  45. }
  46. return nil
  47. }()
  48. if err != nil {
  49. g.Log().Errorf(r.Context(), "回调异常:%v", err)
  50. return
  51. }
  52. r.Response.WriteJson(g.MapStrStr{"code": "200"})
  53. }
  54. // printFilter 打印参数调试
  55. func printFilter(value url.Values) map[string][]string {
  56. var filter = []string{"pdf"} //过滤部分字段
  57. res := map[string][]string{}
  58. for key, val := range value {
  59. add := true
  60. for _, v := range filter {
  61. if key == v {
  62. add = false
  63. break
  64. }
  65. }
  66. if add {
  67. res[key] = val
  68. }
  69. }
  70. return res
  71. }