以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  請求指導  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=74426)

--  作者:catyin1989
--  发布时间:2015/9/10 16:41:00
--  請求指導
很想寫一個翻譯的功能,但是這些碼看不懂,請求大大幫忙把這些碼轉成 VB 或是 foxtable T^T

https://msdn.microsoft.com/en-us/library/ff512421.aspx

--  作者:大红袍
--  发布时间:2015/9/10 17:15:00
--  

Mark 百度翻译API

 

http://developer.baidu.com/wiki/index.php?title=%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3%E9%A6%96%E9%A1%B5/%E7%99%BE%E5%BA%A6%E7%BF%BB%E8%AF%91/%E7%BF%BB%E8%AF%91API

 

 

Dim text As String = "Use pixels to express measurements for padding and margins."

Dim client_id As String = "hAaa2NLELKdAIfMhMjnuEgi1"
Dim from As String = "auto"
Dim [To] As String = "auto"


Dim ScriptControl As Object, data  As Object, JscriptCode As String
JscriptCode = "function toUrl() {return encodeURI(\'" & text & "\')}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    text = .Run("toUrl")
End With

Dim url As String= "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=" & client_id & "&q=" & text & "&from=" & from & "&to=" & [To]

Dim rqst As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)

Dim rsps As System.Net.HttpWebResponse = rqst.GetResponse

Dim stm As System.IO.Stream = rsps.GetResponseStream()

Dim reader As New System.IO.StreamReader(stm)

Dim str As String = reader.ReadToEnd

rsps.Close
stm.Close
reader.close


JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", str)
End With
output.show(str)
For Each o As object In data.trans_result
    output.show(o.src)
    output.show(o.dst)
Next

 


--  作者:catyin1989
--  发布时间:2015/9/10 17:52:00
--  
超級感謝的!!!!! >^<
--  作者:catyin1989
--  发布时间:2016/2/21 17:42:00
--  
現在百度翻譯的網址好像不同了, 原碼不能用?? 能有新的code可用嗎?? T^T
--  作者:大红袍
--  发布时间:2016/2/21 18:48:00
--  

注册成为百度开发者,然后参考

 

http://api.fanyi.baidu.com/api/trans/product/apidoc

 

MD5加密参考

 

msgbox(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("加密内容", "MD5"))

 

随机数参考

 

http://www.foxtable.com/help/topics/0349.htm

 

 


--  作者:catyin1989
--  发布时间:2016/2/21 19:11:00
--  
必須用大陸的手機碼注冊.... 
--  作者:大红袍
--  发布时间:2016/2/21 22:16:00
--  

如下代码,appid和key最好还是你自己注册一个

 

Dim q As String = "Use pixels to express measurements for padding and margins."
Dim from As String = "en"
Dim [To] As String = "zh"
Dim appid As String = "20160221000012908"
Dim salt As String = Rand.Next(1000000000)
Dim key As String =  "4aopMWtb_LTkwYNSJToE"

Dim text As String = appid & q & salt & key
Dim sign As String = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text, "MD5")
sign = sign.ToLower

Dim ScriptControl As Object, data  As Object, JscriptCode As String
JscriptCode = "function toUrl() {return encodeURI(\'" & q & "\')}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    text = .Run("toUrl")
End With

Dim url As String= "http://api.fanyi.baidu.com/api/trans/vip/translate?q=" & text & "&from=" & from & "&to=" & [To] & "&appid=" & appid & "&salt=" & salt & "&sign=" & sign

Dim rqst As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)

Dim rsps As System.Net.HttpWebResponse = rqst.GetResponse

Dim stm As System.IO.Stream = rsps.GetResponseStream()

Dim reader As New System.IO.StreamReader(stm)

Dim str As String = reader.ReadToEnd

rsps.Close
stm.Close
reader.close


JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", str)
End With
output.show(str)
For Each o As object In data.trans_result
    output.show(o.src)
    output.show(o.dst)
Next


--  作者:catyin1989
--  发布时间:2016/2/22 14:57:00
--  
Dim sign As String = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text, "MD5")
這句出 error, 說 security is not a member of web, 應如何更改??



--  作者:大红袍
--  发布时间:2016/2/22 14:58:00
--  

 添加引用那里,填入 System.Web.Dll

 

http://www.foxtable.com/help/topics/1936.htm