pull/1395/head
gedoor 3 years ago
parent 6f5ce967b0
commit 19ca702fd0
  1. 2
      app/src/main/assets/defaultData/httpTTS.json
  2. 20
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineEditDialog.kt

@ -13,7 +13,7 @@
"id": -29, "id": -29,
"name": "3.阿里云语音", "name": "3.阿里云语音",
"url": "https://nls-gateway.cn-shanghai.aliyuncs.com/stream/v1/tts,{\"method\": \"POST\",\"body\", {\"appkey\":\"31f932fb\",\"text\":\"{{speakText}}\",\"format\":\"mp3\"}}", "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": [ "loginUi": [
{ {
"name": "AccessKeyId", "name": "AccessKeyId",

@ -12,6 +12,9 @@ import io.legado.app.data.entities.HttpTTS
import io.legado.app.databinding.DialogHttpTtsEditBinding import io.legado.app.databinding.DialogHttpTtsEditBinding
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.login.SourceLoginActivity 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.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding 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?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) 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) { viewModel.initData(arguments) {
initView(httpTTS = it) initView(httpTTS = it)
} }

Loading…
Cancel
Save