|
@@ -1,4 +1,5 @@
|
|
|
package com.care.common.util;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.tencentcloudapi.common.Credential;
|
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
|
|
@@ -62,7 +63,7 @@ public class VoiceUtil {
|
|
|
clientProfile.setHttpProfile(httpProfile);
|
|
|
/* 实例化要请求产品(以vms为例)的client对象
|
|
|
* 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,或者引用预设的常量 */
|
|
|
- VmsClient client = new VmsClient(cred, region, clientProfile);
|
|
|
+ VmsClient client = new VmsClient(cred, region);
|
|
|
/* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数
|
|
|
* 您可以直接查询SDK源码确定接口有哪些属性可以设置
|
|
|
* 属性可能是基本类型,也可能引用了另一个数据结构
|
|
@@ -84,6 +85,11 @@ public class VoiceUtil {
|
|
|
|
|
|
/* 被叫手机号码,采用 e.164 标准,格式为+[国家或地区码][用户号码]
|
|
|
* 例如:+8613711112222,其中前面有一个+号,86为国家码,13711112222为手机号 */
|
|
|
+ if (phoneNumber.startsWith("+86")){
|
|
|
+ //phoneNumber = phoneNumber.replace("+86","");
|
|
|
+ }else{
|
|
|
+ phoneNumber = "+86"+phoneNumber;
|
|
|
+ }
|
|
|
req.setCalledNumber(phoneNumber);
|
|
|
|
|
|
// 在 [语音控制台] 添加应用后生成的实际SdkAppid,示例如1400006666
|
|
@@ -113,6 +119,53 @@ public class VoiceUtil {
|
|
|
}
|
|
|
}
|
|
|
public static void main(String[] args) {
|
|
|
+ String endpoint ="vms.tencentcloudapi.com";
|
|
|
+ String region="ap-beijing";
|
|
|
+ String secretId="AKIDkKfkbCX0HJ4YkgMlunPkpdBSVHo43mEQ";
|
|
|
+ String secretKey="wb08zZrRkmY3IGyPZS4PUIp66pHUQ6Vd";
|
|
|
+ String voiceSdkAppId="1400591555";
|
|
|
+ String templateId="1182623";
|
|
|
+ String phoneNumber="18010375763";
|
|
|
+ String[] templateParam = {"yyyy年MM月dd日HH时mm分ss秒","久滞","双华时代"};
|
|
|
+ SendStatus sendStatus = VoiceUtil.sendTtsVoice( endpoint,
|
|
|
+ region,
|
|
|
+ secretId,
|
|
|
+ secretKey,
|
|
|
+ voiceSdkAppId,
|
|
|
+ templateId,
|
|
|
+ phoneNumber,
|
|
|
+ templateParam);
|
|
|
+ System.out.println(JSONUtil.toJsonStr(sendStatus));
|
|
|
+
|
|
|
+
|
|
|
+ try{
|
|
|
+ // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
|
|
+ // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
+ Credential cred = new Credential(secretId, secretKey);
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("vms.tencentcloudapi.com");
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ VmsClient client = new VmsClient(cred, "ap-beijing", clientProfile);
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ SendTtsVoiceRequest req = new SendTtsVoiceRequest();
|
|
|
+ req.setTemplateId("1182623");
|
|
|
|
|
|
+ String[] templateParamSet1 = {"1", "2", "3"};
|
|
|
+ req.setTemplateParamSet(templateParamSet1);
|
|
|
+
|
|
|
+ req.setCalledNumber("+8618010375763");
|
|
|
+ req.setPlayTimes(1L);
|
|
|
+ req.setVoiceSdkAppid("1400591555");
|
|
|
+ // 返回的resp是一个SendTtsVoiceResponse的实例,与请求对象对应
|
|
|
+ SendTtsVoiceResponse resp = client.SendTtsVoice(req);
|
|
|
+ // 输出json格式的字符串回包
|
|
|
+ System.out.println(SendTtsVoiceResponse.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
}
|
|
|
}
|