From 1d21886b1445bb37f1a0e2d2e750dc63da614080 Mon Sep 17 00:00:00 2001 From: Chen Junkai <52616111@qq.com> Date: Sun, 22 Oct 2023 15:56:18 +0800 Subject: [PATCH] update: youdao free api is no longer supported --- CapsLock+.ahk | 2 +- language/English.ahk | 32 ++++++++++++++++++-------------- language/Simplified_Chinese.ahk | 28 ++++++++++++++++------------ lib/lib_ydTrans.ahk | 21 ++++++++++++--------- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/CapsLock+.ahk b/CapsLock+.ahk index 6967088..eeef1f2 100644 --- a/CapsLock+.ahk +++ b/CapsLock+.ahk @@ -23,7 +23,7 @@ Menu, Tray, Icon,,, 1 SetStoreCapslockMode, Off -global CLversion:="Version: 3.2.0.0 | 2020-10-24`n`nCopyright Junkai Chen" +global CLversion:="Version: 3.3.0.0 | 2023-10-22`n`nCopyright Junkai Chen" global cClipboardAll ;capslock+ clipboard global caClipboardAll ;capslock+alt clipboard diff --git a/language/English.ahk b/language/English.ahk index 5d13a15..2686a08 100644 --- a/language/English.ahk +++ b/language/English.ahk @@ -26,6 +26,7 @@ global lang_yd_errorNoFunds:="Insufficient account balance" global lang_yd_trans:= "------------------------------ Youdao Translation -----------------------------" global lang_yd_dict:= "------------------------------ Youdao dictionary ------------------------------" global lang_yd_phrase:= "----------------------------------- Phrase ------------------------------------" +global lang_yd_free_key_unavailable_warning:="Youdao Translate no longer provides free translation API, now you can only use the paid API (new accounts have a trial amount), please refer to the instructions in the [TTranslate] section of the CapsLock+settingsDemo.ini file to set up the key and use the translation function." global lang_settingsFileContent:="" lang_settingsFileContent= @@ -282,24 +283,27 @@ progressColor=0x00cc99 [TTranslate] ; About Youdao API ; The translation function is implemented by calling Youdao API. -; The request frequency of the API is limited to 1000 times per hour, In other words, all the people who are using -; Capslock+ translation can not translate more than 1000 times in one hour. -; Youdao API website: http://fanyi.youdao.com/openapi -; paid version website: https://ai.youdao.com/console/#/ -; The key of Youdao API. Leave blank to use the built-in key, shared by all users. -apiKey=0123456789 +; Youdao's paid version API website: https://ai.youdao.com/console/#/ +; Getting started docs about Youdao's API: https://ai.youdao.com/doc.s#guide -; API key type, 0 is the free version, 1 is the paid version. The free version of the key can be applied through the -; above URL. -apiType=0 +; Translation API type, currently can only be 1 +; 0: Free version of Youdao API (no longer available, no longer provided by Youdao) +; 1: Paid version of Youdao API (default value) +apiType=1 -; The "keyfrom" parameter of the API key -keyFrom=xxx +; Parameters for paid version Youdao application -; The key of paid Youdao API. -appPaidID=0123456789 -appPaidKey=0123456789 +; Application ID +appPaidID=xxx + +; Application key +appPaidKey=xxx + +; Capslock+ could use either the free version or the paid version of the Yodao API before, to provide translation functions, now Yodao no longer provides the free version of the API, +; only the paid version of the API can be used. The following parameters related to the free version of the API have been deprecated, please delete them if they are used in your settings file. +; apiKey=xxx +; keyFrom=xxx ;----------------------------------------------------------------; diff --git a/language/Simplified_Chinese.ahk b/language/Simplified_Chinese.ahk index 2beda79..674b2b6 100644 --- a/language/Simplified_Chinese.ahk +++ b/language/Simplified_Chinese.ahk @@ -26,6 +26,7 @@ global lang_yd_errorNoFunds:="帐户余额不足" global lang_yd_trans:="------------------------------------有道翻译------------------------------------" global lang_yd_dict:="------------------------------------有道词典------------------------------------" global lang_yd_phrase:="--------------------------------------短语--------------------------------------" +global lang_yd_free_key_unavailable_warning:="有道翻译已经不再提供免费的翻译 API,现在只能使用收费 API(新账号有试用额度),请参考 CapsLock+settingsDemo.ini 文件中 [TTranslate] 部分的说明设置密钥后使用翻译功能。" global lang_settingsFileContent:="" lang_settingsFileContent= @@ -257,24 +258,27 @@ progressColor=0x00cc99 [TTranslate] ;有道api接口 ;翻译功能通过调用有道的api实现。 -;接口的请求频率限制为每小时1000次,超过限制会被封禁。也就是说所有使用Capslock+翻译的人一小时内翻译的次数加起来不能超过1000次。 -;有道api网址:http://fanyi.youdao.com/openapi + ;收费版api申请网址: https://ai.youdao.com/console/#/ +;有道翻译 API 入门指南: https://ai.youdao.com/doc.s#guide -;有道api的key,如果自己申请到key,可以填入,这样就不用和其他人共用api接口,留空则使用自带的key,所有人共用 -;注意如果是免费版的key,apiType也要相应设置为0,收费版的填写1 -apiKey=0123456789 +;翻译 API 类型,目前只能为 1 +;0: 免费版有道 API(已不可使用,有道翻译不再提供) +;1: 收费版有道 API(默认值) +apiType=1 -;接口类型,0为免费版,1为收费版。通过上面的网址申请的是免费版的,收费版是需要 email 他们来申请的。 -apiType=0 +;收费版申请的参数 -;免费版的有道 api key 的 keyfrom 参数,申请 api 时要求填写的。收费版的不需要填写。 -keyFrom=xxx +;应用ID +appPaidID=xxx -;收费版申请的key -appPaidID=0123456789 -appPaidKey=0123456789 +;应用密钥 +appPaidKey=xxx +;曾经 Capslock+ 可以选择使用免费版或收费版的有道 API 来提供翻译功能,现在有道已经不再提供免费版 API, +;只能使用收费版的 API,以下与免费版 API 相关的参数已经废弃,如果你的设置文件中有使用,请删除掉。 +;apiKey=xxx +;keyFrom=xxx ;----------------------------------------------------------------; diff --git a/lib/lib_ydTrans.ahk b/lib/lib_ydTrans.ahk index 4f87a29..f9a7274 100644 --- a/lib/lib_ydTrans.ahk +++ b/lib/lib_ydTrans.ahk @@ -16,15 +16,11 @@ youdaoApiKey0=12763084 global appID="" global appKey="" -; 收费版改版 -; free key -if(CLSets.TTranslate.apiType=1) +; 收费版 API +if (CLSets.TTranslate.appPaidID != "" && CLSets.TTranslate.appPaidID != "") { - if (CLSets.TTranslate.appPaidID != "" && CLSets.TTranslate.appPaidID != "") - { - appID:=CLSets.TTranslate.appPaidID - appKey:=CLSets.TTranslate.appPaidKey - } + appID:=CLSets.TTranslate.appPaidID + appKey:=CLSets.TTranslate.appPaidKey youdaoApiString=http://openapi.youdao.com/api?signType=v3&from=auto&to=auto&appKey=%appID% } else @@ -48,6 +44,11 @@ return ydTranslate(ss) { +if(CLSets.TTranslate.apiType = 0 || CLSets.TTranslate.appPaidID = "") +{ + MsgBox, %lang_yd_free_key_unavailable_warning% + return +} transStart: ; if(StrLen(ss) >= 2000) ; { @@ -112,7 +113,9 @@ if(youdaoApiString="") goto, setTransText } -if (CLSets.TTranslate.apiType=1) { +; 目前 apiType 只可能为 1,暂时保留对 apiType 的判断结构,以防以后需要添加其他 api 类型的支持 +; youdao api docs: https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html +if (true || CLSets.TTranslate.apiType=1) { ; salt sign curtime ; sign=sha256(应用ID+input+salt+curtime+应用密钥) myNow := A_NowUTC