diff --git a/internal/v2/controller/wxapp/copartner/license.go b/internal/v2/controller/wxapp/copartner/license.go new file mode 100644 index 0000000..f9e4ba6 --- /dev/null +++ b/internal/v2/controller/wxapp/copartner/license.go @@ -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, + }) + } +} diff --git a/internal/v2/logic/wxapp/copartner/license.go b/internal/v2/logic/wxapp/copartner/license.go new file mode 100644 index 0000000..a466753 --- /dev/null +++ b/internal/v2/logic/wxapp/copartner/license.go @@ -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 +} diff --git a/internal/v2/router/wxapp.go b/internal/v2/router/wxapp.go index dfa17d7..38379b7 100644 --- a/internal/v2/router/wxapp.go +++ b/internal/v2/router/wxapp.go @@ -22,6 +22,10 @@ func routerWxapp(wxappRouter *gin.RouterGroup) { { copartnerRouter.POST("personal/add", personalController.Add) // wxapp添加合伙人-个人 } + licenseController := copartner.License{} + { + copartnerRouter.POST("license", licenseController.License) // wxapp识别营业执照 + } } fileR := wxappRouter.Group("files")