using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Reflection;
|
using System.Threading.Tasks;
|
using TencentCloud.Common;
|
using TencentCloud.Common.Profile;
|
using TencentCloud.Ocr.V20181119;
|
using TencentCloud.Ocr.V20181119.Models;
|
|
namespace Helpers
|
{
|
public static class PublicApiHelpers
|
{
|
|
|
#region 腾讯API接口
|
|
/// <summary>
|
/// 发送“通用印刷体识别(高精度版)”请求(腾讯)
|
/// </summary>
|
/// <param name="SecretId">密钥参数SecretId</param>
|
/// <param name="SecretKey">密钥参数SecretKey</param>
|
/// <param name="Endpoint">请求URL</param>
|
/// <param name="Region">地域参数,用来标识希望操作哪个地域的数据。</param>
|
/// <param name="ImageUrl">
|
/// 图片的 Url 地址。
|
/// 要求图片经Base64编码后不超过 7M,分辨率建议600*800以上
|
/// 支持PNG、JPG、JPEG、BMP格式。
|
/// </param>
|
/// <returns></returns>
|
public static string SendGeneralAccurateOCRTC(string SecretId, string SecretKey, string Endpoint, string Region, string ImageUrl,string ImageBase64="")
|
{
|
try
|
{
|
Credential cred = new Credential
|
{
|
SecretId = SecretId,
|
SecretKey = SecretKey
|
};
|
|
ClientProfile clientProfile = new ClientProfile();
|
HttpProfile httpProfile = new HttpProfile();
|
httpProfile.Endpoint = (Endpoint);
|
clientProfile.HttpProfile = httpProfile;
|
|
OcrClient client = new OcrClient(cred, Region, clientProfile);
|
GeneralAccurateOCRRequest req = new GeneralAccurateOCRRequest();
|
if (!string.IsNullOrWhiteSpace(ImageUrl)) {
|
req.ImageUrl = ImageUrl;
|
}
|
else {
|
req.ImageBase64 = ImageBase64;
|
}
|
GeneralAccurateOCRResponse resp = client.GeneralAccurateOCRSync(req);
|
return AbstractModel.ToJsonString(resp);
|
}
|
catch (Exception e)
|
{
|
Helpers.Tool.PrintLog_Error("程序(SendGeneralAccurateOCRTC)运行异常:" + e.Message, e.StackTrace+"\r\n"+ ImageUrl);
|
return string.Empty;
|
}
|
}
|
|
#endregion
|
|
#region 百度API接口
|
|
//private static string GetAccessTokenBD()
|
//{
|
// var config = Tool.GetSystemConfig().BDApi;
|
|
// Dictionary<string, string> dic = new Dictionary<string, string>();
|
// dic.Add("grant_type", config.accessToken.grant_type);
|
// dic.Add("client_id", config.accessToken.client_id);
|
// dic.Add("client_secret", config.accessToken.client_secret);
|
// string paramStr = Tool.DicToUrlParam(dic);
|
|
// string res = Tool.HttpPost(config.accessToken.RequestUrl, paramStr);
|
|
// if (res.IndexOf("error") > -1)
|
// {
|
// //请求token错误,记录下错误情况
|
|
// Tool.PrintLog_Error("百度API Token验证获取失败", $"百度API Token验证获取失败,请求参数:{paramStr},请求地址:{config.accessToken.RequestUrl},返回结果:{res}");
|
// return string.Empty;
|
// }
|
|
// Hashtable hst = res.ToModel<Hashtable>();
|
|
// //记录到redis中
|
|
// return "";
|
//}
|
|
|
//public static string SendGeneralAccurateOCRBD() { }
|
|
#endregion
|
}
|
}
|