fix upload

This commit is contained in:
liangzai 2025-04-25 13:01:40 +08:00
parent 6f0b876dfc
commit c3811cf8d2

View File

@ -7,19 +7,20 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/qiniu/go-sdk/v7/storagev2/credentials"
"github.com/qiniu/go-sdk/v7/storagev2/http_client"
"github.com/qiniu/go-sdk/v7/storagev2/uploader"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"io"
"math/big"
"net/http"
"net/url"
"os"
"strings"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"time"
"github.com/qiniu/go-sdk/v7/storagev2/credentials"
"github.com/qiniu/go-sdk/v7/storagev2/http_client"
"github.com/qiniu/go-sdk/v7/storagev2/uploader"
"github.com/zeromicro/go-zero/core/logx"
)
@ -65,15 +66,15 @@ func (l *UploadBusinessLicenseLogic) UploadBusinessLicense(r *http.Request) (res
// 5. 调用百度智能云进行营业执照识别
tempFilePath := tempFile.Name()
fileBytes, err := os.ReadFile(tempFilePath)
if err != nil {
return nil, fmt.Errorf("读取临时文件失败: %v", err)
}
// fileBytes, err := os.ReadFile(tempFilePath)
// if err != nil {
// return nil, fmt.Errorf("读取临时文件失败: %v", err)
// }
licenseInfo, err := l.RecognizeBusinessLicense(fileBytes)
if err != nil {
return nil, fmt.Errorf("营业执照识别失败: %v", err)
}
// licenseInfo, err := l.RecognizeBusinessLicense(fileBytes)
// if err != nil {
// return nil, fmt.Errorf("营业执照识别失败: %v", err)
// }
// 6. 生成新的文件名
newFileName := l.GenerateFileName("business_license_", handler.Filename)
@ -87,9 +88,12 @@ func (l *UploadBusinessLicenseLogic) UploadBusinessLicense(r *http.Request) (res
// 8. 返回百度智能云的识别信息和图片URL给前端
return &types.UploadBusinessLicenseResp{
Url: imageUrl,
EnterpriseName: licenseInfo["company_name"],
CreditCode: licenseInfo["credit_code"],
LegalPerson: licenseInfo["legal_person"],
// EnterpriseName: licenseInfo["company_name"],
// CreditCode: licenseInfo["credit_code"],
// LegalPerson: licenseInfo["legal_person"],
EnterpriseName: "",
CreditCode: "",
LegalPerson: "",
}, nil
}