pull/1395/head
gedoor 3 years ago
parent ad45a551da
commit f2689285de
  1. 2
      app/src/main/assets/defaultData/httpTTS.json
  2. 6
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  3. 5
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  4. 3
      app/src/main/java/io/legado/app/service/HttpReadAloudService.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 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)", "loginUrl": "var loginInfo = source.getLoginInfoMap();\nvar accessKeyId = loginInfo.get('AccessKeyId');\nvar accessKeySecret = loginInfo.get('AccessKeySecret');\nvar timestamp = java.timeFormatUTC(new Date().getTime(), \"YYYY-MM-dd'T'HH:mm:ss'Z'\", 0);\nvar aly = new JavaImporter(Packages.javax.crypto.Mac, Packages.javax.crypto.spec.SecretKeySpec, Packages.javax.xml.bind.DatatypeConverter, Packages.java.net.URLEncoder, Packages.java.lang.String, Packages.android.util.Base64);\nwith (aly) {\n function percentEncode(value) {\n return URLEncoder.encode(value, \"UTF-8\").replace(\"+\", \"%20\")\n .replace(\"*\", \"%2A\").replace(\"%7E\", \"~\")\n }\n\n function sign(stringToSign, accessKeySecret) {\n var mac = Mac.getInstance('HmacSHA1');\n mac.init(new SecretKeySpec(String(accessKeySecret + '&').getBytes(\"UTF-8\"), \"HmacSHA1\"));\n var signData = mac.doFinal(String(stringToSign).getBytes(\"UTF-8\"));\n var signBase64 = Base64.encodeToString(signData, Base64.NO_WRAP);\n var signUrlEncode = percentEncode(signBase64);\n return signUrlEncode;\n }\n}\nvar query = 'AccessKeyId=' + accessKeyId + '&Action=CreateToken&Format=JSON&RegionId=cn-shanghai&SignatureMethod=HMAC-SHA1&SignatureNonce=' + java.randomUUID() + '&SignatureVersion=1.0&Timestamp=' + percentEncode(timestamp) + '&Version=2019-02-28';\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)\nvar res = JSON.parse(body)\nif (res.ErrMsg != '') {\n throw res.ErrMsg\n}\nvar header = { \"X-NLS-Token\": res.Token.Id };\nsource.putLoginHeader(JSON.stringify(header))",
"loginUi": [ "loginUi": [
{ {
"name": "AccessKeyId", "name": "AccessKeyId",

@ -46,6 +46,12 @@ interface BaseSource : JsExtensions {
} }
} }
fun login() {
getLoginJs()?.let {
evalJS(it)
}
}
/** /**
* 解析header规则 * 解析header规则
*/ */

@ -2,7 +2,9 @@ package io.legado.app.help
import android.net.Uri import android.net.Uri
import android.util.Base64 import android.util.Base64
import android.util.Log
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.BuildConfig
import io.legado.app.constant.AppConst.dateFormat import io.legado.app.constant.AppConst.dateFormat
import io.legado.app.data.entities.BaseSource import io.legado.app.data.entities.BaseSource
import io.legado.app.help.http.* import io.legado.app.help.http.*
@ -478,6 +480,9 @@ interface JsExtensions {
getSource()?.let { getSource()?.let {
Debug.log(it.getKey(), msg) Debug.log(it.getKey(), msg)
} ?: Debug.log(msg) } ?: Debug.log(msg)
if (BuildConfig.DEBUG) {
Log.d("SourceDebugLog", msg)
}
return msg return msg
} }

@ -114,6 +114,9 @@ class HttpReadAloudService : BaseReadAloudService(),
var response = analyzeUrl.getResponse() var response = analyzeUrl.getResponse()
httpTts.loginCheckJs?.let { checkJs -> httpTts.loginCheckJs?.let { checkJs ->
if (checkJs.isNotBlank()) { if (checkJs.isNotBlank()) {
if (response.headers["Content-Type"] != "audio/mpeg") {
response.body!!.string()
}
response = analyzeUrl.evalJS(checkJs, response) as Response response = analyzeUrl.evalJS(checkJs, response) as Response
} }
} }

Loading…
Cancel
Save