|
|
|
@ -51,6 +51,7 @@ using System.Threading;
|
|
|
|
|
using Furion.JsonSerialization;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using Myshipping.Application.Helper;
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
@ -784,7 +785,8 @@ namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("提单号:" + MBLNO + " 调用运踪接口");
|
|
|
|
|
var key = _repWebAcc.FirstOrDefault(x => x.TenantId == Convert.ToInt64(UserManager.TENANT_ID) && x.TypeCode == "seae_billtraceurl");
|
|
|
|
|
if (key==null) {
|
|
|
|
|
if (key == null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah("调用运踪接口相关账号未维护!");
|
|
|
|
|
}
|
|
|
|
@ -2196,6 +2198,122 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ocr
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上传ocr文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingOrder/OcrUpFile")]
|
|
|
|
|
public async Task<string> OcrUpFile(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
//未上传文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("未上传文件");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var originalFilename = file.FileName; // 文件原始名称
|
|
|
|
|
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
|
|
|
|
|
|
|
|
|
|
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
|
|
|
|
|
if (!serverUrl.EndsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
serverUrl += "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ms = new MemoryStream();
|
|
|
|
|
await file.CopyToAsync(ms);
|
|
|
|
|
_logger.LogInformation($"调用ocr处理文件{originalFilename}");
|
|
|
|
|
|
|
|
|
|
//Furion框架上传文件名称带有双引号,导致上传失败
|
|
|
|
|
//var strRtn = await $"{serverUrl}pdf/upload"
|
|
|
|
|
// .SetContentType("multipart/form-data")
|
|
|
|
|
// .SetContentEncoding(Encoding.UTF8)
|
|
|
|
|
// .SetBodyBytes(("file", ms.GetBuffer(), "test.pdf"))
|
|
|
|
|
// .PostAsStringAsync();
|
|
|
|
|
//var jobj = strRtn.ToJObject();
|
|
|
|
|
//if (jobj.GetIntValue("code") == 0)
|
|
|
|
|
//{
|
|
|
|
|
// var fn = jobj.GetStringValue("data");
|
|
|
|
|
// return fn;
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(jobj.GetStringValue("message"));
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//使用HttpClient方式上传文件
|
|
|
|
|
ms.Position = 0;
|
|
|
|
|
var formData = new MultipartFormDataContent();
|
|
|
|
|
formData.Add(new StreamContent(ms, (int)ms.Length), "file", originalFilename);
|
|
|
|
|
var _httpclient = new HttpClient();
|
|
|
|
|
var response = await _httpclient.PostAsync($"{serverUrl}pdf/upload", formData);
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
var strRtn = response.Content.ReadAsStringAsync().Result;
|
|
|
|
|
var jobj = strRtn.ToJObject();
|
|
|
|
|
if (jobj.GetIntValue("code") == 0)
|
|
|
|
|
{
|
|
|
|
|
var fn = jobj.GetStringValue("data");
|
|
|
|
|
return fn;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(jobj.GetStringValue("message"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah("文件上传失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取图片
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fileName">文件名称</param>
|
|
|
|
|
/// <param name="scale">缩放比例,默认为1.5</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingOrder/OcrGetImg")]
|
|
|
|
|
public async Task<IActionResult> OcrGetImg(string fileName, float scale = 1.5f)
|
|
|
|
|
{
|
|
|
|
|
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
|
|
|
|
|
if (!serverUrl.EndsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
serverUrl += "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bs = await $"{serverUrl}pdf/getCanvasImage?fileName={fileName}&scale={scale}"
|
|
|
|
|
.GetAsByteArrayAsync();
|
|
|
|
|
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = "ocr.jpg" };
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取文字
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fileName">文件名称</param>
|
|
|
|
|
/// <param name="scale">缩放比例</param>
|
|
|
|
|
/// <param name="x">x坐标</param>
|
|
|
|
|
/// <param name="y">y坐标</param>
|
|
|
|
|
/// <param name="w">宽度</param>
|
|
|
|
|
/// <param name="h">高度</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingOrder/OcrGetText")]
|
|
|
|
|
public async Task<string> OcrGetText(string fileName, float scale, int x, int y, int w, int h)
|
|
|
|
|
{
|
|
|
|
|
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
|
|
|
|
|
if (!serverUrl.EndsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
serverUrl += "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var str = await $"{serverUrl}pdf/getRegionText?fileName={fileName}&scale={scale}&x={x}&y={y}&w={w}&h={h}"
|
|
|
|
|
.PostAsStringAsync();
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 其他
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取用户报表的json
|
|
|
|
|