package controller import ( "ElectronicInvoice/internal/service" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/util/gconv" "net/url" "strings" ) // CallBack 回调 func CallBack(r *ghttp.Request) { var ( callType = r.Get("calltype").String() ctx = r.Context() ) err := func() error { if g.Cfg().MustGet(r.Context(), "reqDebug", false).Bool() { g.Log().Infof(r.Context(), "%s\n接口回调 信息调试\ncallType: %s\ncallBack form: %+v", strings.Repeat("=", 50), callType, printFilter(r.Request.Form)) } switch callType { case "userQuit": //用户退出登录 service.JyInvoiceManager.Login = false g.Log().Info(ctx, "长在线退出登录") case "Invoicing": //开发票回调 return service.InvoicingCallBackLogic(r) case "InvoicingAll": //批量开票 g.Log().Info(ctx, "用户退出登录") case "offset": return service.InvoicingMakeRedCallBackLogic(r) case "livenessDetection": g.Log().Info(ctx, "活体认证:%s") case "login": //扫码登录回调 var flag bool if r.Get("code").String() == "200" { flag = true } service.JyInvoiceManager.ScanLogin <- flag case "quit": qData := gconv.Map(r.Get("data")) switch qData["taskType"] { case "2": //电子发票开具 <-service.JyInvoiceManager.RunPool //可进行下次开票请求 g.Log().Infof(ctx, "开具发票结束") case "4": //活体认证 case "5": //验证电子税局登录授权 case "9": //红冲 <-service.JyInvoiceManager.RunPool //可进行下次开票请求 g.Log().Infof(ctx, "发票冲红结束") default: g.Log().Infof(ctx, "未知回调任务退出 %+v", qData) } default: g.Log().Infof(ctx, "未设置消息回调:%s", callType) } return nil }() if err != nil { g.Log().Errorf(ctx, "回调异常 callType: %s Error: %v", callType, err) return } r.Response.WriteJson(g.MapStrStr{"code": "200"}) } // printFilter 打印参数调试 func printFilter(value url.Values) map[string][]string { var filter = []string{"pdf"} //过滤部分字段 res := map[string][]string{} for key, val := range value { add := true for _, v := range filter { if key == v { add = false break } } if add { res[key] = val } } return res }