From 19ca702fd00dff733adc09c118d79c8dc3933fac Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 10 Oct 2021 23:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/defaultData/httpTTS.json | 2 +- .../book/read/config/SpeakEngineEditDialog.kt | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/defaultData/httpTTS.json b/app/src/main/assets/defaultData/httpTTS.json index 1dd21ac25..39208e64c 100644 --- a/app/src/main/assets/defaultData/httpTTS.json +++ b/app/src/main/assets/defaultData/httpTTS.json @@ -13,7 +13,7 @@ "id": -29, "name": "3.阿里云语音", "url": "https://nls-gateway.cn-shanghai.aliyuncs.com/stream/v1/tts,{\"method\": \"POST\",\"body\", {\"appkey\":\"31f932fb\",\"text\":\"{{speakText}}\",\"format\":\"mp3\"}}", - "loginUrl": "var query = 'AccessKeyId=' + source.loginInfoMap().get('AccessKeyId') + '&Action=CreateToken&Format=JSON&RegionId=cn-shanghai&SignatureMethod=HMAC-SHA1&SignatureNonce=' + java.UUID + '&SignatureVersion=1.0&Timestamp=' + java.timeFormatUTC(new Date().getTime(), 'YYYY-MM-DDThh:mm:ssZ', 0) + '&Version=2019-02-28'; ", + "loginUrl": "var loginInfo = source.getLoginInfoMap();\nvar accessKeyId = loginInfo.get('AccessKeyId');\nvar accessKeySecret = loginInfo.get('AccessKeySecret');\nvar timestamp = java.timeFormatUTC(new Date().getTime(), 'YYYY-MM-DDThh:mm:ssZ', 0);\nvar query = 'AccessKeyId=' + accessKeyId + '&Action=CreateToken&Format=JSON&RegionId=cn-shanghai&SignatureMethod=HMAC-SHA1&SignatureNonce=' + java.randomUUID() + '&SignatureVersion=1.0&Timestamp=' + timestamp + '&Version=2019-02-28';\nvar crypto = new JavaImporter(javax.crypto.Mac, javax.crypto.spec.SecretKeySpec, javax.xml.bind.DatatypeConverter, java.net.URLEncoder);\nwith (crypto) {\n function percentEncode(value) {\n return URLEncoder.encode(value, URL_ENCODING).replace(\"+\", \"%20\")\n .replace(\"*\", \"%2A\").replace(\"%7E\", \"~\")\n }\n\n function sign(stringToSign, accessKeySecret) {\n var mac = Mac.getInstance(ALGORITHM_NAME);\n mac.init(new SecretKeySpec((accessKeySecret + '&').getBytes(\"UTF-8\"), \"HmacSHA1\"));\n var signData = mac.doFinal(stringToSign.getBytes(\"UTF-8\"));\n var signBase64 = DatatypeConverter.printBase64Binary(signData);\n var signUrlEncode = percentEncode(signBase64);\n return signUrlEncode;\n }\n}\nvar signStr = sign('GET&' + percentEncode('/') + '&' + percentEncode(query), accessKeySecret);\nvar queryStringWithSign = \"Signature=\" + signStr + \"&\" + query;\nvar body = java.ajax('http://nls-meta.cn-shanghai.aliyuncs.com/?' + queryStringWithSign)\njava.log(body)", "loginUi": [ { "name": "AccessKeyId", diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineEditDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineEditDialog.kt index 2e69d495e..dd6b43dee 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineEditDialog.kt @@ -12,6 +12,9 @@ import io.legado.app.data.entities.HttpTTS import io.legado.app.databinding.DialogHttpTtsEditBinding import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.login.SourceLoginActivity +import io.legado.app.ui.widget.code.addJsPattern +import io.legado.app.ui.widget.code.addJsonPattern +import io.legado.app.ui.widget.code.addLegadoPattern import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -35,6 +38,23 @@ class SpeakEngineEditDialog() : BaseDialogFragment(R.layout.dialog_http_tts_edit override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { binding.toolBar.setBackgroundColor(primaryColor) + binding.tvUrl.run { + addLegadoPattern() + addJsonPattern() + addJsPattern() + } + binding.tvLoginUrl.run { + addLegadoPattern() + addJsonPattern() + addJsPattern() + } + binding.tvLoginUi.addJsonPattern() + binding.tvLoginCheckJs.addJsPattern() + binding.tvHeaders.run { + addLegadoPattern() + addJsonPattern() + addJsPattern() + } viewModel.initData(arguments) { initView(httpTTS = it) }