| | |
| | | /// <param name="url"></param> |
| | | /// <param name="scene"></param> |
| | | /// <param name="isOssUrl"></param> |
| | | public static async Task<BaiduOcrBusinessLicenseResult> OcrBusinessLicense(this string url, string scene, bool isOssUrl = true) |
| | | public static async Task<BaiduOcrBusinessLicenseResult> OcrBusinessLicense(this string url, string scene = null, bool isOssUrl = true) |
| | | { |
| | | var options = App.GetOptions<BaiduOptions>(); |
| | | var ocr = new Ocr(options.Ocr.Key, options.Ocr.Secret); |
| | |
| | | RegisteredCapital = result.WordsResult["注册资本"].Words, |
| | | EstablishmentDate = result.WordsResult["成立日期"].Words, |
| | | Address = result.WordsResult["地址"].Words, |
| | | BusinessScope = result.WordsResult["经营范围"].Words, |
| | | MainBusiness = result.WordsResult["经营范围"].Words, |
| | | }; |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 身份证正面OCR |
| | | /// </summary> |
| | | /// <param name="url"></param> |
| | | /// <param name="scene"></param> |
| | | /// <param name="isOssUrl"></param> |
| | | public static async Task<BaiduOcrIdentityFrontResult> OcrIdentityFront(this string url, string scene = null, bool isOssUrl = true) |
| | | { |
| | | var options = App.GetOptions<BaiduOptions>(); |
| | | var ocr = new Ocr(options.Ocr.Key, options.Ocr.Secret); |
| | | ocr.Timeout = 60000; |
| | | JObject value; |
| | | if (isOssUrl) |
| | | { |
| | | var downloadUrl = AliyunOSSUtils.GetUrl(url); |
| | | var buffer = await App.GetRequiredService<IHttpRemoteService>().GetAsByteArrayAsync(downloadUrl); |
| | | value = ocr.Idcard(buffer, "front"); |
| | | } |
| | | else |
| | | { |
| | | var upload = AliyunOSSUtils.Upload(scene, url); |
| | | url = upload.Url; |
| | | value = ocr.Idcard(upload.Buffer, "front"); |
| | | } |
| | | var result = value.ToObject<BaiduOcrIdentityFrontResult>(); |
| | | result.Url = url; |
| | | if (result.ErrorCode.IsNotNull()) |
| | | { |
| | | return result; |
| | | } |
| | | |
| | | result.Model = new BaiduOcrIdentityFrontResultModel |
| | | { |
| | | Address = result.WordsResult["住址"].Words, |
| | | Identity = result.WordsResult["公民身份号码"].Words, |
| | | BirthdayText = result.WordsResult["出生"].Words, |
| | | Name = result.WordsResult["姓名"].Words, |
| | | GenderText = result.WordsResult["性别"].Words, |
| | | Nation = result.WordsResult["民族"].Words, |
| | | }; |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 身份证背面OCR |
| | | /// </summary> |
| | | /// <param name="url"></param> |
| | | /// <param name="scene"></param> |
| | | /// <param name="isOssUrl"></param> |
| | | public static async Task<BaiduOcrIdentityBackResult> OcrIdentityBack(this string url, string scene = null, bool isOssUrl = true) |
| | | { |
| | | var options = App.GetOptions<BaiduOptions>(); |
| | | var ocr = new Ocr(options.Ocr.Key, options.Ocr.Secret); |
| | | ocr.Timeout = 60000; |
| | | JObject value; |
| | | if (isOssUrl) |
| | | { |
| | | var downloadUrl = AliyunOSSUtils.GetUrl(url); |
| | | var buffer = await App.GetRequiredService<IHttpRemoteService>().GetAsByteArrayAsync(downloadUrl); |
| | | value = ocr.Idcard(buffer, "back"); |
| | | } |
| | | else |
| | | { |
| | | var upload = AliyunOSSUtils.Upload(scene, url); |
| | | url = upload.Url; |
| | | value = ocr.Idcard(upload.Buffer, "back"); |
| | | } |
| | | var result = value.ToObject<BaiduOcrIdentityBackResult>(); |
| | | result.Url = url; |
| | | if (result.ErrorCode.IsNotNull()) |
| | | { |
| | | return result; |
| | | } |
| | | |
| | | result.Model = new BaiduOcrIdentityBackResultModel |
| | | { |
| | | ExpiryDateText = result.WordsResult["失效日期"].Words, |
| | | IssueAuthority = result.WordsResult["签发机关"].Words, |
| | | IssueDateText = result.WordsResult["签发日期"].Words, |
| | | }; |
| | | return result; |
| | | } |
| | | } |
| | | } |