@ -14,20 +14,20 @@ using System.Text;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using System.Web ;
using System.Web ;
namespace WpfApp1.translationKey
namespace testRjgc.transToNet
{
{
internal class jsonNet
internal class jsonNet : StrToJson
{
{
static string https = "http://api.fanyi.baidu.com/api/trans/vip/translate?" ;
static string https = "http://api.fanyi.baidu.com/api/trans/vip/translate?" ;
static string appid = "20230925001829663" ; //20230925001829663,20230923001827495
static string appid = "20230925001829663" ; //20230925001829663,20230923001827495
static Random rd = new Random ( ) ;
static Random rd = new Random ( ) ;
static string salt = rd . Next ( 100000 ) . ToString ( ) ;
static string salt = rd . Next ( 100000 ) . ToString ( ) ;
static string key = "f7ZHpw28izQ1VU_ixoY5" ; //f7ZHpw28izQ1VU_ixoY5,yjvMNY33Qc1TYSBjTQYQ
static string key = "f7ZHpw28izQ1VU_ixoY5" ; //f7ZHpw28izQ1VU_ixoY5,yjvMNY33Qc1TYSBjTQYQ
//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");
//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 ( )
private static HttpClient HttpRe = new HttpClient ( )
{
{
@ -45,7 +45,7 @@ namespace WpfApp1.translationKey
Console . WriteLine ( $"{jsonResponse}\n" ) ;
Console . WriteLine ( $"{jsonResponse}\n" ) ;
}
}
* /
* /
public static string EncryptString ( string str ) //百度MD5加密计算方式
public static string EncryptString ( string str ) //百度MD5加密计算方式
{
{
MD5 md5 = MD5 . Create ( ) ;
MD5 md5 = MD5 . Create ( ) ;
@ -63,8 +63,33 @@ namespace WpfApp1.translationKey
// 返回加密的字符串
// 返回加密的字符串
return sb . ToString ( ) ;
return sb . ToString ( ) ;
}
}
public string RequestJsonLanguageChange ( string input , string srcl , string dstl )
public string RequestJsonPrivate ( string input , string srcl , string dstl , string aid , string kkey ) //自定义id, key以及源语言和目标语言
{
string sign = EncryptString ( aid + input + salt + kkey ) ;
string temp = "q=" + HttpUtility . UrlEncode ( input ) + "&from=" + srcl + "&to=" + dstl + "&appid=" + aid + "&salt=" + salt + "&sign=" + sign ;
Console . WriteLine ( https + temp ) ;
//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 ( ) ;
tempC2 temp1 = JsonConvert . DeserializeObject < tempC2 > ( retString ) ;
Trans_result result = temp1 . trans_result [ 0 ] ;
string s = result . dst ;
return s ;
}
public string RequestJsonLanguageChange ( string input , string srcl , string dstl ) //可以自定义源语言与目标语言
{
{
string sign = EncryptString ( appid + input + salt + key ) ;
string sign = EncryptString ( appid + input + salt + key ) ;
@ -89,10 +114,10 @@ namespace WpfApp1.translationKey
return s ;
return s ;
}
}
public string RequestJsonBaiDu ( string input )
public string RequestJsonBaiDu ( string input ) //默认
{
{
string sign = EncryptString ( appid + input + salt + key ) ;
string sign = EncryptString ( appid + input + salt + key ) ;
string temp = "q=" + HttpUtility . UrlEncode ( input ) + "&from=jp&to=zh&appid=" + appid + "&salt=" + salt + "&sign=" + sign ;
string temp = "q=" + HttpUtility . UrlEncode ( input ) + "&from=jp&to=zh&appid=" + appid + "&salt=" + salt + "&sign=" + sign ;
Console . WriteLine ( https + temp ) ;
Console . WriteLine ( https + temp ) ;
//Task t = GetAsync(HttpRe); t.Wait();
//Task t = GetAsync(HttpRe); t.Wait();
@ -112,8 +137,8 @@ namespace WpfApp1.translationKey
Trans_result result = temp1 . trans_result [ 0 ] ;
Trans_result result = temp1 . trans_result [ 0 ] ;
string s = result . dst ;
string s = result . dst ;
return s ;
return s ;
}
}
}
}
public class Trans_result
public class Trans_result