|
@@ -2,24 +2,11 @@ package controller
|
|
|
|
|
|
import (
|
|
|
"ElectronicInvoice/internal/service"
|
|
|
- "encoding/base64"
|
|
|
- "fmt"
|
|
|
- "github.com/gogf/gf/v2/errors/gerror"
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
|
- "net/url"
|
|
|
- "os"
|
|
|
"strings"
|
|
|
- "time"
|
|
|
)
|
|
|
|
|
|
-type callBackParam struct {
|
|
|
- CallType string `json:"calltype"` // 回调信息类型
|
|
|
- TaxNum string `json:"taxNum"` //税号
|
|
|
- Tel string `json:"tel"` //税号
|
|
|
- Parameter string `json:"parameter"` //校验
|
|
|
-}
|
|
|
-
|
|
|
// CallBack 回调
|
|
|
func CallBack(r *ghttp.Request) {
|
|
|
err := func() error {
|
|
@@ -30,15 +17,15 @@ func CallBack(r *ghttp.Request) {
|
|
|
|
|
|
switch callType {
|
|
|
case "userQuit": //用户退出登录
|
|
|
- g.Log().Infof(r.Context(), "长在线退出登录:%s", "string(bb)")
|
|
|
+ g.Log().Info(r.Context(), "长在线退出登录")
|
|
|
case "Invoicing": //开发票回调
|
|
|
- return InvoicingCallBackLogic(r)
|
|
|
+ return service.InvoicingCallBackLogic(r)
|
|
|
case "InvoicingAll": //批量开票
|
|
|
- g.Log().Infof(r.Context(), "用户退出登录:%s", "string(bb)")
|
|
|
+ g.Log().Info(r.Context(), "用户退出登录")
|
|
|
case "Offset":
|
|
|
- g.Log().Infof(r.Context(), "开红票:%s", "string(bb)")
|
|
|
+ g.Log().Info(r.Context(), "开红票:%s")
|
|
|
case "livenessDetection":
|
|
|
- g.Log().Infof(r.Context(), "活体认证:%s", "string(bb)")
|
|
|
+ g.Log().Info(r.Context(), "活体认证:%s")
|
|
|
default:
|
|
|
g.Log().Infof(r.Context(), "未设置消息回调:%s", callType)
|
|
|
}
|
|
@@ -52,41 +39,3 @@ func CallBack(r *ghttp.Request) {
|
|
|
}
|
|
|
|
|
|
//callbak = logging
|
|
|
-
|
|
|
-// InvoicingCallBackLogic 开票回调逻辑
|
|
|
-func InvoicingCallBackLogic(r *ghttp.Request) error {
|
|
|
- tType := r.Get("type").Int() //type [0 需要活体检测;1 成功 返回base64]
|
|
|
- switch tType {
|
|
|
- case 0: //需要活体检测
|
|
|
- imgVal, err := url.QueryUnescape(r.Get("img").String())
|
|
|
- if err != nil {
|
|
|
- return gerror.Wrap(err, "活体检测二维码解析失败")
|
|
|
- }
|
|
|
- if err := service.SendQrImage2ChatBot(imgVal); err != nil {
|
|
|
- return gerror.Wrap(err, "发送活体检测消息出错")
|
|
|
- }
|
|
|
- case 1: //开票成功
|
|
|
- pdfBase64 := r.Get("pdf").String()
|
|
|
- orderCode := r.Get("id").String()
|
|
|
- fmt.Println("orderCode")
|
|
|
- data, err := base64.StdEncoding.DecodeString(pdfBase64)
|
|
|
- if err != nil {
|
|
|
- return gerror.Wrap(err, "解析文件base64编码失败")
|
|
|
- }
|
|
|
- if err := os.WriteFile(fmt.Sprintf("./%s_%d.pdf", orderCode, time.Now().Unix()), data, 0644); err != nil {
|
|
|
- return gerror.Wrap(err, "解析文件base64编码失败")
|
|
|
- }
|
|
|
- g.Log().Infof(r.Context(), "pdf保存成功")
|
|
|
- case 3:
|
|
|
- g.Log().Info(r.Context(), "活体验证已过期,未完成活体验证")
|
|
|
- case 4:
|
|
|
- g.Log().Info(r.Context(), "系统错误")
|
|
|
- case 6:
|
|
|
- g.Log().Info(r.Context(), "税率不存在")
|
|
|
- case 7:
|
|
|
- g.Log().Info(r.Context(), "非数电票试点纳税人,未核定数电票票种,不允许开票或其他原因")
|
|
|
- default:
|
|
|
- g.Log().Infof(r.Context(), "InvoicingCallBackLogic tType:%s", tType)
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|