华为云会议接口java查询会议鉴权Token查询会议录制

郎健柏
2023-12-01

华为云会议接口:文档 https://support.huaweicloud.com/api-meeting/meeting_21_0014.html

在线调试页面:https://apiexplorer.developer.huaweicloud.com/apiexplorer/sdk?product=Meeting&api=UpdateToken

华为云会议后台管理:https://bmeeting.huaweicloud.com/#/login

<!--华为云-->
        <dependency>
            <groupId>com.huaweicloud.sdk</groupId>
            <artifactId>huaweicloud-sdk-meeting</artifactId>
            <version>3.0.23-beta</version>
        </dependency>
<!-- commons-httpclient -->
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.0.1</version>
        </dependency>

此方法项目中@OpenApi可以忽略,其中日期区间华为云很坑的地方是设置完时区之后还是存在相差8小时,PC和APP上显示的不一样相差8个小时,下面方法中已处理

package com.wl.partner.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cre.dmp.osp.common.config.openapi.OpenApi;
import com.huaweicloud.sdk.meeting.v1.model.*;
import com.wl.partner.entity.RecordFileInfo;
import com.wl.partner.entity.ResultVO;
import com.wl.partner.utils.StringUtil;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Encoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


@RestController
@RequestMapping("/huaWeiMeet")
public class HuaWeiMeeting {
    /**
     * postMan调用参数
     * 请求头设置:Content-Type   application/json;charset=UTF-8
     * body中{"userName":"****","passWord":"***"}
     * @param map
     * @return
     */
    @ApiOperation(value = "创建华为云token", notes = "创建华为云token")
    @OpenApi
    @RequestMapping(value = "/openCreateToken", method = {RequestMethod.POST})
    public ResultVO openCreateToken(@OpenApi Map map) {
        String userName = (String) map.get("hwUserName");
        String passWord = (String) map.get("hwPassWord");
        ResultVO j = new ResultVO();
        String message = null;
        try {
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
            HttpPost post = new HttpPost("https://api.meeting.huaweicloud.com/v1/usg/acs/auth/account");
            BASE64Encoder encoder = new BASE64Encoder();
            final byte[] textByte = (userName + ":" + passWord).getBytes(StandardCharsets.UTF_8);
            String encodedText =  "Basic " +encoder.encode(textByte);
            post.addHeader("Authorization",encodedText);
            System.out.println("华为Base验证账号密码加密后的编码:    "+encodedText);
            post.addHeader("Content-Type","application/json;charset=UTF-8");
            HashMap<String, Object> mapParameter = new HashMap<>();
            mapParameter.put("account",userName);
            mapParameter.put("clientType",0);
            /**
             * 登录帐号类型。
             * 0:Web客户端类型
             * 5:cloudlink pc
             * 6:cloudlink mobile
             * 15:硬终端
             * 16:WeLink pc
             * 17:cloudlink 大屏
             * 18:welink mobile
             * 20:welink 大屏
             * 24:cloudlink/welink pad;
             * 26:智慧屏
             */
            net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(mapParameter);
            StringEntity json = new StringEntity(jsonObject.toString());
            //json.setContentEncoding("UTF-8");
            //发送json数据需要设置contentType
            json.setContentType("application/json;charset=UTF-8");
            post.setEntity(json); //设置请求参数
            HttpResponse response = httpClient.execute(post);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                //返回String
                String res = EntityUtils.toString(response.getEntity());
                JSONObject object = JSONObject.parseObject(res);
                String accessToken = (String)object.get("accessToken");
                String userId = (String)JSONObject.parseObject(object.get("user").toString()).get("userId");
                HashMap<String, String> hashMap = new HashMap<>();
                if(StringUtil.isNotEmpty(accessToken)){
                    System.out.println("华为云会议登陆token:"+accessToken);
                    hashMap.put("accessToken",accessToken);
                    hashMap.put("userId",userId);
                    j.setObj(hashMap);
                    message="签名成功";
                }
            }else {
                message="请求异常";
                j.setSuccess(false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }

    /**
     * 刷新token
     * @param map
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openRefreshToken",method = RequestMethod.POST)
    public ResultVO openRefreshToken(@OpenApi Map map) {
        String accessToken = (String) map.get("accessToken");
        ResultVO j = new ResultVO();
        String message = null;
        try {
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
            HttpPut put = new HttpPut("https://api.meeting.huaweicloud.com/v1/usg/acs/token");
            put.addHeader("X-Access-Token",accessToken);
            HttpResponse response = httpClient.execute(put);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                //返回String
                String res = EntityUtils.toString(response.getEntity());
                JSONObject object = JSONObject.parseObject(res);
                String newAccessToken = (String)object.get("accessToken");
                Integer refreshValidPeriodSecond = (Integer)object.get("refreshValidPeriod");//失效时间戳
                System.out.println("有效时长:"+ refreshValidPeriodSecond +"秒");
                if(StringUtil.isNotEmpty(newAccessToken)){
                    j.setObj(newAccessToken);
                    message="刷新token成功";
                }
            }else {
                message="刷新失败,请传入刷新之后的token";
                j.setSuccess(false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }
//    public String refreshTokenBd(String accessToken) {
//        try {
//            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
//            HttpPut put = new HttpPut("https://api.meeting.huaweicloud.com/v1/usg/acs/token");
//            put.addHeader("X-Access-Token",accessToken);
//            HttpResponse response = httpClient.execute(put);
//            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
//                //返回String
//                String res = EntityUtils.toString(response.getEntity());
//                JSONObject object = JSONObject.parseObject(res);
//                String newAccessToken = (String)object.get("accessToken");
//                if(StringUtil.isNotEmpty(newAccessToken)){
//                   return newAccessToken;
//                }
//            }else {
//                return "刷新失败重新登陆获取token";
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
    /**
     * 校验token
     * {
     *     "accessToken": "********"
     * }
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openValidateToken",method = RequestMethod.POST)
    public ResultVO openValidateToken(@OpenApi Map map) {
        String accessToken = (String) map.get("accessToken");
        ResultVO j = new ResultVO();
        String message = null;
        try {
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
            HttpPost post = new HttpPost("https://api.meeting.huaweicloud.com/v1/usg/acs/token/validate");
            post.addHeader("Content-Type","application/json; charset=UTF-8");
            HashMap<String, Object> mapParameter = new HashMap<>();
            mapParameter.put("token",accessToken);
            mapParameter.put("needGenNewToken",false);//是否生成新的token。 true:生成新的token值。false:不生成新的token值。
            net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(mapParameter);
            StringEntity json = new StringEntity(jsonObject.toString());
            //发送json数据需要设置contentType
            json.setContentType("application/json;charset=UTF-8");
            post.setEntity(json); //设置请求参数
            HttpResponse response = httpClient.execute(post);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                j.setObj(true);
                j.setMsg("校验成功");
            }else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED){
                j.setObj(false);
                j.setMsg("Token失效");;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return j;
    }
    /**
     * 创建会议:http://172.29.53.161:8089/jeecg/huaWeiMeeting.do?createMeeting
     * 参数目前先定一个: accessToken
     * 创建会议
     * {
     *     "X-Access-Token": "*************",
     *     "mediaTypes": "Video",
     *     "length": 15,
     *     "startDate": "2020-12-12",
     *     "endDate": "2020-12-18",
     *     "conferenceType":0,
     *     "cycle": "Day",
     *     "subject":"指定时间会议",
     *     "phone": "15555555555",
     *     "startTime":"2020-12-11 15:00"
     * }
     * @param
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openCreateMeeting",method = RequestMethod.POST)
    public ResultVO openCreateMeeting(@OpenApi Map map) {
        ResultVO j = new ResultVO();
        String message = null;
        try {
            String accessToken = (String) map.get("X-Access-Token");
            String mediaTypes = (String) map.get("mediaTypes");
            Integer length = (Integer) map.get("length");
            String startTime = (String) map.get("startTime");
            Integer recordAuthType = (Integer) map.get("recordAuthType");
            Integer recordType = (Integer) map.get("recordType");
            Integer isAutoRecord = (Integer) map.get("isAutoRecord");
            Integer interval = (Integer) map.get("interval");
            String sms = (String) map.get("sms");
            Boolean isSendSms = (Boolean) map.get("isSendSms");
            Integer conferenceType = (Integer) map.get("conferenceType");
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
            HttpPost post = new HttpPost("https://api.meeting.huaweicloud.com/v1/mmc/management/conferences");
            post.addHeader("X-Access-Token",accessToken);
            HashMap<String, Object> mapParameter = new HashMap<>();
            mapParameter.put("mediaTypes",mediaTypes);//"Voice”:语音。 Video 标清视频。 "HDVideo”:高清视频
            if(recordAuthType!=null){
                mapParameter.put("recordAuthType",recordAuthType);//0:可通过链接观看/下载。1:企业用户可观看/下载。2:与会者可观看/下载。
            }
            if(recordType!=null){
                mapParameter.put("recordType",recordType);//录播类型。默认为禁用。0: 禁用 。1: 直播 。2: 录播。3: 直播+录播。
            }
            if(isAutoRecord!=null){
                mapParameter.put("isAutoRecord",isAutoRecord);//会议是否自动启动录制,在录播类型为:录播、录播+直播时才生效。默认为不自动启动。1:自动启动录制。 0:不自动启动录制。
            }
            if(interval!=null){
                mapParameter.put("interval",interval);//“cycle”选择了“Day”,表示每几天召开一次,取值范围[1,60]。“cycle”选择了“Week”,表示每几周召开一次,取值范围[1,5]。“cycle”选择了“Month”,Interval表示隔几月,取值范围[1,12]。
            }
            mapParameter.put("timeZoneID","56");//时区
            if(StringUtil.isNotEmpty(startTime)){
                String s = subDayHour(startTime);//会议开始时间(UTC时间)减去8小时,接口正常返回,存在逆向问题 +8 -8
                mapParameter.put("startTime",s);//创建预约会议时,如果没有指定开始时间或填空串,则表示会议马上开始。格式:yyyy-MM-dd HH:mm
            }
            if(conferenceType!=null && conferenceType!=0){
                mapParameter.put("conferenceType",conferenceType);//创建会议类型(默认为普通会议)。0 : 普通会议。 1:周期会议,此时“cycleParams”必须填写。
                CycleParams cycleParams = new CycleParams();
                String startDate = (String) map.get("startDate");
                String endDate = (String) map.get("endDate");
                Object point = map.get("point");
                if(StringUtil.isNotEmpty(startDate) && StringUtil.isNotEmpty(endDate)){
                    cycleParams.setStartDate(startDate);//周期会议的开始日期,格式:YYYY-MM-DD。开始日期不能早于当前日期。
                    cycleParams.setEndDate(endDate);
                    if(StringUtil.isNotEmpty(point)){
                        List<Integer> pointlist = castList(point, Integer.class);
                        cycleParams.setPoint(pointlist);
                    }
                }else {
                    j.setMsg("缺失必填参数开始时间 或者 结束时间");
                    return j;
                }
                String cycle = (String) map.get("cycle");
                if(StringUtil.isNotEmpty(cycle)){
                    cycleParams.setCycle(cycle);//周期类型。“Day”:天。“Week”:星期。“Month”:月。
                }else {
                    j.setMsg("缺失必填参数 周期类型");
                    return j;
                }
                cycleParams.setPreRemindDays(1);
                /**
                 * 支持用户指定提前会议通知的天数N,预订人收到整个周期会议的通知,所有与会人在每个子会议召开时间的前N天收到会议通知(包括日历)。
                 * 天数N的输入根据间隔期进行自动调整,如果按日每隔2天召开,则N自动变为2,如果为按周每2周的周一、周二,则N自动变为14。 约束:暂不考虑夏令时处理。
                 * 取值范围[1,30]。
                 * default: 1
                 */
                mapParameter.put("cycleParams",cycleParams);
            }
            String subject = (String) map.get("subject");//会议主题
            if(StringUtil.isNotEmpty(subject)){
                mapParameter.put("subject",subject);
            }
            if (StringUtil.isNotEmpty(length)) {
                mapParameter.put("length",length);//会议持续时长,单位分钟,最大值为1440,最短15。default: 30。
            }
            /** mediaTypes
             * 会议的媒体类型。
             * 由1个或多个枚举String组成,多个枚举时,每个枚举值之间通过“,”逗号分隔,枚举值如下:
             *
             * "Voice”:语音。
             * "Video”:标清视频。
             * "HDVideo”:高清视频(与Video互斥,如果同时选择Video、HDVideo,则系统默认选择Video)。
             * "Telepresence”:智真(与HDVideo、Video互斥,如果同时选择,系统使用Telepresence)。(预留字段)
             * "Data”:多媒体(系统配置决定是否自动添加Data)。
             */
            /**
             * attendee 与会者列表。该列表可以用于发送会议通知、会议提醒、会议开始时候进行自动邀请
             */
            String phone = (String) map.get("phone");
            if(StringUtil.isNotEmpty(phone)){
                Attendee attendee = new Attendee();
                attendee.setPhone(phone);
                mapParameter.put("attendee",attendee);
                if(StringUtil.isNotEmpty(phone)){
                    attendee.setPhone(phone);
                    mapParameter.put("sms",sms);
                }
            }
            //是否发送短信
            if(StringUtil.isNotEmpty(isSendSms) || true==(isSendSms==null?false:true)){
                RestConfConfigDTO confConfigDTO = new RestConfConfigDTO();
                confConfigDTO.setIsSendSms(true);
                mapParameter.put("ConfConfigInfo",confConfigDTO);
            }
            String jsonObject = JSON.toJSONString(mapParameter);
            StringEntity json = new StringEntity(jsonObject,"UTF-8");
            post.setEntity(json); //设置请求参数
            post.setHeader("Content-Type", "application/json;charset=utf8");
            HttpResponse response = httpClient.execute(post);
            //response.setHeader("Content-Type","application/json;charset=utf8");
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                message = "创建会议成功";
                //返回String
                String res = EntityUtils.toString(response.getEntity(),"UTF-8");
                List<ConferenceInfo> conferenceInfos = JSONObject.parseArray(res, ConferenceInfo.class);
                for (ConferenceInfo conferenceInfo : conferenceInfos) {
                    System.out.println("创建的会议ID "+conferenceInfo.getConferenceID());
                }
                j.setObj(conferenceInfos);
            }else {
                message = "创建异常或者Token失效";
                j.setSuccess(false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }

    /**
     * 查询会议列表
     * @param
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openSearchMeetings",method = RequestMethod.POST)
    public ResultVO  openSearchMeetings(@OpenApi Map map) {
        ResultVO j = new ResultVO();
        String message = null;
        try {
            String accessToken =(String )map.get("X-Access-Token");
            String queryConfMode =(String )map.get("queryConfMode");
            Integer offset =(Integer )map.get("offset");
            Integer limit =(Integer )map.get("limit");
            String searchKey =(String )map.get("searchKey");
            HttpClient httpClient = new HttpClient();
            httpClient.setConnectionTimeout(1000 * 60);
            //处理乱码
            httpClient.getParams().setContentCharset("UTF-8");
            httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
            GetMethod getMethod = null;
            String url="";
            if(StringUtil.isNotEmpty(queryConfMode)){
                //ADAY:一天。AWEEK:一周。AMONTH:一个月。ALL:查询所有。
                //创建post请求
                url="https://api.meeting.huaweicloud.com/v1/mmc/management/conferences?queryConfMode="+queryConfMode+"&offset="+(offset==null?0:offset)+"&limit="+(limit==null?20:limit);
            }else {
                //创建post请求
                url="https://api.meeting.huaweicloud.com/v1/mmc/management/conferences?offset="+(offset==null?0:offset)+"&limit="+(limit==null?20:limit);
            }
            if(StringUtil.isNotEmpty(searchKey)){
                url=url+"&searchKey="+ URLEncoder.encode(searchKey, "utf-8");
            }
            getMethod = new GetMethod(url);
            //创建post请求
            //组装参数
            getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
            getMethod.addRequestHeader("X-Access-Token",accessToken);
            getMethod.addRequestHeader("Content-Type","application/json;charset=UTF-8");
            try {
                //执行请求 返回状态码
                int statusCode = httpClient.executeMethod(getMethod);
                if (statusCode != HttpStatus.SC_OK) { // 200
                   j.setMsg("查询会议异常或者Token过期");
                   j.setSuccess(false);
                   return j;
                }else {
                //获取responsebody
                byte[] responseBody = getMethod.getResponseBody();
                String result = new String(responseBody, "UTF-8");
                JSONObject jsonBody = JSONObject.parseObject(result);
                j.setObj(jsonBody);
//                Object data = JSONObject.parseObject(jsonBody.toJSONString()).get("data");
//                List<ConferenceInfo> conferenceInfos = JSONObject.parseArray(data.toString(), ConferenceInfo.class);
//                for (ConferenceInfo conferenceInfo : conferenceInfos) {
//                    System.out.println("查询已创建的会议ID "+conferenceInfo.getConferenceID()+ " " +conferenceInfo.getSubject());
//                }
//                message = "查询会议列表成功";
//                j.setObj(conferenceInfos);
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }
    /**
     * 查询在线会议列表
     * @param
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openSearchOnLineMeetings",method = RequestMethod.POST)
    public ResultVO  openSearchOnLineMeetings(@OpenApi Map map) {
        ResultVO j = new ResultVO();
        String message = null;
        try {
            String accessToken =(String )map.get("X-Access-Token");
            Boolean queryAll =(Boolean )map.get("queryAll");
            Integer offset =(Integer )map.get("offset");
            Integer limit =(Integer )map.get("limit");
            String searchKey =(String )map.get("searchKey");
            HttpClient httpClient = new HttpClient();
            httpClient.setConnectionTimeout(1000 * 60);
            //处理乱码
            httpClient.getParams().setContentCharset("UTF-8");
            httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
            GetMethod getMethod = null;
            String url="";
            if(StringUtil.isNotEmpty(queryAll)){
                //ADAY:一天。AWEEK:一周。AMONTH:一个月。ALL:查询所有。
                //创建post请求
                url="https://api.meeting.huaweicloud.com/v1/mmc/management/conferences/online?queryAll="+queryAll+"&offset="+(offset==null?0:offset)+"&limit="+(limit==null?20:limit);
            }else {
                //创建post请求
                url="https://api.meeting.huaweicloud.com/v1/mmc/management/conferences/online?offset="+(offset==null?0:offset)+"&limit="+(limit==null?20:limit);
            }
            if(StringUtil.isNotEmpty(searchKey)){
                url=url+"&searchKey="+ URLEncoder.encode(searchKey, "utf-8");
            }
            getMethod = new GetMethod(url);
            //创建post请求
            //组装参数
            getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
            getMethod.addRequestHeader("X-Access-Token",accessToken);
            getMethod.addRequestHeader("Content-Type","application/json;charset=UTF-8");
            try {
                //执行请求 返回状态码
                int statusCode = httpClient.executeMethod(getMethod);
                if (statusCode != HttpStatus.SC_OK) { // 200
                    j.setMsg("查询会议异常或者Token过期");
                    j.setSuccess(false);
                    return j;
                }else {
                    //获取responsebody
                    byte[] responseBody = getMethod.getResponseBody();
                    String result = new String(responseBody, "UTF-8");
                    JSONObject jsonBody = JSONObject.parseObject(result);
                    j.setObj(jsonBody);
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }
    /**
     * 取消预约会议
     * @param
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openCancelMeeting",method = RequestMethod.POST)
    public ResultVO  openCancelMeeting(@OpenApi Map map) {
        ResultVO j = new ResultVO();
        String message = null;
        try {
            String accessToken =(String )map.get("X-Access-Token");
            String conferenceID =(String )map.get("conferenceID");
            HttpClient httpClient = new HttpClient();
            httpClient.setConnectionTimeout(1000 * 60);
            //处理乱码
            httpClient.getParams().setContentCharset("UTF-8");
            httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
            //创建delete请求
            DeleteMethod deleteMethod = new DeleteMethod("https://api.meeting.huaweicloud.com/v1/mmc/management/conferences?conferenceID="+conferenceID);
            //组装参数
            deleteMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
            deleteMethod.addRequestHeader("X-Access-Token",accessToken);
            deleteMethod.addRequestHeader("Content-Type","application/json;charset=UTF-8");
            try {
                //执行请求 返回状态码
                int statusCode = httpClient.executeMethod(deleteMethod);
                if (statusCode != HttpStatus.SC_OK) {
                    JSONObject jsonBody = JSONObject.parseObject(new String(deleteMethod.getResponseBody(), "UTF-8"));
                    String error_code = (String)jsonBody.get("error_code");
                    if("MMC.111071067".equalsIgnoreCase(error_code)){
                        j.setMsg("会议正在召开无法取消");
                        j.setSuccess(false);
                        return j;
                    }if("MMC.111070005".equalsIgnoreCase(error_code)){
                        j.setMsg("请检查会议ID是否正确,或会议是否已召开");
                        j.setSuccess(false);
                        return j;
                    }else {
                        System.out.println( new String(deleteMethod.getResponseBody(), "UTF-8"));
                        j.setMsg("查询取消异常或者Token过期");
                        j.setSuccess(false);
                        return j;
                    }
                }else {
                    message = "取消会议成功";
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }
    /**
     * 查询华为云企业通讯录
     * @param
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openQueryMeetingAddressList",method = RequestMethod.POST)
    public ResultVO  openQueryMeetingAddressList(@OpenApi Map map) {
        ResultVO j = new ResultVO();
        String message = null;
        try {
            String accessToken =(String )map.get("X-Access-Token");
            String searchKey =(String )map.get("searchKey");//搜索条件。支持账号、姓名、手机、邮箱模糊搜索
            String deptCode =(String )map.get("deptCode");//部门编码。maxLength: 32   minLength:0
            HttpClient httpClient = new HttpClient();
            //处理乱码
            httpClient.getParams().setContentCharset("UTF-8");
            httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
            //创建get请求
            GetMethod getMethod =null;
            if(StringUtil.isNotEmpty(searchKey)){
                 getMethod = new GetMethod("https://api.meeting.huaweicloud.com/v1/usg/abs/users?searchKey="+searchKey);
            }else if(StringUtil.isNotEmpty(deptCode)){
                getMethod = new GetMethod("https://api.meeting.huaweicloud.com/v1/usg/abs/users?deptCode="+deptCode);

            } else{
                 getMethod = new GetMethod("https://api.meeting.huaweicloud.com/v1/usg/abs/users");
            }
            //组装参数
            getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
            getMethod.addRequestHeader("X-Access-Token",accessToken);
            getMethod.addRequestHeader("Content-Type","application/json;charset=UTF-8");
            try {
                //执行请求 返回状态码
                int statusCode = httpClient.executeMethod(getMethod);
                if (statusCode != HttpStatus.SC_OK) {
                    JSONObject jsonBody = JSONObject.parseObject(new String(getMethod.getResponseBody(), "UTF-8"));
                    String error_code = (String)jsonBody.get("error_code");
                    String error_msg = (String)jsonBody.get("error_msg");
                    if("USG.000000004".equalsIgnoreCase(error_code)){
                        j.setMsg("请检查请求头域X-Auth-Token或X-Access-Token的值是否过期");
                    }else {
                        j.setMsg("查询取消异常或者Token过期");
                    }
                    j.setSuccess(false);
                    return j;
                }else {
                    byte[] responseBody = getMethod.getResponseBody();
                    String result = new String(responseBody, "UTF-8");
                    JSONObject jsonBody = JSONObject.parseObject(result);
                    Object data = JSONObject.parseObject(jsonBody.toJSONString()).get("data");
                    List<UserDTO > userDTOList = JSONObject.parseArray(data.toString(), UserDTO.class);
                    j.setObj(userDTOList);
                    message = "查询通讯录成功";
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }
    /**
     * 查询会议录制列表
     * @param
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openSearchMeetingsRecordList",method = RequestMethod.POST)
    public ResultVO  openSearchMeetingsRecordList(@OpenApi Map map) {
        ResultVO j = new ResultVO();
        String message = null;
        try {
            String accessToken =(String )map.get("X-Access-Token");
            System.out.printf("startDate:  "+(String) map.get("startDate"));
            long startDate= Long.parseLong((String) map.get("startDate"));
            long endDate = Long.parseLong((String) map.get("endDate"));
            Boolean queryAll =(Boolean )map.get("queryAll");
            HttpClient httpClient = new HttpClient();
            httpClient.setConnectionTimeout(1000 * 60);
            //处理乱码
            httpClient.getParams().setContentCharset("UTF-8");
            httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
            //创建post请求
            GetMethod getMethod = new GetMethod("https://api.meeting.huaweicloud.com/v1/mmc/management/record/files?startDate="+startDate+"&endDate="+endDate+"&queryAll="+queryAll);
            //组装参数
            getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
            getMethod.addRequestHeader("X-Access-Token",accessToken);
            getMethod.addRequestHeader("Content-Type","application/json;charset=UTF-8");
            try {
                //执行请求 返回状态码
                int statusCode = httpClient.executeMethod(getMethod);
                if (statusCode != HttpStatus.SC_OK) { // 200
                    j.setMsg("查询会议录制异常或者Token过期");
                    j.setSuccess(false);
                    return j;
                }else {
                    //获取responsebody
                    byte[] responseBody = getMethod.getResponseBody();
                    String result = new String(responseBody, "UTF-8");
                    JSONObject jsonBody = JSONObject.parseObject(result);
                    Object data = JSONObject.parseObject(jsonBody.toJSONString()).get("data");
//                    List<RecordFileInfo> recordFileInfo = JSONObject.parseArray(data.toString(), RecordFileInfo.class);
//                    message = "查询会议录制列表成功";
//                    j.setObj(recordFileInfo);
                    message = "查询会议录制列表成功";
                    j.setObj(data);
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }

    /**
     * 批量删除录制视频
     * @param map
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/openDeleteMeetingsRecordByIds",method = RequestMethod.POST)
    public ResultVO  openDeleteMeetingsRecordByIds(@OpenApi Map map) {
        ResultVO j = new ResultVO();
        String message = null;
        try {
            String accessToken =(String )map.get("X-Access-Token");
            String confUUIDs =(String )map.get("confUUIDs");
            HttpClient httpClient = new HttpClient();
            //处理乱码
            httpClient.getParams().setContentCharset("UTF-8");
            httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
            //创建delete请求
            DeleteMethod deleteMethod = new DeleteMethod("https://api.meeting.huaweicloud.com/v1/mmc/management/record/files?confUUIDs="+confUUIDs);
            //组装参数
            deleteMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
            deleteMethod.addRequestHeader("X-Access-Token",accessToken);
            deleteMethod.addRequestHeader("Content-Type","application/json;charset=UTF-8");
            try {
                //执行请求 返回状态码
                int statusCode = httpClient.executeMethod(deleteMethod);
                if (statusCode != HttpStatus.SC_OK) {
                    JSONObject jsonBody = JSONObject.parseObject(new String(deleteMethod.getResponseBody(), "UTF-8"));
                    String error_code = (String)jsonBody.get("error_code");
                    String error_msg = (String)jsonBody.get("error_msg");
                    System.out.printf(error_msg + error_code);
                }else {
                    message = "删除录制成功";
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }

    /**
     * 华为云修改密码
     * @param map
     * @return
     */
    @OpenApi
    @RequestMapping(value = "/updatePassWord",method = RequestMethod.POST)
    public ResultVO updatePassWord(@OpenApi Map map) {
        String accessToken = (String) map.get("accessToken");
        String account = (String) map.get("account");//帐号,必须是携带域名的帐号
        String newPwd = (String) map.get("newPwd");
        String oldPwd = (String) map.get("oldPwd");
        ResultVO j = new ResultVO();
        String message = null;
        try {
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
            HttpPut put = new HttpPut("https://api.meeting.huaweicloud.com/v1/usg/acs/password");
            put.addHeader("X-Access-Token",accessToken);
            put.addHeader("Content-Type","application/json; charset=UTF-8");
            HashMap<String, Object> mapParameter = new HashMap<>();
            mapParameter.put("account",account);
            mapParameter.put("oldPwd",oldPwd);
            mapParameter.put("newPwd",newPwd);//用户新的登录密码。密码要求:长度要求8~32个字符
            //至少包含两种字符类型:小写字母、大写字母、数字、特殊字符(` ~ ! @ # $ % ^ & * ( ) - _ = + \ | [ { } ] ; : " ,' < . > / ?)
            //旧密码和新密码不能相同 上次修改密码后5分钟内不能更新密码 不能与最近使用的旧密码相同 不能包含3个以上重复字符
            //密码不能包含与其对应的用户名(不区分大小写)以及逆序的用户名(不区分大小写)
            //新密码与旧密码之间允许的最少不相同字符数为2个
            net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(mapParameter);
            StringEntity json = new StringEntity(jsonObject.toString());
            //发送json数据需要设置contentType
            json.setContentType("application/json;charset=UTF-8");
            put.setEntity(json); //设置请求参数
            HttpResponse response = httpClient.execute(put);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                //返回String
                String res = EntityUtils.toString(response.getEntity());
                JSONObject object = JSONObject.parseObject(res);
//                String newAccessToken = (String)object.get("accessToken");
//                Integer refreshValidPeriodSecond = (Integer)object.get("refreshValidPeriod");//失效时间戳
//                System.out.println("有效时长:"+ refreshValidPeriodSecond +"秒");
//                if(StringUtil.isNotEmpty(newAccessToken)){
//                    j.setObj(newAccessToken);
//                    message="刷新token成功";
//                }
            }else {
                message="修改失败";
                j.setSuccess(false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg(message);
        return j;
    }
    /**
     * 当前时间减去8天
     * @param date
     * @return
     * @throws ParseException
     */
    private String subDayHour(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dt = sdf.parse(date);
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.HOUR_OF_DAY, -8);
        Date dt1 = rightNow.getTime();
        String reStr = sdf.format(dt1);
        return reStr;
    }
    public static <T> List<T> castList(Object obj, Class<T> clazz)
    {
        List<T> result = new ArrayList<T>();
        if(obj instanceof List<?>)
        {
            for (Object o : (List<?>) obj)
            {
                result.add(clazz.cast(o));
            }
            return result;
        }
        return null;
    }
}

 

 类似资料: