惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
Project Zero
Project Zero
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tor Project blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
Cloudbric
Cloudbric
I
Intezer
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
AI
AI
B
Blog
S
Securelist
P
Proofpoint News Feed
量子位
Jina AI
Jina AI
V2EX - 技术
V2EX - 技术
T
The Exploit Database - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - Tonyyang

【XAF】如何通过前缀或自定义架构将数据库表与内置系统表分开 Power Shell 7 和5.1 批量给pdf添加页码 [XAF] Declare Conditional Appearance Rules in Code DataTableHelper C# 多任务数据同步 【原】 XAF Localization改用百度翻译 SqlQueryDynamic BOM导入 C#上传到FTP Server FREE OFFER - .NET App Security API (Role-based Access Control) 后台管理框架 Model to Model JSON序列化和反序列化日期时间的处理 Asp.net MVC 上传文件 Asp.net MVC bootstrap 穿梭框 EXT.NET Combox下拉Grid 转 Refresh Excel Pivot Tables Automatically Using SSIS Script Task SQL Server Integration Services SSIS最佳实践 PowerBI
C#百度翻译--亲测试可用
Tonyyang · 2022-08-19 · via 博客园 - Tonyyang
 public class Rootobject
    {
        public string from { get; set; }
        public string to { get; set; }
        public string domain { get; set; }
        public int type { get; set; }
        public int status { get; set; }

        public int error { get; set; }
        public string msg { get; set; }

        public Trans_Result[] trans_result { get; set; }
    }

    public class Trans_Result
    {
        public string src { get; set; }
        public string dst { get; set; }

        public int prefixWrap { get; set; }

        public object[] relation { get; set; }
        public object[][] result { get; set; }
    }

public static async Task<Rootobject> Baidu_Translate(string content) { return await Baidu_Translate("en", "zh", content); } public static async Task<Rootobject> Baidu_Translate(string from, string to, string content) { // 原文 string q = content; // 源语言 // 改成您的APP ID string appId = ""; Random rd = new Random(); string salt = rd.Next(100000).ToString(); // 改成您的密钥 string secretKey = ""; string sign = EncryptString(appId + q + salt + secretKey); string url = "http://api.fanyi.baidu.com/api/trans/vip/translate?"; url += "q=" + HttpUtility.UrlEncode(q); url += "&from=" + from; url += "&to=" + to; url += "&appid=" + appId; url += "&salt=" + salt; url += "&sign=" + sign; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; request.UserAgent = null; request.Timeout = 6000; using (WebResponse response = await request.GetResponseAsync()) { using (Stream myResponseStream = response.GetResponseStream()) { using (StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"))) { string retString = myStreamReader.ReadToEnd(); Debug.WriteLine(retString); var result = JsonConvert.DeserializeObject<Rootobject>(retString); return result; } } } } // 计算MD5值 public static string EncryptString(string str) { MD5 md5 = MD5.Create(); // 将字符串转换成字节数组 byte[] byteOld = Encoding.UTF8.GetBytes(str); // 调用加密方法 byte[] byteNew = md5.ComputeHash(byteOld); // 将加密结果转换为字符串 StringBuilder sb = new StringBuilder(); foreach (byte b in byteNew) { // 将字节转换成16进制表示的字符串, sb.Append(b.ToString("x2")); } // 返回加密的字符串 return sb.ToString(); } private async void button1_Click(object sender, EventArgs e) { var res = await Baidu_Translate(richTextBox1.Text); string result = res.trans_result[0].dst; richTextBox2.Text = result; }