parent
28e5c7a408
commit
3e5ecc12d2
@ -0,0 +1,35 @@
|
|||||||
|
package copartner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"recook/internal/v2/lib/back"
|
||||||
|
"recook/internal/v2/logic/wxapp/copartner"
|
||||||
|
"recook/tools"
|
||||||
|
)
|
||||||
|
|
||||||
|
type License struct {
|
||||||
|
}
|
||||||
|
type argsCompanyLicense struct {
|
||||||
|
url string // 营业执照 地址
|
||||||
|
}
|
||||||
|
type argsCompanyLicenseResp struct {
|
||||||
|
Taxpayer string `json:"taxpayer"`
|
||||||
|
CorporationName string `json:"corporation_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// License @Title 识别营业执照
|
||||||
|
func (l License) License(c *gin.Context) {
|
||||||
|
var args argsCompanyLicense
|
||||||
|
if err := tools.Params(&args, c); err != nil {
|
||||||
|
back.Fail(c, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if name, num, err := copartner.LicenseLogic.License(args.url); err != nil {
|
||||||
|
back.Fail(c, err.Error())
|
||||||
|
} else {
|
||||||
|
back.Suc(c, "ok", argsCompanyLicenseResp{
|
||||||
|
Taxpayer: num,
|
||||||
|
CorporationName: name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
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
|
||||||
|
}
|
Loading…
Reference in new issue