|
|
|
@ -0,0 +1,86 @@
|
|
|
|
|
using Stripe.Terminal;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Reflection.Metadata;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Security.Policy;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
namespace WpfApp1.translationKey
|
|
|
|
|
{
|
|
|
|
|
internal class jsonNet
|
|
|
|
|
{
|
|
|
|
|
static string https = "http://api.fanyi.baidu.com/api/trans/vip/translate?";
|
|
|
|
|
|
|
|
|
|
static string trans = "apple";
|
|
|
|
|
static string appid = "20230925001829663";
|
|
|
|
|
static string fl = "en";
|
|
|
|
|
static string dl = "zh";
|
|
|
|
|
static Random rd = new Random();
|
|
|
|
|
static string salt = rd.Next(100000).ToString();
|
|
|
|
|
static string key = "f7ZHpw28izQ1VU_ixoY5";
|
|
|
|
|
static string sign = EncryptString(appid + trans + salt + key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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");
|
|
|
|
|
/*
|
|
|
|
|
private static HttpClient HttpRe = new HttpClient()
|
|
|
|
|
{
|
|
|
|
|
BaseAddress = new Uri("http://api.fanyi.baidu.com/api/trans/vip/translate?"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static async Task GetAsync(HttpClient httpc)
|
|
|
|
|
{
|
|
|
|
|
using HttpResponseMessage response = await httpc.GetAsync(temp);
|
|
|
|
|
|
|
|
|
|
//var value = response.EnsureSuccessStatusCode().WriteRequestToConsole();
|
|
|
|
|
|
|
|
|
|
var jsonResponse = await response.Content.ReadAsStringAsync();//收到json
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"{jsonResponse}\n");
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public static string EncryptString(string str)//百度MD5加密计算方式
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void requestJson()
|
|
|
|
|
{
|
|
|
|
|
string temp = "q=" + HttpUtility.UrlEncode(trans) + "&from" + fl + "&to" + dl + "&appid" + appid + "&salt" + salt + "&sign" + sign;
|
|
|
|
|
//Task t = GetAsync(HttpRe); t.Wait();
|
|
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(https + temp);
|
|
|
|
|
request.Method = "GET";
|
|
|
|
|
request.ContentType = "text/html;charset=UTF-8";
|
|
|
|
|
request.UserAgent = null;
|
|
|
|
|
request.Timeout = 6000;
|
|
|
|
|
|
|
|
|
|
var response = request.GetResponse();
|
|
|
|
|
var myResponseStream = response.GetResponseStream();
|
|
|
|
|
var myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
|
|
|
|
string retString = myStreamReader.ReadToEnd();
|
|
|
|
|
Console.WriteLine(retString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|