From 92907c90c43279cd2b64e1b6847f0b5d3b6ac1ec Mon Sep 17 00:00:00 2001 From: lilium-saber Date: Fri, 13 Oct 2023 16:49:44 +0800 Subject: [PATCH] jah Signed-off-by: lilium-saber --- src/Network/TransNetworkApi.cs | 11 +++- src/Network/jsonNet.cs | 29 +++++++-- src/WinOcr/OcrSofia.cs | 71 +++++++++++++++++++++ src/WinOcr/Sofia.cs | 13 ++++ src/translationKey/translationApi.cs | 2 +- src/translationKey/translationPrivateIn.cs | 2 +- src/translationKey/translationPrivateOut.cs | 2 +- src/translationKey/translationPublic.cs | 5 +- 8 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 src/WinOcr/OcrSofia.cs create mode 100644 src/WinOcr/Sofia.cs diff --git a/src/Network/TransNetworkApi.cs b/src/Network/TransNetworkApi.cs index 3b826eb..ef60641 100644 --- a/src/Network/TransNetworkApi.cs +++ b/src/Network/TransNetworkApi.cs @@ -6,14 +6,19 @@ using System.Threading.Tasks; namespace testRjgc.transToNet { - interface StrToJson + interface Messiah { - public abstract string RequestJsonPrivate(string input, string srcl, string dstl, string aid, string kkey); + public abstract string RequestJsonPrivateBaiDu(string input, string srcl, string dstl, string aid, string kkey); - public abstract string RequestJsonLanguageChange(string input, string srcl, string dstl); + public abstract string RequestJsonLanguageChangeBaiDu(string input, string srcl, string dstl); public abstract string RequestJsonBaiDu(string input); + public abstract string RequestJsonXunFei(string input); + + public abstract string RequestJsonPrivateXunFei(string input, string srcl, string dstl, string xid, string xkey); + + public abstract string RequestJsonLanguageChangeXunFei(string input, string srcl, string dstl); } /* diff --git a/src/Network/jsonNet.cs b/src/Network/jsonNet.cs index efa384e..783029f 100644 --- a/src/Network/jsonNet.cs +++ b/src/Network/jsonNet.cs @@ -16,14 +16,22 @@ using System.Web; namespace testRjgc.transToNet { - internal class jsonNet : StrToJson + internal class jsonNet : Messiah { static string https = "http://api.fanyi.baidu.com/api/trans/vip/translate?"; - static string appid = "20230925001829663";//20230925001829663,20230923001827495 static Random rd = new Random(); static string salt = rd.Next(100000).ToString(); static string key = "f7ZHpw28izQ1VU_ixoY5";//f7ZHpw28izQ1VU_ixoY5,yjvMNY33Qc1TYSBjTQYQ + //baidu + + static string xunweb = "https://itrans.xf-yun.com/v1/its"; + static string xunid = "1299c840"; + static string xunsec = "M2Q4YzkzZTIwZjNkMGE2ZjkwZWMxNzZk"; + static string xunkey = "828cb2dc915d28464a904bda5d7b01b3"; + static string xunfl = "ja"; + static string xundl = "cn"; + static string xuntxt = "白上"; //static HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://api.fanyi.baidu.com/api/trans/vip/translate?q=apple&from=en&to=zh&appid=20230925001829663&salt=1435660288&sign=c963bc2275c0fd1ed30da014c1ef1933"); @@ -64,7 +72,7 @@ namespace testRjgc.transToNet return sb.ToString(); } - public string RequestJsonPrivate(string input, string srcl, string dstl, string aid, string kkey)//自定义id,key以及源语言和目标语言 + public string RequestJsonPrivateBaiDu(string input, string srcl, string dstl, string aid, string kkey)//自定义id,key以及源语言和目标语言 { string sign = EncryptString(aid + input + salt + kkey); @@ -89,7 +97,7 @@ namespace testRjgc.transToNet return s; } - public string RequestJsonLanguageChange(string input, string srcl, string dstl)//可以自定义源语言与目标语言 + public string RequestJsonLanguageChangeBaiDu(string input, string srcl, string dstl)//可以自定义源语言与目标语言 { string sign = EncryptString(appid + input + salt + key); @@ -137,9 +145,22 @@ namespace testRjgc.transToNet Trans_result result = temp1.trans_result[0]; string s = result.dst; return s; + } + public string RequestJsonXunFei(string input) + { + return "error"; } + public string RequestJsonPrivateXunFei(string input, string srcl, string dstl, string xid, string xkey) + { + return "error"; + } + + public string RequestJsonLanguageChangeXunFei(string input, string srcl, string dstl) + { + return "error"; + } } public class Trans_result { diff --git a/src/WinOcr/OcrSofia.cs b/src/WinOcr/OcrSofia.cs new file mode 100644 index 0000000..eaf14d1 --- /dev/null +++ b/src/WinOcr/OcrSofia.cs @@ -0,0 +1,71 @@ +using System.Drawing; +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace testRjgc.WinOcr +{ + internal class OcrSofia : Sofia + { + static string path = Directory.GetCurrentDirectory() + "\\TempImage"; + + public OcrSofia() { } + + public string WindowsOcrToGetStringAndTranslate(string name) + { + string retxt = ""; + + this.DirExists(); + Image image = null; + + MODI.Document modiDocument = new MODI.Document(); + modiDocument.Create(path + "\\" + name + ".jpg"); + modiDocument.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true); + MODI.Image modiImage = (MODI.Image)modiDocument.Images[0]; + retxt = modiImage.Layout.Text; + return retxt; + } + + public void DirExists() + { + if(Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + } + +/* +internal class OcrSofia : Sofia + { + public OcrSofia() { } + + public string WindowsOcrToGetStringAndTranslate() + { + string result = ""; + + // 获取剪贴板中的图像 + Image image = Clipboard.GetImage(); + + // 将图像保存到临时文件中 + string tempFile = Path.GetTempFileName(); + image.Save(tempFile, ImageFormat.Tiff); + + // 使用Windows OCR引擎识别图像中的文本 + MODI.Document modiDocument = new MODI.Document(); + modiDocument.Create(tempFile); + modiDocument.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true); + MODI.Image modiImage = (MODI.Image)modiDocument.Images[0]; + result = modiImage.Layout.Text; + + // 删除临时文件 + File.Delete(tempFile); + + return result; + } + } +*/ + } +} diff --git a/src/WinOcr/Sofia.cs b/src/WinOcr/Sofia.cs new file mode 100644 index 0000000..cd40e93 --- /dev/null +++ b/src/WinOcr/Sofia.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace testRjgc.WinOcr +{ + internal interface Sofia + { + public abstract string WindowsOcrToGetStringAndTranslate(string name); + } +} diff --git a/src/translationKey/translationApi.cs b/src/translationKey/translationApi.cs index 4caa6cf..a95cfe9 100644 --- a/src/translationKey/translationApi.cs +++ b/src/translationKey/translationApi.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace WpfApp1.translationKey { - interface TranslationApiStr + interface TranslationApiStr//Mohammed { public abstract List OutputTranslationS(string id); diff --git a/src/translationKey/translationPrivateIn.cs b/src/translationKey/translationPrivateIn.cs index a2f8adb..9935304 100644 --- a/src/translationKey/translationPrivateIn.cs +++ b/src/translationKey/translationPrivateIn.cs @@ -17,7 +17,7 @@ namespace WpfApp1.translationKey public void InputTranslationPrivate(string name, string id, string key) { - if(!Directory.Exists(pathTemp)) + if(Directory.Exists(pathTemp)) { Directory.CreateDirectory(pathTemp); } diff --git a/src/translationKey/translationPrivateOut.cs b/src/translationKey/translationPrivateOut.cs index 5ae0e6b..bc38ca6 100644 --- a/src/translationKey/translationPrivateOut.cs +++ b/src/translationKey/translationPrivateOut.cs @@ -58,7 +58,7 @@ namespace WpfApp1.translationKey List temp = new List { }; - if (Directory.Exists(temppath)) + if (Directory.Exists(temppath))//诺不存在 { temp.Add("ERROR"); return temp; diff --git a/src/translationKey/translationPublic.cs b/src/translationKey/translationPublic.cs index 7112139..0a17196 100644 --- a/src/translationKey/translationPublic.cs +++ b/src/translationKey/translationPublic.cs @@ -16,8 +16,9 @@ namespace WpfApp1.translationKey { case 0://讯飞 { - temp.Add("");//APISecret - temp.Add("");//APIKey + temp.Add("1299c840");//id + temp.Add("M2Q4YzkzZTIwZjNkMGE2ZjkwZWMxNzZk");//APISecret + temp.Add("828cb2dc915d28464a904bda5d7b01b3");//APIKey break; } case 1://百度