123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package com.sooka.sponest.dataexchange.hwMeeting.controller;
- import com.dahuatech.hutool.json.JSONArray;
- import com.dahuatech.hutool.json.JSONObject;
- import com.dahuatech.hutool.json.JSONTokener;
- import com.dahuatech.hutool.json.JSONUtil;
- import com.ruoyi.common.core.web.domain.AjaxResult;
- import com.ruoyi.common.redis.service.RedisService;
- import com.sooka.sponest.dataexchange.hwMeeting.service.HwMeetingService;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import javax.annotation.Resource;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * 华为云会议控制器
- */
- @Controller
- @RequestMapping("/hwMeeting")
- public class HwMeetingController {
- @Resource
- private HwMeetingService hwMeetingService;
- @Resource
- private RedisService redisService;
- /**
- * 创建或加入会议
- */
- @GetMapping("/joinConferences/{eventId}/{subject}/{nickName}")
- @ResponseBody
- public AjaxResult hasConferences(@PathVariable(name = "eventId") String eventId,
- @PathVariable(name = "subject") String subject,
- @PathVariable(name = "nickName") String nickName) {
- Map<String,Object> map = new HashMap<>();
- //查询在线会议
- JSONObject hasConferences = JSONUtil.parseObj(hwMeetingService.hasConferences());
- //有在线会议 返回来宾入会凭据
- if (hasConferences.getInt("count") > 0) {
- //取会议信息
- JSONObject conferencesInfo = hasConferences.getJSONArray("data").getJSONObject(0);
- //取密码数组 passwordEntry
- JSONArray array = JSONUtil.parseArray(conferencesInfo.get("passwordEntry"));
- for (Object o : array) {
- JSONObject password = JSONUtil.parseObj(o);
- JSONObject generalInfo = new JSONObject();
- if (password.getStr("conferenceRole").equals("general")) {
- generalInfo.put("conferenceID", conferencesInfo.getStr("conferenceID"));
- generalInfo.put("password", password.getStr("password"));
- map.put("info",generalInfo);
- }
- }
- }else{
- //无在线会议 创建会议并返回主持人入会凭据
- this.createConferences(eventId,subject,map);
- }
- map.put("nickName",nickName);
- map.put("nonce",hwMeetingService.getNonce());
- return AjaxResult.success(map);
- }
- /**
- * 创建会议
- */
- public boolean createConferences(String eventId,String subject,Map map) {
- String result = hwMeetingService.conferences(subject);
- if (isSuccess(result)) {
- //将结果转换为json数组,当处理成功时返回的格式为数组
- Object ob = JSONUtil.parseArray(result).get(0);
- //ob转换为JSONObject 取主持人入会信息返回
- JSONObject object = JSONUtil.parseObj(ob);
- //取密码数组 passwordEntry
- JSONArray array = JSONUtil.parseArray(object.get("passwordEntry"));
- for (Object o : array) {
- JSONObject password = JSONUtil.parseObj(o);
- JSONObject chairInfo = new JSONObject();
- //返回主持人入会凭据
- if (password.getStr("conferenceRole").equals("chair")) {
- chairInfo.put("conferenceID", object.getStr("conferenceID"));
- chairInfo.put("password", password.getStr("password"));
- map.put("info",chairInfo);
- }
- }
- return true;
- }
- return false;
- }
- /**
- * 获取加入会议URI
- */
- @ResponseBody
- @GetMapping("/guestJoinUri/{eventId}")
- public AjaxResult guestJoinUri(@PathVariable(name = "eventId") String eventId) {
- //查询在线会议
- JSONObject hasConferences = JSONUtil.parseObj(hwMeetingService.hasConferences());
- if(hasConferences != null){
- //取会议信息
- JSONObject conferencesInfo = hasConferences.getJSONArray("data").getJSONObject(0);
- //取入会链接
- return AjaxResult.success(conferencesInfo.get("guestJoinUri"));
- }
- return AjaxResult.error("未查询到数据");
- }
- /**
- * 判断返回数据是JSONArray还是JSONObject,
- * 如果是Array 则表示成功
- * 反之失败
- * */
- private boolean isSuccess(String result) {
- Object object = new JSONTokener(result).nextValue();
- if (object instanceof JSONObject) {
- JSONObject jsonObject = (JSONObject) object;
- String error_code = jsonObject.get("error_code").toString();
- System.err.println(error_code);
- return false;
- }
- return true;
- }
- }
|