You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
package copartner
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"errors"
|
|
"io/ioutil"
|
|
"recook/internal/dbc"
|
|
"recook/internal/libs/aliyun"
|
|
"recook/internal/model/gys"
|
|
"recook/internal/static_path"
|
|
)
|
|
|
|
var LicenseLogic = &licenseLogic{}
|
|
|
|
type licenseLogic struct {
|
|
}
|
|
|
|
// License @Title 获取营业执照
|
|
func (c *licenseLogic) License(licenseUrl string) (string, string, error) {
|
|
if licenseUrl == "" {
|
|
return "", "", errors.New("参数错误")
|
|
}
|
|
licenseInfo := gys.OcrBusinessLicense{}
|
|
dbc.DB.First(&licenseInfo, "img_path = ?", licenseUrl)
|
|
if licenseInfo.Id > 0 {
|
|
return licenseInfo.Name, licenseInfo.RegNum, errors.New("参数错误")
|
|
}
|
|
file, err := ioutil.ReadFile(static_path.Dir.Root + licenseUrl)
|
|
if err != nil {
|
|
return "", "", errors.New("图片地址错误")
|
|
}
|
|
license, err := aliyun.Ocr.BusinessLicense(base64.StdEncoding.EncodeToString(file))
|
|
if err != nil {
|
|
return "", "", errors.New("未识别出印业执照")
|
|
}
|
|
isSuccess := 0
|
|
if license.Success {
|
|
isSuccess = 1
|
|
}
|
|
dbc.DB.Create(&gys.OcrBusinessLicense{
|
|
ImgPath: licenseUrl,
|
|
IsSuccess: isSuccess,
|
|
Name: license.Name,
|
|
RegNum: license.RegNum,
|
|
})
|
|
return license.Name, license.RegNum, nil
|
|
}
|