通话逻辑
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package com.ruoyi.cai.agora;
|
||||
package com.ruoyi.cai.trd;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cai.util.RestTemplateUtil;
|
||||
import com.ruoyi.websocket.config.AgoraProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -45,15 +44,15 @@ public class Agora {
|
||||
|
||||
public void closeChannel(String roomId){
|
||||
String url = "http://api.sd-rtn.com/dev/v1/kicking-rule";
|
||||
Map<String,Object> param = new HashMap<>();
|
||||
param.put("appid",agoraProperties.getAppId());
|
||||
param.put("cname",roomId);
|
||||
param.put("time",0);
|
||||
param.put("privileges",Collections.emptyList());
|
||||
Map<String,Object> bodyData = new HashMap<>();
|
||||
bodyData.put("appid",agoraProperties.getAppId());
|
||||
bodyData.put("cname",roomId);
|
||||
bodyData.put("time",0);
|
||||
bodyData.put("privileges",Collections.emptyList());
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set("Authorization", getAuthorizationHeader());
|
||||
HttpEntity httpEntity = new HttpEntity<>(param, headers);
|
||||
HttpEntity httpEntity = new HttpEntity<>(bodyData, headers);
|
||||
RestTemplateUtil.restTemplate.postForObject(url, httpEntity, JSONObject.class);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.cai.trd;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "agora")
|
||||
public class AgoraProperties {
|
||||
private String appId;
|
||||
private String key;
|
||||
private String secret;
|
||||
}
|
||||
18
ruoyi-cai/src/main/java/com/ruoyi/cai/trd/ImDataRes.java
Normal file
18
ruoyi-cai/src/main/java/com/ruoyi/cai/trd/ImDataRes.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.ruoyi.cai.trd;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ImDataRes {
|
||||
private Integer type;
|
||||
private ImData data;
|
||||
|
||||
@Data
|
||||
public static class ImData {
|
||||
private Integer callType;
|
||||
private Integer status;
|
||||
private String fromUid;
|
||||
private String toUid;
|
||||
private Integer callTime;
|
||||
}
|
||||
}
|
||||
24
ruoyi-cai/src/main/java/com/ruoyi/cai/trd/ImMsgGen.java
Normal file
24
ruoyi-cai/src/main/java/com/ruoyi/cai/trd/ImMsgGen.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.ruoyi.cai.trd;
|
||||
|
||||
public class ImMsgGen {
|
||||
|
||||
/**
|
||||
* 通话通知
|
||||
* @param status
|
||||
* @param from
|
||||
* @param to
|
||||
* @param callTime
|
||||
*/
|
||||
public static ImDataRes callNotice(int status,String from,String to,int callTime){
|
||||
ImDataRes imDataRes = new ImDataRes();
|
||||
imDataRes.setType(15);
|
||||
ImDataRes.ImData imData = new ImDataRes.ImData();
|
||||
imData.setCallType(1);
|
||||
imData.setStatus(status);
|
||||
imData.setFromUid(from);
|
||||
imData.setToUid(to);
|
||||
imData.setCallTime(callTime);
|
||||
imDataRes.setData(imData);
|
||||
return imDataRes;
|
||||
}
|
||||
}
|
||||
77
ruoyi-cai/src/main/java/com/ruoyi/cai/trd/Yunxin.java
Normal file
77
ruoyi-cai/src/main/java/com/ruoyi/cai/trd/Yunxin.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package com.ruoyi.cai.trd;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cai.util.RestTemplateUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class Yunxin {
|
||||
|
||||
@Autowired
|
||||
private YunxinProperties yunxinProperties;
|
||||
|
||||
private final static String SEND_URL = "https://api.netease.im/nimserver/msg/sendMsg.action";
|
||||
private final static String SEND_ATTR_URL = "https://api.netease.im/nimserver/msg/sendAttachMsg.action";
|
||||
|
||||
public void sendTo(String toUid,Object data,String fromUid){
|
||||
Map<String,Object> option = new HashMap<>();
|
||||
option.put("push",true); // 该消息是否需要APNS推送或安卓系统通知栏推送
|
||||
option.put("roam",false); // 该消息是否需要漫游(需要app开通漫游消息功能)
|
||||
option.put("history",false); // 该消息是否存云端历史
|
||||
option.put("sendersync",false); // 该消息是否需要发送方多端同步
|
||||
option.put("route",false); // 该消息是否需要抄送第三方 (需要app开通消息抄送功能)
|
||||
|
||||
Map<String,Object> bodyData = new HashMap<>();
|
||||
bodyData.put("from", StringUtils.isBlank(fromUid) ? yunxinProperties.getDefaultFromUid() :fromUid);
|
||||
bodyData.put("ope", 0);
|
||||
bodyData.put("to", toUid);
|
||||
bodyData.put("type", 100);
|
||||
bodyData.put("body", JSON.toJSONString(data));
|
||||
bodyData.put("option", JSON.toJSONString(option));
|
||||
String nonce = UUID.fastUUID().toString();
|
||||
String curTime = DateUtil.currentSeconds() + "";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("AppKey",yunxinProperties.getAppKey());
|
||||
headers.add("Nonce", nonce);
|
||||
headers.add("CurTime", curTime);
|
||||
headers.add("CheckSum", yunxinProperties.getAppSecret()+nonce+curTime);
|
||||
HttpEntity httpEntity = new HttpEntity<>(bodyData, headers);
|
||||
RestTemplateUtil.restTemplate.postForObject(SEND_URL,httpEntity, JSONObject.class);
|
||||
}
|
||||
|
||||
public void sendAttachMsg(String toUid,Object data,String fromUid){
|
||||
Map<String,Object> option = new HashMap<>();
|
||||
option.put("push",true); // 该消息是否需要APNS推送或安卓系统通知栏推送
|
||||
option.put("roam",false); // 该消息是否需要漫游(需要app开通漫游消息功能)
|
||||
option.put("history",false); // 该消息是否存云端历史
|
||||
option.put("sendersync",false); // 该消息是否需要发送方多端同步
|
||||
option.put("route",false); // 该消息是否需要抄送第三方 (需要app开通消息抄送功能)
|
||||
|
||||
Map<String,Object> bodyData = new HashMap<>();
|
||||
bodyData.put("from", StringUtils.isBlank(fromUid) ? yunxinProperties.getDefaultFromUid() :fromUid);
|
||||
bodyData.put("ope", 0);
|
||||
bodyData.put("to", toUid);
|
||||
bodyData.put("type", 100);
|
||||
bodyData.put("body", JSON.toJSONString(data));
|
||||
bodyData.put("option", JSON.toJSONString(option));
|
||||
String nonce = UUID.fastUUID().toString();
|
||||
String curTime = DateUtil.currentSeconds() + "";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("AppKey",yunxinProperties.getAppKey());
|
||||
headers.add("Nonce", nonce);
|
||||
headers.add("CurTime", curTime);
|
||||
headers.add("CheckSum", yunxinProperties.getAppSecret()+nonce+curTime);
|
||||
HttpEntity httpEntity = new HttpEntity<>(bodyData, headers);
|
||||
RestTemplateUtil.restTemplate.postForObject(SEND_ATTR_URL,httpEntity, JSONObject.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ruoyi.cai.trd;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "yunxin")
|
||||
public class YunxinProperties {
|
||||
private String appKey;
|
||||
private String appSecret;
|
||||
|
||||
private String defaultFromUid;
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
public class RestTemplateUtil {
|
||||
|
||||
public static RestTemplate restTemplate = null;
|
||||
public static RestTemplate restTemplate;
|
||||
|
||||
static {
|
||||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.ruoyi.cai.ws.processon;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ruoyi.cai.agora.Agora;
|
||||
import com.ruoyi.cai.trd.Agora;
|
||||
import com.ruoyi.cai.executor.ExecutorConstant;
|
||||
import com.ruoyi.cai.service.CaiAnchorService;
|
||||
import com.ruoyi.cai.service.CaiUserService;
|
||||
|
||||
Reference in New Issue
Block a user