JAVA中调用阿里云语音通知Api并接收消息回执
配置文件
需要的包
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dyvmsapi</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.aliyun.mns</groupId>
<artifactId>aliyun-sdk-mns</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dyvmsapi20170525</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>com.meiyuan</groupId>
<artifactId>alicom-mns-receive-sdk-0.0.1-SNAPSHOT</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.meiyuan</groupId>
<artifactId>aliyun-java-sdk-dybaseapi-1.0.0-SNAPSHOT</artifactId>
<version>1.0.0</version>
</dependency>
具体代码及步骤
1.获取配置文件中的参数
package com.meiyuan.reservation.dto.call;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.io.Serializable;
/**
* 功能描述:ali云 语音通知辅助类实体
*
* @author tc
* @version 1.0
* @since 2020/12/15 17:24
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "aliyun")
public class ClientConfigDto implements Serializable {
private static final long serialVersionUID = 7736942314547915021L;
/**
* 您的AccessKey ID
*/
private String accessKeyId;
/**
* 您的AccessKey Secret
*/
private String accessKeySecret;
/**
* 语音文件的语音ID
*/
private String ttsCode;
private String product;
private String domain;
/**
* 主叫号码
*/
private String calledShowNumber;
/**
* 相应产品的消息类型
*/
private String messageType;
/**
* 在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName
*/
private String queueName;
}
2.调用阿里云语音Api,三种不同的呼叫方式,根据需要选择调用
package com.meiyuan.reservation.call;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dyvmsapi.model.v20170525.IvrCallRequest;
import com.aliyuncs.dyvmsapi.model.v20170525.IvrCallResponse;
import com.aliyuncs.dyvmsapi.model.v20170525.SingleCallByTtsRequest;
import com.aliyuncs.dyvmsapi.model.v20170525.SingleCallByTtsResponse;
import com.aliyuncs.dyvmsapi.model.v20170525.SingleCallByVoiceRequest;
import com.aliyuncs.dyvmsapi.model.v20170525.SingleCallByVoiceResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.meiyuan.reservation.dto.call.CallMsgDto;
import com.meiyuan.reservation.dto.call.ClientConfigDto;
import com.meiyuan.reservation.mq.sender.ReservationMqSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 功能描述:ali云 语音通知辅助类
*
* @author tc
* @version 1.0
* @since 2020/12/15 17:17
*/
@Slf4j
@Component
public class VmsDemo {
/**
* 文本转语音外呼
*
* @return
* @throws ClientException
*/
@Autowired
private ReservationMqSender reservationMqSender