|
@@ -1,4 +1,4 @@
|
|
|
-// 腾讯云语音合成 (TTS) - TextToVoice 轻量 C++ 客户端 实现
|
|
|
|
|
|
|
+// 腾讯云语音合成 (TTS) - TextToVoice 轻量 C++ 客户端 实现
|
|
|
//
|
|
//
|
|
|
// 签名算法:TC3-HMAC-SHA256
|
|
// 签名算法:TC3-HMAC-SHA256
|
|
|
// 参考:https://cloud.tencent.com/document/api/213/30654
|
|
// 参考:https://cloud.tencent.com/document/api/213/30654
|
|
@@ -328,7 +328,18 @@ TtsResult TtsClient::Synthesize(const std::string& text_utf8, const TtsOptions&
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
|
|
if (verify_peer_) {
|
|
if (verify_peer_) {
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
|
|
- if (!ca_file_.empty()) curl_easy_setopt(curl, CURLOPT_CAINFO, ca_file_.c_str());
|
|
|
|
|
|
|
+ if (!ca_file_.empty()) {
|
|
|
|
|
+ curl_easy_setopt(curl, CURLOPT_CAINFO, ca_file_.c_str());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Windows + curl >= 7.71:直接用操作系统自带的证书库。
|
|
|
|
|
+ // 这是最省事也最安全的做法 —— OpenSSL 后端在 Windows 上默认找不到
|
|
|
|
|
+ // OpenSSL 自己目录下的根证书,不设这个就必定报
|
|
|
|
|
+ // "SSL peer certificate or SSH remote key was not OK"。
|
|
|
|
|
+ // 有了它就不用自己下载维护 cacert.pem,安全性也不打折。
|
|
|
|
|
+#if defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x074700
|
|
|
|
|
+ curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, (long)CURLSSLOPT_NATIVE_CA);
|
|
|
|
|
+#endif
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
|
}
|
|
}
|
|
@@ -343,7 +354,22 @@ TtsResult TtsClient::Synthesize(const std::string& text_utf8, const TtsOptions&
|
|
|
last_response_ = response;
|
|
last_response_ = response;
|
|
|
|
|
|
|
|
if (rc != CURLE_OK) {
|
|
if (rc != CURLE_OK) {
|
|
|
- result.error_message = std::string("network error: ") + curl_easy_strerror(rc);
|
|
|
|
|
|
|
+ std::string msg = std::string("network error: ") + curl_easy_strerror(rc);
|
|
|
|
|
+ // 证书校验失败是最常见的配置问题,给出明确的下一步而不是干巴巴的英文
|
|
|
|
|
+ if (rc == CURLE_PEER_FAILED_VERIFICATION) {
|
|
|
|
|
+ msg += "(提示:libcurl 找不到/校验不通过服务端证书。";
|
|
|
|
|
+ if (verify_peer_) {
|
|
|
|
|
+ if (ca_file_.empty()) {
|
|
|
|
|
+ msg += "可下载 https://curl.se/ca/cacert.pem,设环境变量 TTS_CA_FILE;"
|
|
|
|
|
+ "或调 client.SetCaFile();或临时 SetVerifyPeer(false) 跳过校验。)";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ msg += "已设置 CA 文件但仍失败,请确认路径正确、是 PEM 格式且未被防火墙篡改。)";
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ msg += "已禁用证书校验仍失败,问题不在证书,可能是 TLS 1.2 不支持:见 README 9.2。)";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ result.error_message = msg;
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|