@ -14,9 +14,9 @@ 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?" ;
@ -64,7 +64,32 @@ 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,7 +114,7 @@ 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 ) ;