腾讯会议API接入

最近项目需要对接腾讯会议,所以提前预研一下腾讯会议的API的接入方式。

一、     产品购买

进入页面https://meeting.tencent.com/buy.html(腾讯云会议购买页面)

腾讯云会议分为:个人版、商业版、企业版。这里介绍企业版的接入。

如果需要云会议室,可以同时购买腾讯会议 Rooms。如想了解详情请联系腾讯会议客户平台。

 

二、     个人中心配置

1、获取腾讯会议sdk配置

进入页面:https://meeting.tencent.com使用购买腾讯会议服务时使用的手机号进行登录操作。

1)      进入个人中心

2)      进入REST API页面

3)      点击添加应用

4)      应用状态改为已启用

5)      添加完成后会生成对应的:AppID SDKIDSecretIDSecretKey

 

2、腾讯会议室及Rooms配置

Romms下载地址:https://meeting.tencent.com/download-rooms-page.html

【前提】购买了Rooms付费账号

1)      进入个人中心

2)      点击会议室管理(会议室)

3)      添加会议室并将预定状态修改为(开放预定)

4)      在会议平板上安装rooms客户端

 

三、代码接入

 1、授权、鉴权(鉴权的方式有两种:企业自建应用鉴权(JWT)、第三方应用鉴权(OAuth2.0)),这里只介绍企业自建应用鉴权(JWT)。

腾讯接口调用请求头签名生成工具:
import lombok.extern.slf4j.Slf4j;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author dongliang7
 * 
 * @ClassName SignUtil.java
 * @description: 腾讯接口调用请求头签名生成工具
 * @createTime 2021年11月19日 08:45:00
 */
@Slf4j
public class SignUtil {

    static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    static final Charset UTF_8 = StandardCharsets.UTF_8;

    public static String bytesToHex(byte[] bytes) {

        char[] buf = new char[bytes.length * 2];
        int index = 0;
        for (byte b : bytes) {
            buf[index++] = HEX_CHAR[b >>> 4 & 0xf];
            buf[index++] = HEX_CHAR[b & 0xf];
        }

        return new String(buf);
    }

    /**
     * 获取签名
     * @param signVo 签名实体类
     * @return
     */
    public static String getSign(SignVo signVo) {
        try {
            String contentCharset = "UTF-8";
            String hmacAlgorithm = "HmacSHA256";
            String tobeSig = signVo.getMethod() + "\nX-TC-Key=" + signVo.getSecretId() + "&X-TC-Nonce="
                    +  signVo.getNonce() + "&X-TC-Timestamp=" + signVo.getTimestamp() + "\n"
                    + signVo.getUri() + "\n" + signVo.getBody();
            Mac mac = Mac.getInstance(hmacAlgorithm);
            byte[] hash;
            SecretKeySpec spec = new SecretKeySpec(signVo.getSecretKey().getBytes(UTF_8), mac.getAlgorithm());
            mac.init(spec);
            hash = mac.doFinal(tobeSig.getBytes(contentCharset));
            String hexHash = bytesToHex(hash);
            log.info("hexHash -> " + hexHash);
            String sig = new String(Base64.getEncoder().encode(hexHash.getBytes(contentCharset)));
            log.info("sig -> " + sig);
            return sig;
        } catch (Exception e) {
            log.info("ERROR OCCURED");
            throw new RuntimeException(e.getCause());
        }
    }
}

请求头参数封装工具类:

import org.springframework.http.HttpMethod;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Random;

/**
 * @author dongliang7
 * 
 * @ClassName RequestHeaderUtil.java
 * @description: 请求头参数封装工具类
 * @createTime 2021年11月19日 13:44:00
 */
public class RequestHeaderUtil {

    //获取数据库加载的 腾讯会议静态配置
    public static TencentSdkConfig sdkConfig =  TenCentSdkConfig.tencentSdkConfig;
    /**
     * 组建 header
     * @param body 请求体
     * @param httpMethod 请求方法 GET POST .....
     * @param uri 请求路径
     * @return 返回请求头
     */
    public static HeadVo getHeader(String body, HttpMethod httpMethod, String uri) {
        // 1、随机正整数字符串
        String randomStr = String.valueOf(new Random().nextInt(999999));
        // 2、获取时间戳字符串
        long seconds = LocalDateTime.now().atZone(ZoneId.systemDefault()).toEpochSecond();
        String dateTimeStr = String.valueOf(seconds);
        //3、构建签名对象
        if(null == sdkConfig){
            return null;
        }
        SignVo signVo = SignVo.Builder.create().withNonce(randomStr).withSecretId(sdkConfig.getSecretId())
                .withTimestamp(dateTimeStr).withSecretKey(sdkConfig.getSecretKey())
                .withBody(body).withMethod(httpMethod.name()).withUri(uri).build();
        //4、获取签名字符串
        String sign = SignUtil.getSign(signVo);
        HeadVo headVo = HeadVo.Builder.create().withNonce(signVo.getNonce()).withTimestamp(signVo.getTimestamp())
                .withAppId(sdkConfig.getAppId()).withSdkId(sdkConfig.getSdkId()).withKey(sdkConfig.getSecretId())
                .withSignature(sign).withRegistered("1").build();
        return headVo;
    }
}

请求方法及参数封装:

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpMethod; import java.util.Map; /** * @author dongliang7 * * @ClassName TencentMeetingProcess.java * @description: 请求方法及参数封装 * @createTime 2021年11月22日 14:39:00 */ @Slf4j public class TencentMeetingProcess { /** * POST 请求封装 * @param uri 请求路径 * @param requestBody 请求体 * @param <T> * @return 返回接口调用结果 */ public static<T> HttpResponse postProcess(String uri , T requestBody){ String url = Constant.HOST.concat(uri); String body = JSON.toJSONString(requestBody); HeadVo header = RequestHeaderUtil.getHeader(body, HttpMethod.POST, uri); Map<String, String> headMap = fromHeadVo(header); log.info("tencentMeeting the http post url ---" + url); log.info("request tencentMeeting header --->" + JSON.toJSONString(headMap)); HttpResponse httpResponse = OKHttpClient.httpPostJson(url, headMap, body); return httpResponse; } /** * PUT 请求封装 * @param uri 请求路径 * @param requestBody 请求体 * @param <T> * @return 返回接口调用结果 */ public static<T> HttpResponse putProcess(String uri ,T requestBody){ String url = Constant.HOST.concat(uri); String body = JSON.toJSONString(requestBody); HeadVo header = RequestHeaderUtil.getHeader(body, HttpMethod.PUT, uri); Map<String, String> headMap = fromHeadVo(header); log.info("tencentMeeting the http put url ---" + url); log.info("request tencentMeeting header --->" + JSON.toJSONString(headMap)); HttpResponse httpResponse = OKHttpClient.httpPutJson(url, headMap, body); return httpResponse; } /** * GET 请求封装 * @param uri 请求路径 * @return 返回接口调用结果 */ public static HttpResponse getProcess(String uri){ String url = Constant.HOST.concat(uri); HeadVo header = RequestHeaderUtil.getHeader(Constant.NULL_CHAR_STR, HttpMethod.GET, uri); Map<String, String> headMap = fromHeadVo(header); log.info("tencentMeeting the http get url ---" + url); log.info("request tencentMeeting header --->" + JSON.toJSONString(headMap)); HttpResponse httpResponse = OKHttpClient.httpGet(url, headMap); return httpResponse; } /** * DELETE 请求封装 * @param uri 请求路径 * @return 返回接口调用结果 */ public static HttpResponse deleteProcess(String uri){ String url = Constant.HOST.concat(uri); HeadVo header = RequestHeaderUtil.getHeader(Constant.NULL_CHAR_STR, HttpMethod.DELETE, uri); Map<String, String> headMap = fromHeadVo(header); log.info("tencentMeeting the http delete url ---" + url); log.info("request tencentMeeting header --->" + JSON.toJSONString(headMap)); HttpResponse httpResponse = OKHttpClient.httpDelete(url, headMap); return httpResponse; } /** * 将实体类转换成Map集合 * @param headVo 请求head公参实体 * @return 返回map集合 */ public static Map<String, String> fromHeadVo(HeadVo headVo) { return JSON.parseObject(JSON.toJSONString(headVo), new TypeReference<Map<String, String>>() {}); } }

OkHttpClient封装三方接口调用工具:

/**
 * @author dongliang7
 * 
 * @ClassName OKHttpClient.java
 * @description: OkHttpClient封装三方接口调用工具
 * @createTime 2021年11月19日 10:05:00
 */
public class OKHttpClient {

    private static final Logger log = LoggerFactory.getLogger(OKHttpClient.class);

    private static final String JSON_CHARSET_UTF_8 = "application/json; charset=utf-8";
    //创建 OkHttpClient 不进行SSL(证书)验证
    private static final OkHttpClient okHttpClient = SSLSocketClient.getUnsafeOkHttpClient();


    /**
     * Http GET 请求 不带请求头
     * @param url 请求路径
     * @return 返回请求结果
     */
    public static HttpResponse httpGet(String url) {
        if(StringUtils.isBlank(url)){
            log.error("http GET 请求过程中url为null!");
            return new HttpResponse();
        }
        Request.Builder builder = new Request.Builder();
        Request request = builder.get().url(url).build();
        HttpResponse httpResponse = new HttpResponse();
        try {
            Response response = okHttpClient.newCall(request).execute();
            ResponseBody responseBody = response.body();
            httpResponse.setResponseBody(responseBody.string());
            httpResponse.setResponseCode(response.code());
            if (response.code() == 200) {
                log.info("http GET 请求成功; [url={}]", url);
            } else {
                log.warn("Http GET 请求失败; [errorCode = {} , url={}]," +
                        "responseBody={}]", response.code(), url, httpResponse.getResponseBody());
            }
        } catch (IOException e) {
            throw new RuntimeException("同步http GET 请求失败,url:" + url, e);
        }
        return httpResponse;
    }

    /**
     * Http GET 请求 带请求头
     * @param url 请求路径
     * @param headers 请求头
     * @return 返回请求结果
     */
    public static HttpResponse httpGet(String url, Map<String, String> headers) {
        if (CollectionUtils.isEmpty(headers)) {
            return httpGet(url);
        }
        Request.Builder builder = new Request.Builder();
        headers.forEach(builder::header);
        Request request = builder.get().url(url).build();
        HttpResponse httpResponse = new HttpResponse();
        try {
            Response response = okHttpClient.newCall(request).execute();
            ResponseBody responseBody = response.body();
            httpResponse.setResponseBody(responseBody.string());
            httpResponse.setResponseCode(response.code());
            if (response.code() == 200) {
                log.info("Http GET 请求成功; [url={},responseBody={}]", url, httpResponse.getResponseBody());
            } else {
                log.warn("Http GET 请求失败; [errorCode = {} , url={}, " +
                        "responseBody={}]", response.code(), url, httpResponse.getResponseBody());
            }
        } catch (IOException e) {
            throw new RuntimeException("同步http GET 请求失败,url:" + url, e);
        }
        return httpResponse;
    }

    /**
     * Http POST请求 不带请求头
     * @param url  请求路径
     * @param json 请求体 body
     * @return 返回请求结果
     */
    public static HttpResponse httpPostJson(String url, String json) {
        if(StringUtils.isBlank(url)){
            log.error("Http POST 请求过程中url为null!");
            return new HttpResponse();
        }
        MediaType mediaType = MediaType.parse(JSON_CHARSET_UTF_8);
        RequestBody body = RequestBody.create(json,  mediaType);
        Request.Builder requestBuilder = new Request.Builder().url(url);
        Request request = requestBuilder.post(body).build();
        HttpResponse httpResponse = new HttpResponse();
        try {
            Response response = okHttpClient.newCall(request).execute();
            ResponseBody responseBody = response.body();
            httpResponse.setResponseBody(responseBody.string());
            httpResponse.setResponseCode(response.code());
            if (response.code() == 200) {
                log.info("Http POST 请求成功; [url={}, requestContent={}]", url, json);
            } else {
                log.warn("Http POST 请求失败; [ errorCode = {}, url={}, " +
                        "param={}]", response.code(), url, json);
            }
        } catch (IOException e) {
            throw new RuntimeException("同步http请求失败,url:" + url, e);
        }
        return httpResponse;
    }

    /**
     * HTTP POST请求 带请求头
     * @param url 请求路径
     * @param headers 请求头
     * @param json 请求体 body
     * @return 返回请求结果
     */
    public static HttpResponse httpPostJson(String url, Map<String, String> headers, String json) {
        //校验是否需要请求头 , 如果需要直接执行 , 如果不需要则调用
        if (CollectionUtils.isEmpty(headers)) {
            return httpPostJson(url, json);
        }
        MediaType mediaType = MediaType.parse(JSON_CHARSET_UTF_8);
        RequestBody body = RequestBody.create(json,mediaType);
        Request.Builder requestBuilder = new Request.Builder().url(url);
        headers.forEach(requestBuilder::addHeader);
        Request request = requestBuilder.post(body).build();
        HttpResponse httpResponse = new HttpResponse();
        try {
            Response response = okHttpClient.newCall(request).execute();
            ResponseBody responseBody = response.body();
            httpResponse.setResponseBody(responseBody.string());
            httpResponse.setResponseCode(response.code());
            if (response.code() == 200) {
                log.info("Http POST 请求成功; [url={},responseBody={}]", url, httpResponse.getResponseBody());
            } else {
                log.warn("Http POST 请求失败 ; [ errorCode = {}, url={},"
                        + " param={},responseBody ={}]", response.code(), url, json, httpResponse.getResponseBody());
            }
        } catch (IOException e) {
            throw new RuntimeException("同步http POST 请求失败,url:" + url, e);
        }
        return httpResponse;
    }


    /**
     *  HTTP PUT 请求 带请求头
     * @param url 请求路径
     * @param headers 请求头
     * @param json 请求体
     * @return 返回 put 请求响应体
     */
    public static HttpResponse httpPutJson(String url, Map<String, String> headers, String json) {
        MediaType mediaType = MediaType.parse(JSON_CHARSET_UTF_8);
        RequestBody body = RequestBody.create(json,mediaType);
        Request.Builder requestBuilder = new Request.Builder().url(url);
        headers.forEach(requestBuilder::addHeader);
        Request request = requestBuilder.put(body).build();
        HttpResponse httpResponse = new HttpResponse();
        try {
            Response response = okHttpClient.newCall(request).execute();
            ResponseBody responseBody = response.body();
            httpResponse.setResponseBody(responseBody.string());
            httpResponse.setResponseCode(response.code());
            if (response.code() == 200) {
                log.info("Http PUT 请求成功; [url={},responseBody={}]", url, httpResponse.getResponseBody());
            } else {
                log.warn("Http PUT 请求失败 ; [ errorCode = {}, url={}," + " param={},responseBody ={}]", response.code(), url, json, httpResponse.getResponseBody());
            }
        } catch (IOException e) {
            throw new RuntimeException("同步http PUT 请求失败,url:" + url, e);
        }
        return httpResponse;
    }



    /**
     * Http DELETE 请求 带请求头
     * @param url 请求路径
     * @param headers 请求头
     * @return 返回请求结果
     */
    public static HttpResponse httpDelete(String url, Map<String, String> headers) {
        Request.Builder builder = new Request.Builder();
        headers.forEach(builder::header);
        Request request = builder.delete().url(url).build();
        HttpResponse httpResponse = new HttpResponse();
        try {
            Response response = okHttpClient.newCall(request).execute();
            ResponseBody responseBody = response.body();
            httpResponse.setResponseBody(responseBody.string());
            httpResponse.setResponseCode(response.code());
            if (response.code() == 200) {
                log.info("Http DELETE 请求成功; [url={},responseBody={}]", url, httpResponse.getResponseBody());
            } else {
                log.warn("Http DELETE 请求失败; [errorCode = {} , url={}, " + "responseBody={}]", response.code(), url, httpResponse.getResponseBody());
            }
        } catch (IOException e) {
            throw new RuntimeException("同步http DELETE 请求失败,url:" + url, e);
        }
        return httpResponse;
    }
}

创建 OkHttpClient 不进行SSL(证书)验证:

import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;

import javax.net.ssl.*;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * @author dongliang7
 * 
 * @ClassName SSLSocketClient.java
 * @description: 创建 OkHttpClient 不进行SSL(证书)验证
 * @createTime 2021年11月19日 09:50:00
 */
@Slf4j
public class SSLSocketClient {

    public static OkHttpClient getUnsafeOkHttpClient() {
        try {
            // 创建不验证证书链的信任管理器
            final TrustManager[] trustAllCerts = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {}
                    @Override
                    public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {}
                    @Override
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return new java.security.cert.X509Certificate[]{};
                    }
                }
            };
            if (trustAllCerts.length != 1 || !(trustAllCerts[0] instanceof X509TrustManager)) {
                throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustAllCerts));
            }
            X509TrustManager x509TrustManager = (X509TrustManager) trustAllCerts[0];

            // 安装全信任信任管理器
            final SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
            // 使用我们完全信任的管理器创建 ssl 套接字工厂
            final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

            OkHttpClient.Builder builder = new OkHttpClient.Builder()
                    .connectTimeout(60 , TimeUnit.SECONDS).readTimeout(60 , TimeUnit.SECONDS).writeTimeout(120 , TimeUnit.SECONDS);
            builder.sslSocketFactory(sslSocketFactory , x509TrustManager);
            builder.hostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
            OkHttpClient okHttpClient = builder.build();
            return okHttpClient;
        } catch (Exception e) {
            log.error("创建OkHttpClient不进行SSL(证书)验证失败:{}", e.getMessage());
            throw new RuntimeException(e);
        }
    }
}

腾讯会议API调用 会议管理业务处理层:

/**
 * @author dongliang7
 * 
 * @ClassName MeetingsServiceImpl.java
 * @description: 腾讯会议API调用  会议管理业务处理层
 * @createTime 2021年11月24日 09:51:00
 */
@Service
@Slf4j
public class MeetingsApi {
    private final String baseUri = "/v1/meetings";

    /**
     * 创建会议
     *
     * @param createMeetingReqVo
     * @return
     */
    public HttpResponse scheduleMeeting(CreateMeetingReqVo createMeetingReqVo) {
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(baseUri, createMeetingReqVo);
        return httpResponse;
    }

    /**
     * 通过 meetingId 查询会议
     *
     * @param queryMeetingByIdRegVo
     * @return
     */
    public HttpResponse queryMeetingInfo(QueryMeetingByIdRegVo queryMeetingByIdRegVo) {
        String uri = baseUri.concat("/").concat(queryMeetingByIdRegVo.getMeetingId()).concat("?userid=")
                .concat(queryMeetingByIdRegVo.getUserId()).concat("&instanceid=")
                .concat(String.valueOf(queryMeetingByIdRegVo.getInstanceId()));
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return httpResponse;
    }

    /**
     * 取消会议
     *
     * @param cancelMeetingReqVo
     * @return
     */
    public HttpResponse cancelMeeting(CancelMeetingReqVo cancelMeetingReqVo) {
        String uri = baseUri.concat("/").concat(cancelMeetingReqVo.getMeetingId()).concat("/").concat("cancel");
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, cancelMeetingReqVo);
        return httpResponse;
    }

    /**
     * 修改会议
     *
     * @param createMeetingReqVo
     * @return
     */
    public HttpResponse editMeeting(CreateMeetingReqVo createMeetingReqVo, String meetingId) {
        String uri = baseUri.concat("/").concat(meetingId);
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, createMeetingReqVo);
        return httpResponse;
    }

    /**
     * 查询会议列表
     *
     * @param queryMeetingInfoListVo
     * @return
     */
    public QueryMeetingInfoResVo queryMeetingInfoList(QueryMeetingInfoListVo queryMeetingInfoListVo) {
        String uri = baseUri.concat("?").concat("userid=").concat(queryMeetingInfoListVo.getUserId())
                .concat("&instanceid=").concat(String.valueOf(queryMeetingInfoListVo.getInstanceId()));
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return JSON.parseObject(httpResponse.getResponseBody().toString(), QueryMeetingInfoResVo.class);
    }

    /**
     * 查询参会人员
     * @param reqVo
     * @return
     */
    public QueryMeetingParticipantsResVo queryMeetingParticipants(QueryMeetingParticipantsReqVo reqVo) {
        String uri = baseUri.concat("/").concat(reqVo.getMeetingId()).concat("/participants?userid=").concat(reqVo.getUserId());
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return JSON.parseObject(httpResponse.getResponseBody().toString(), QueryMeetingParticipantsResVo.class);
    }

    /**
     * 设置会议邀请成员
     * @param meetingInviteesVo
     * @return
     */
    public String setUpMeetingInvitees(MeetingInviteesVo meetingInviteesVo) {
        //https://api.meeting.qq.com/v1/meetings/{meeting_id}/invitees
        String uri = baseUri.concat("/").concat(meetingInviteesVo.getMeetingId()).concat("/invitees");
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, meetingInviteesVo);
        return httpResponse.getResponseCode().toString();
    }
}

腾讯会议API调用 会议室业务处理层:

/**
 * @author dongliang7
 * 
 * @ClassName RoomsServiceImpl.java
 * @description:  腾讯会议API调用 会议室业务处理层
 * @createTime 2021年11月24日 10:14:00
 */
@Service
@Slf4j
public class RoomsApi {
    private final String baseUri = "/v1/meeting-rooms";

    /**
     * 查询账户下 Rooms 资源
     * @return
     */
    public HttpResponse roomsInventory() {
        String uri = "/v1/rooms-inventory";
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return httpResponse;
    }

    /**
     * 查询会议室列表
     * @return
     */
    public HttpResponse meetingRooms(Integer page , Integer pageSize) {
        ///v1/meeting-rooms?page={page}&page_size={page_size}&meeting_room_name={meeting_room_name}
        String uri = baseUri.concat("?page=").concat(String.valueOf(page)).concat("&page_size=").concat(String.valueOf(pageSize));
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return httpResponse;
    }

    /**
     * 生成设备激活码
     * @param activeCodeVo
     * @return
     */
    public Map<String, Object> activeCode(ActiveCodeVo activeCodeVo) {
        String uri = baseUri.concat("/").concat(activeCodeVo.getMeetingRoomId()).concat("/active-code");
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, activeCodeVo);
        return JSON.parseObject(httpResponse.getResponseBody().toString(), Map.class);
    }

    /**
     * 查询会议室详情
     * @param meetingRoomId
     * @return
     */
    public HttpResponse queryMeetingRoomInfo(String meetingRoomId) {
        String uri = baseUri.concat("/").concat(meetingRoomId);
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return httpResponse;
    }

    /**
     * 查询设备列表
     * @param queryDeviceListVo
     * @return
     */
    public Map<String, Object> queryDeviceList(QueryDeviceListVo queryDeviceListVo) {
        //https://api.meeting.qq.com/v1/devices?page={page}&page_size={page_size}&meeting_room_name={meeting_room_name}
        String uri = "/v1/devices".concat("?page=").concat(String.valueOf(queryDeviceListVo.getPage()))
                .concat("&page_size=").concat(String.valueOf(queryDeviceListVo.getPageSize()))
                .concat("&meeting_room_name=").concat(queryDeviceListVo.getMeetingRoomName());
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return JSON.parseObject(httpResponse.getResponseBody().toString(), Map.class);
    }

    /**
     * 预定会议室
     * @param bookRoomsVo
     * @return
     */
    public HttpResponse bookRooms(BookRoomsVo bookRoomsVo) {
        String uri = "/v1/meetings/".concat(bookRoomsVo.getMeetingId()).concat("/book-rooms");
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, bookRoomsVo);
        return httpResponse;
    }

    /**
     * 释放会议室
     * @param bookRoomsVo
     * @return
     */
    public HttpResponse releaseRooms(BookRoomsVo bookRoomsVo) {
        //https://api.meeting.qq.com/v1/meetings/{meeting_id}/release-rooms
        String uri = "/v1/meetings/".concat(bookRoomsVo.getMeetingId()).concat("/release-rooms");
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, bookRoomsVo);
        return httpResponse;
    }
}

腾讯会议API调用 用户业务处理层:

/**
 * @author dongliang7
 * 
 * @ClassName UsersServiceImpl.java
 * @description: 腾讯会议API调用 用户业务处理层
 * @createTime 2021年11月24日 10:19:00
 */
@Service
@Slf4j
public class UsersApi {
    private final String userUri = "/v1/users";

    /**
     * 创建用户
     * @param userCreateVo
     */
    public HttpResponse createUser(UserCreateVo userCreateVo) {
        String uri = userUri;
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, userCreateVo);
        return httpResponse;
    }

    /**
     * 通过 userid 更新用户
     * @param userUpdateVo
     * @return
     */
    public HttpResponse updateUser(UserUpdateVo userUpdateVo) {
        String uri = userUri.concat("/").concat(userUpdateVo.getUserid());
        HttpResponse httpResponse = TencentMeetingProcess.putProcess(uri, userUpdateVo);
        return httpResponse;
    }

    /**
     * 查询用户详情
     * @param userId
     * @return
     */
    public HttpResponse queryUserInfoDetail(String userId) {
        String uri = userUri.concat("/").concat(userId);
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return httpResponse;
    }

    /**
     * 查询用户列表
     * @param page
     * @param pageSize
     * @return
     */
    public QueryUserInfoList queryUserInfoList(Integer page, Integer pageSize) {
        String uri = userUri.concat("/list?page=").concat(String.valueOf(page))
                .concat("&page_size=").concat(String.valueOf(pageSize));
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return JSON.parseObject(httpResponse.getResponseBody().toString(), QueryUserInfoList.class);
    }

    /**
     * 通过 userid 删除用户
     * @param userDeleteVo
     * @return
     */
    public HttpResponse deleteUser(UserDeleteVo userDeleteVo) {
        String uri = userUri.concat("/").concat(userDeleteVo.getUserId());
        HttpResponse httpResponse = TencentMeetingProcess.deleteProcess(uri);
        return httpResponse;
    }

    /**
     *  查询个人会议号配置信息
     * @param userId
     * @param instanceId
     * @return
     */
    public String getMeetingPmiConfig(String userId, String instanceId) {
        //GET https://api.meeting.qq.com/v1/pmi-meetings/pmi-config?userid=tester&instanceid=1
        String uri = "/v1/pmi-meetings/pmi-config".concat("?userid=").concat(userId).concat("&instanceid=").concat(instanceId);
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return httpResponse.getResponseBody().toString();
    }

    /**
     * 设置企业成员发起会议的权限
     * @param authorizedUsersVo
     * @return
     */
    public String setUpAuthorizedUsers(AuthorizedUsersVo authorizedUsersVo) {
        //POST https://api.meeting.qq.com/v1/corp-resource/book-meeting/authorized-users
        String uri = "/v1/corp-resource/book-meeting/authorized-users";
        HttpResponse httpResponse = TencentMeetingProcess.postProcess(uri, authorizedUsersVo);
        return httpResponse.getResponseBody().toString();
    }

    /**
     * 查询企业下可发起会议的成员列表
     * @param queryAuthorizedUsersVo
     * @return
     */
    public String queryAuthorizedUsers(QueryAuthorizedUsersVo queryAuthorizedUsersVo) {
        //GET v1/corp-resource/book-meeting/authorized-users?operator_userid={operator_userid}&page={page}&page_size={page_size}
        String uri = "/v1/corp-resource/book-meeting/authorized-users?operator_userid="
                .concat(queryAuthorizedUsersVo.getOperatorUserId())
                .concat("&page=").concat(String.valueOf(queryAuthorizedUsersVo.getPage()))
                .concat("&page_size=").concat(String.valueOf(queryAuthorizedUsersVo.getPageSize()));
        HttpResponse httpResponse = TencentMeetingProcess.getProcess(uri);
        return httpResponse.getResponseBody().toString();
    }
}

 代码地址GitHub:https://github.com/dongl-dl/tencent-meeting-api

posted @ 2022-01-05 10:52  AmourLee  阅读(4440)  评论(1编辑  收藏  举报