12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package controller
- import (
- "ElectronicInvoice/internal/service"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/net/ghttp"
- "net/url"
- "strings"
- )
- // CallBack 回调
- func CallBack(r *ghttp.Request) {
- err := func() error {
- callType := r.Get("calltype").String()
- 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(r.Context(), "长在线退出登录")
- case "Invoicing": //开发票回调
- return service.InvoicingCallBackLogic(r)
- case "InvoicingAll": //批量开票
- g.Log().Info(r.Context(), "用户退出登录")
- case "offset":
- return service.InvoicingMakeRedCallBackLogic(r)
- case "livenessDetection":
- g.Log().Info(r.Context(), "活体认证:%s")
- case "login": //扫码登录回调
- var flag bool
- if r.Get("code").String() == "200" {
- flag = true
- }
- service.JyInvoiceManager.ScanLogin <- flag
- case "quit":
- switch r.Get("taskType").String() {
- case "2": //电子发票开具
- service.JyInvoiceManager.ReleasePool() //可进行下次开票请求
- case "4": //活体认证
- case "5": //验证电子税局登录授权
- case "9": //红冲
- service.JyInvoiceManager.ReleasePool() //可进行下次开票请求
- }
- default:
- g.Log().Infof(r.Context(), "未设置消息回调:%s", callType)
- }
- return nil
- }()
- if err != nil {
- g.Log().Errorf(r.Context(), "回调异常:%v", 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
- }
|