调整融合通信代码与配置功能

This commit is contained in:
wanggeng 2022-03-23 16:46:45 +08:00
parent 1970c22e2a
commit 096ec1a46e
18 changed files with 201 additions and 219 deletions

View File

@ -1,6 +1,6 @@
package cn.com.tenlion.usercenter.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import ink.wgink.login.base.manager.ConfigManager;
import org.springframework.stereotype.Component;
/**
@ -11,34 +11,22 @@ import org.springframework.stereotype.Component;
* @Version: 1.0
*/
@Component
@ConfigurationProperties(prefix = "params-config")
public class ParamsConfigProperties {
private String roleSpecializedPerson;
private String roleGridMember;
private Boolean huaweiSmc;
public String getRoleSpecializedPerson() {
return roleSpecializedPerson == null ? "" : roleSpecializedPerson.trim();
}
public void setRoleSpecializedPerson(String roleSpecializedPerson) {
this.roleSpecializedPerson = roleSpecializedPerson;
return ConfigManager.getInstance().getSystemConfigParamsValue("roleSpecializedPerson");
}
public String getRoleGridMember() {
return roleGridMember == null ? "" : roleGridMember.trim();
}
public void setRoleGridMember(String roleGridMember) {
this.roleGridMember = roleGridMember;
return ConfigManager.getInstance().getSystemConfigParamsValue("roleGridMember");
}
public Boolean getHuaweiSmc() {
return huaweiSmc == null ? false : huaweiSmc;
return Boolean.parseBoolean(ConfigManager.getInstance().getSystemConfigParamsValue("huaweiSmc"));
}
public void setHuaweiSmc(Boolean huaweiSmc) {
this.huaweiSmc = huaweiSmc;
public Boolean getKafkaActive() {
return Boolean.parseBoolean(ConfigManager.getInstance().getSystemConfigParamsValue("kafkaActive"));
}
}

View File

@ -12,9 +12,13 @@ public class HuaWeiSMCManager {
private static final SMCHttpUtil httpUtil = new SMCHttpUtil();
public static void main(String[] args) throws Exception {
//System.out.println(createMeeting("集宁区-薛志芳", "18648051687123"));
// deleteMeeting("f645ae39-78c7-47d1-83bf-9a2e5af1f6c4");
}
/**
* 删除会议室
*
* @param meetingId 会议室ID
* @throws Exception
*/
@ -24,7 +28,6 @@ public class HuaWeiSMCManager {
/**
* 创建会议室
*
* @param name 昵称 : 集宁区-王耿
* @param username 账号 手机号 英文+数字
* @return {"meetingId":"08d7384a-c784-47ec-93ac-f83c9133e3a8","username":"15655252252","password":"tenlion@123","number":"04744543519341"}
@ -36,7 +39,6 @@ public class HuaWeiSMCManager {
/**
* 判断账号是否存在(在创建会议室已经内部校验,无需再调用)
*
* @param username
* @return
* @throws Exception

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.department.IDepartmentDeleteAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.util.string.WStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -28,11 +28,11 @@ public class DepartmentDeleteAfterHandlerImpl implements IDepartmentDeleteAfterH
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(List<String> departmentIds) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (departmentIds == null || departmentIds.isEmpty()) {

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.department.IDepartmentSaveAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -27,11 +27,11 @@ public class DepartmentSaveAfterHandlerImpl implements IDepartmentSaveAfterHandl
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(String departmentId, String departmentParentId, String departmentName, String departmentCode, Integer departmentType, String departmentAreaCode, String departmentAreaName) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(departmentId)) {

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.department.IDepartmentUpdateAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -27,7 +27,7 @@ public class DepartmentUpdateAfterHandlerImpl implements IDepartmentUpdateAfterH
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(String departmentId,
@ -36,7 +36,7 @@ public class DepartmentUpdateAfterHandlerImpl implements IDepartmentUpdateAfterH
Integer departmentType,
String departmentAreaCode,
String departmentAreaName) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(departmentId)) {

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.map.IGridDeleteAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.util.string.WStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -31,11 +31,11 @@ public class GridDeleteAfterHandlerImpl implements IGridDeleteAfterHandler {
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handler(List<String> gridIds) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (gridIds.isEmpty()) {

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.map.IGridPointDeleteAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.util.string.WStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -27,11 +27,11 @@ public class GridPointDeleteAfterHandlerImpl implements IGridPointDeleteAfterHan
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(List<String> gridIds) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (gridIds == null || gridIds.isEmpty()) {

View File

@ -1,5 +1,6 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
@ -7,7 +8,6 @@ import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.map.IGridPointSaveAfterHandler;
import ink.wgink.module.map.pojo.dtos.grid.GridPointDTO;
import ink.wgink.module.map.service.grid.IGridPointService;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.util.UUIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -33,11 +33,11 @@ public class GridPointSaveAfterHandlerImpl implements IGridPointSaveAfterHandler
@Autowired
private IGridPointService gridPointService;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(String gridId) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(gridId)) {

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.map.IGridRelationDeleteAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.util.string.WStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -28,11 +28,11 @@ public class GridRelationDeleteAfterHandlerImpl implements IGridRelationDeleteAf
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(List<String> relationIds) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (relationIds.isEmpty()) {

View File

@ -1,5 +1,6 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
@ -8,7 +9,6 @@ import ink.wgink.interfaces.map.IGridRelationSaveAfterHandler;
import ink.wgink.module.map.pojo.dtos.grid.GridDTO;
import ink.wgink.module.map.service.grid.IGridService;
import ink.wgink.pojo.dtos.user.UserDTO;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.service.user.service.IUserService;
import ink.wgink.util.string.WStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,11 +37,11 @@ public class GridRelationSaveAfterHandlerImpl implements IGridRelationSaveAfterH
@Autowired
private IGridService gridService;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(List<String> relationIds) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (relationIds.isEmpty()) {
@ -59,7 +59,7 @@ public class GridRelationSaveAfterHandlerImpl implements IGridRelationSaveAfterH
@Override
public void handle(UserDTO userDTO) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
List<GridDTO> gridDTOs = gridService.listByRelationId(userDTO.getUserId());

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.map.IGridSaveAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -27,11 +27,11 @@ public class GridSaveAfterHandlerImpl implements IGridSaveAfterHandler {
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(String gridId, String gridCode, String gridName, String fillColor, String areaCode, String areaName) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(gridId)) {

View File

@ -1,11 +1,11 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.map.IGridUpdateAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
@ -30,11 +30,11 @@ public class GridUpdateAfterHandlerImpl implements IGridUpdateAfterHandler {
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(String gridId, String gridName, String fillColor) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(gridId)) {

View File

@ -6,7 +6,6 @@ import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.role.IRoleUserDeleteAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.util.string.WStringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -30,12 +29,10 @@ public class RoleUserDeleteAfterHandlerImpl implements IRoleUserDeleteAfterHandl
private KafkaTemplate kafkaTemplate;
@Autowired
private ParamsConfigProperties paramsConfigProperties;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
@Override
public void handle(String roleId, List<String> userIds) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(roleId)) {

View File

@ -8,7 +8,6 @@ import cn.com.tenlion.usercenter.service.userexpand.IUserExpandService;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.role.IRoleUserSaveAfterHandler;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.service.role.service.IRoleUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,12 +36,10 @@ public class RoleUserSaveAfterHandlerImpl implements IRoleUserSaveAfterHandler {
private IUserExpandService userExpandService;
@Autowired
private ParamsConfigProperties paramsConfigProperties;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
@Override
public void handle(String roleId, List<String> userIds) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(roleId)) {

View File

@ -1,12 +1,12 @@
package cn.com.tenlion.usercenter.service.kafka.impl;
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.user.IUserUpdateAfterHandler;
import ink.wgink.pojo.dtos.user.UserDTO;
import ink.wgink.properties.kafka.KafkaCustomProperties;
import ink.wgink.service.user.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,11 +31,11 @@ public class UserUpdateAfterHandlerImpl implements IUserUpdateAfterHandler {
@Autowired
private IUserService userService;
@Autowired
private KafkaCustomProperties kafkaCustomProperties;
private ParamsConfigProperties paramsConfigProperties;
@Override
public void handle(String userId) throws SystemException {
if (!kafkaCustomProperties.getActive()) {
if (!paramsConfigProperties.getKafkaActive()) {
return;
}
if (StringUtils.isBlank(userId)) {

View File

@ -64,7 +64,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx
@Autowired
private IMongoDataService mongoDataService;
private static final String SMC_STATE_DELETE = "delete";
private static final String SMC_STATE_ADD = "add";
private static final String SMC_STATE_BIND = "bind";
@Override
public String getRoute() {
@ -188,6 +188,35 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx
return;
}
LOG.debug("user expand properties doesn't exist, add SMC, call SMC createMeeting");
setSMCMeeting(userId, params);
return;
}
if (StringUtils.equals(SMC_STATE_BIND, smcState)) {
if (StringUtils.isBlank(userExpandPO.getSmcMeetingId())) {
LOG.debug("user expand properties doesn't have meetingId, create.");
setSMCMeeting(userId, params);
} else {
LOG.debug("have accountadd SMCno handle");
params.put("smcMeetingId", userExpandPO.getSmcMeetingId());
params.put("smcUsername", userExpandPO.getSmcUsername());
params.put("smcPassword", userExpandPO.getSmcPassword());
params.put("smcNumber", userExpandPO.getSmcNumber());
}
}
if (StringUtils.equals(SMC_STATE_DELETE, smcState) && !StringUtils.isBlank(userExpandPO.getSmcMeetingId())) {
LOG.debug("have accountdelete SMCcall SMS deleteMeeting");
HuaWeiSMCManager.deleteMeeting(userExpandPO.getSmcMeetingId());
}
}
/**
* 设置SMC会议信息
*
* @param userId
* @param params
* @throws Exception
*/
private void setSMCMeeting(String userId, Map<String, Object> params) throws Exception {
UserDTO userDTO = userBaseService.get(userId);
SMCMeetingDTO meeting = HuaWeiSMCManager.createMeeting(userDTO.getUserName(), userDTO.getUserUsername());
LOG.debug("meeting: {}", meeting);
@ -195,19 +224,6 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx
params.put("smcUsername", meeting.getUsername());
params.put("smcPassword", ISmartCityUserCenterConsts.HUAWEI_SMC_DEFAULT_PASSWORD);
params.put("smcNumber", meeting.getNumber());
return;
}
if (StringUtils.equals(SMC_STATE_ADD, smcState) && !StringUtils.isBlank(userExpandPO.getSmcMeetingId())) {
LOG.debug("have accountadd SMCno handle");
params.put("smcMeetingId", userExpandPO.getSmcMeetingId());
params.put("smcUsername", userExpandPO.getSmcUsername());
params.put("smcPassword", userExpandPO.getSmcPassword());
params.put("smcNumber", userExpandPO.getSmcNumber());
}
if (StringUtils.equals(SMC_STATE_DELETE, smcState) && !StringUtils.isBlank(userExpandPO.getSmcMeetingId())) {
LOG.debug("have accountdelete SMCcall SMS deleteMeeting");
HuaWeiSMCManager.deleteMeeting(userExpandPO.getSmcMeetingId());
}
}
@Override

View File

@ -4,16 +4,12 @@ import cn.com.tenlion.usercenter.pojo.dtos.huawei.MeetingCreateDTO;
import cn.com.tenlion.usercenter.pojo.dtos.huawei.SMCMeetingDTO;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import javax.net.ssl.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
@ -35,26 +31,20 @@ import java.util.Map.Entry;
* @date 2019年6月19日
*/
public class SMCHttpUtil {
private static final CloseableHttpClient httpclient = HttpClients.createDefault();
/**
* 请求超时时间
*/
private static Integer TIMEOUT = 3000;
private static final String getTokenUrl = "https://10.1.18.2/sys-portal/tokens";// 登陆
private static final String checkMeetingUrl = "https://10.1.18.2/sys-portal/terminalparams/search";// 会议室终端是否存在
private static final String getMeetingNumberUrl = "https://10.1.18.2/sys-portal/terminalparams";// 获取随机分配的会议终端号码
private static final String createMeetingUrl = "https://10.1.18.2/sys-portal/meetingrooms/create";// 创建会议室
private static final String deleteMeetingUrl = "https://10.1.18.2/sys-portal/meetingrooms/batch";// 删除会议室
private static final String username = "shiyuzhili";
private static final String password = "Syzl@2022wlcb";
private static String token = "";
private static long tokenTimeOut = 0L;
/** 请求超时时间 */
private static Integer TIMEOUT = 3000;
private static final String checkMeetingUrl = "https://10.25.248.213/sys-portal/terminalparams/search"; // 会议室终端是否存在
private static final String checkMeetingNameUrl = "https://10.25.248.213/sys-portal/meetingrooms/search/name"; // 会议室名称是否存在
private static final String getMeetingNumberUrl = "https://10.25.248.213/sys-portal/terminalparams"; // 获取随机分配的会议终端号码
private static final String createMeetingUrl = "https://10.25.248.213/sys-portal/meetingrooms/create"; // 创建会议室
private static final String deleteMeetingUrl = "https://10.25.248.213/sys-portal/meetingrooms/batch"; // 删除会议室
static {
try {
trustAllHttpsCertificates();
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
@ -71,7 +61,7 @@ public class SMCHttpUtil {
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
private static class TrustAllManager implements X509TrustManager {
public static class TrustAllManager implements X509TrustManager {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@ -85,39 +75,42 @@ public class SMCHttpUtil {
/**
* 删除会议室
*
* @param meetingId 会议室ID
* @return
* @throws Exception
*/
public static void deleteMeeting(String meetingId) throws Exception {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> param = new HashMap<String, String>();
public void deleteMeeting(String meetingId) throws Exception {
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
Map<String,String> param = new HashMap<String,String>();
param.put("id", meetingId);
list.add(param);
String json = JSONObject.toJSONString(list);
String result = doJson(deleteMeetingUrl, "DELETE", json);
if (result.contains("error")) {
if(result.contains("error")) {
throw new Exception("删除会议室失败");
}
}
/**
* 创建会议室
*
* @param name 名称 ( : 集宁区-张三丰)
* @param username 账号
* @return
* @throws Exception
*/
public static SMCMeetingDTO createMeeting(String name, String username) throws Exception {
public SMCMeetingDTO createMeeting(String name, String username) throws Exception {
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", username);
// 判断是否已存在
Boolean exists = checkMeetingExists(username);
if (exists) {
if(exists) {
throw new Exception("该账号已存在会议室");
}
// 判断是否已存在
// Boolean nameExists = checkMeetingNameExists(name);
// if(nameExists) {
// throw new Exception("该名称已存在会议室");
// }
// 获取随机的会议终端号码
String meetingNumber = getMeetingNumber();
String number = "0474" + meetingNumber;
@ -131,26 +124,32 @@ public class SMCHttpUtil {
create.setTerminalParam(paramBean);
String json = JSONObject.toJSONString(create);
try {
String result = doJson(createMeetingUrl, "POST", json);
if(result.contains("MEETINGROOM_NAME_EXIST")) {
throw new Exception("该名称已存在会议室");
}
SMCMeetingDTO dto = new SMCMeetingDTO();
JSONObject resultObject = JSONObject.parseObject(result);
dto.setMeetingId(resultObject.getString("id"));
dto.setNumber(number);
dto.setUsername(username);
return dto;
}catch (Exception e) {
throw e;
}
}
/**
* 获取随机的会议终端号码
*
* @return
*/
private static String getMeetingNumber() throws Exception {
private String getMeetingNumber() throws Exception {
Map<String, Object> params = new HashMap<String, Object>();
params.put("zoneid", "06e26a21-36b9-47e9-aabd-944eb7a33e23");
// params.put("zoneid", "06e26a21-36b9-47e9-aabd-944eb7a33e23");
params.put("number", 1); // 数量
String result = doPost(getMeetingNumberUrl, params, null);
if (result.contains("error")) {
if(result.contains("error")) {
throw new Exception("获取随机的会议终端号失败");
}
JSONArray jsonArray = JSONObject.parseArray(result);
@ -159,10 +158,9 @@ public class SMCHttpUtil {
/**
* 验证会议室是否已经存在
*
* @return
*/
public static Boolean checkMeetingExists(String username) throws Exception {
public Boolean checkMeetingExists(String username) throws Exception {
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", username);
params.put("accountType", "SMC");
@ -170,47 +168,56 @@ public class SMCHttpUtil {
return Boolean.parseBoolean(result);
}
private static String getHeader() {
String auth = username + ":" + password;
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
String authHeader = "Basic " + new String(encodedAuth);
return authHeader;
/**
* 验证会议室是否已经存在
* @return
*/
public Boolean checkMeetingNameExists(String name) throws Exception {
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", name);
String result = doGet(checkMeetingNameUrl, params, null);
return Boolean.parseBoolean(result);
}
private static void flashToken() throws Exception {
// Token30秒后到期, 则更新
if (tokenTimeOut == 0 || System.currentTimeMillis() + 30000 > tokenTimeOut) {
Map<String, String> property = new HashMap<String, String>();
property.put("Authorization", getHeader());
String result = doInitToken(getTokenUrl, null, property);
if (result.contains("uuid")) {
JSONObject object = JSONObject.parseObject(result);
String uuid = object.getString("uuid");
String expire = object.getString("expire");
token = uuid;
tokenTimeOut = Long.parseLong(expire);
} else {
throw new Exception("获取融合通信Token失败");
}
}
}
// private static String getHeader() {
// String auth = username + ":" + password;
// byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
// String authHeader = "Basic " + new String(encodedAuth);
// return authHeader;
// }
//
//
// private static void flashToken() throws Exception {
// // Token30秒后到期, 则更新
// if(tokenTimeOut == 0 || System.currentTimeMillis() + 30000 > tokenTimeOut) {
// Map<String,String> property = new HashMap<String, String>();
// property.put("Authorization", getHeader());
// String result = doInitToken(getTokenUrl, null, property);
// if(result.contains("uuid")) {
// JSONObject object = JSONObject.parseObject(result);
// String uuid = object.getString("uuid");
// String expire = object.getString("expire");
// token = uuid;
// tokenTimeOut = Long.parseLong(expire);
// }else {
// throw new Exception("获取融合通信Token失败");
// }
// }
// }
/**
* jsonPost请求
*
* @Description: TODO
* @param @param postUrl
* @param @param json
* @param @return
* @return String
* @throws
* @Description: TODO
* @author 崔宝铖
* @date 2019年6月19日
*/
private static String doJson(String postUrl, String type, String json) throws Exception {
flashToken();
OutputStream out = null;
BufferedReader br = null;
String response = "";// 响应内容
@ -222,10 +229,11 @@ public class SMCHttpUtil {
HttpURLConnection httpUrlConnection = (HttpURLConnection) restUrl.openConnection();
// 设置请求方式为 POST
httpUrlConnection.setRequestMethod(type);
httpUrlConnection.setRequestProperty("token", token);
httpUrlConnection.setRequestProperty("Connection", "keep-Alive");
httpUrlConnection.setRequestProperty("X-HW-ID", "697db861-bc1b-4e31-bc75-969e1ab5a9a5");
httpUrlConnection.setRequestProperty("X-HW-APPKEY", "H!UkcRIWb/lI1034/w5T3h%c5..4#8.+L-085%g!3Kq$w.vg3w$QD0!%i#nqE=83");
httpUrlConnection.setRequestProperty("Connection","keep-Alive");
//设置发送文件类型
httpUrlConnection.setRequestProperty("Content-Type", "application/json");
httpUrlConnection.setRequestProperty("Content-Type","application/json");
// 输入 输出 都打开
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setDoInput(true);
@ -236,56 +244,47 @@ public class SMCHttpUtil {
out.write(json.getBytes());
out.flush();
// 读取数据
br = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), "utf-8"));
br = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(),"utf-8"));
String line = null;
while (null != (line = br.readLine())) {
while (null != (line=br.readLine())){
response += line;
}
// 获得URL的响应状态码
status = new Integer(httpUrlConnection.getResponseCode()).toString();
} catch (Exception e) {
e.printStackTrace();
} finally {
}finally {
try {
if (out != null) {
out.close();
}
if (br != null) {
br.close();
}
if (out != null) { out.close();}
if (br != null) {br.close();}
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (!status.startsWith("2")) {
if(!status.startsWith("2")) {
System.out.println(response);
throw new Exception("请求结果状态不是200");
}
if (response.contains("error")) {
System.out.println(response);
throw new Exception("请求出现错误");
}
return response;
}
/**
* Post请求
*
* @Description: TODO
* @param @param postUrl
* @param @param param
* @param @return
* @return String
* @throws IOException
* @throws
* @Description: TODO
* @author 崔宝铖
* @date 2019年6月19日
*/
private static String doPost(String postUrl, Map<String, Object> param, JSONObject jsonObject) throws Exception {
flashToken();
private static String doPost(String postUrl, Map<String,Object> param, JSONObject jsonObject) throws Exception {
// 封装发送的请求参数
StringBuffer buffer = new StringBuffer();
if (param != null) {
if(param != null) {
buffer.append("?");
int x = 0;
for (Entry<String, Object> map : param.entrySet()) {
buffer.append(map.getKey()).append("=").append(map.getValue().toString());
@ -295,12 +294,13 @@ public class SMCHttpUtil {
x++;
}
}
URL url = new URL(postUrl);
URL url = new URL(postUrl + buffer.toString());
URLConnection urlConnection = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;
httpUrlConnection.setConnectTimeout(TIMEOUT);
// 设置请求头属性参数
httpUrlConnection.setRequestProperty("token", token);
httpUrlConnection.setRequestProperty("X-HW-ID", "697db861-bc1b-4e31-bc75-969e1ab5a9a5");
httpUrlConnection.setRequestProperty("X-HW-APPKEY", "H!UkcRIWb/lI1034/w5T3h%c5..4#8.+L-085%g!3Kq$w.vg3w$QD0!%i#nqE=83");
httpUrlConnection.setRequestProperty("charset", "UTF-8");
httpUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpUrlConnection.setRequestProperty("accept", "application/json");
@ -311,14 +311,14 @@ public class SMCHttpUtil {
String status = "";// 响应状态
PrintWriter out = null;
BufferedReader in = null;
try {
try{
// 获取URLConnection对象对应的输出流
out = new PrintWriter(httpUrlConnection.getOutputStream());
// 发送请求参数
if (buffer.toString().length() > 0) {
if(buffer.toString().length() > 0) {
out.write(buffer.toString());
}
if (jsonObject != null) {
if(jsonObject != null) {
String json = java.net.URLEncoder.encode(jsonObject.toString(), "utf-8");
out.write(json);
}
@ -333,67 +333,56 @@ public class SMCHttpUtil {
}
// 获得URL的响应状态码
status = new Integer(httpUrlConnection.getResponseCode()).toString();
} catch (Exception e) {
}catch(Exception e) {
e.printStackTrace();
} finally {
}finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
if (out != null) { out.close();}
if (in != null) {in.close();}
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (!status.startsWith("2")) {
if(!status.startsWith("2")) {
System.out.println(response);
throw new Exception("请求结果状态不是200");
}
if (response.contains("error")) {
System.out.println(response);
throw new Exception("请求出现错误");
}
return response;
}
/**
* Get请求
*
* @Description: TODO
* @param @param getUrl 请求地址
* @param @param param 请求参数
* @param @return
* @param @throws Exception
* @return RetBody<PageData>
* @throws
* @Description: TODO
* @author 崔宝铖
* @date 2019年6月19日
*/
private static String doGet(String getUrl, Map<String, Object> param, Map<String, String> property) throws Exception {
flashToken();
private static String doGet(String getUrl, Map<String,Object> param, Map<String,String> property) throws Exception {
return doInitToken(getUrl, param, property);
}
/**
* 初始化Token
*
* @param getUrl
* @param param
* @param property
* @return
* @throws Exception
*/
private static String doInitToken(String getUrl, Map<String, Object> param, Map<String, String> property) throws Exception {
private static String doInitToken(String getUrl, Map<String,Object> param, Map<String,String> property) throws Exception {
// 封装发送的请求参数
StringBuffer buffer = new StringBuffer();
if (param != null) {
if(param != null) {
buffer.append("?");
int x = 0;
for (Entry<String, Object> map : param.entrySet()) {
for(Entry<String, Object> map : param.entrySet()) {
buffer.append(map.getKey()).append("=").append(map.getValue().toString());
if (x != param.size() - 1) {
if(x != param.size()-1) {
buffer.append("&");
}
x++;
@ -405,11 +394,12 @@ public class SMCHttpUtil {
HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;
httpUrlConnection.setConnectTimeout(TIMEOUT);
// 设置请求头属性参数
httpUrlConnection.setRequestProperty("token", token);
httpUrlConnection.setRequestProperty("X-HW-ID", "697db861-bc1b-4e31-bc75-969e1ab5a9a5");
httpUrlConnection.setRequestProperty("X-HW-APPKEY", "H!UkcRIWb/lI1034/w5T3h%c5..4#8.+L-085%g!3Kq$w.vg3w$QD0!%i#nqE=83");
httpUrlConnection.setRequestProperty("charset", "UTF-8");
httpUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpUrlConnection.setRequestProperty("accept", "application/json");
if (property != null) {
if(property != null) {
for (Entry<String, String> map : property.entrySet()) {
httpUrlConnection.setRequestProperty(map.getKey(), map.getValue());
}
@ -418,7 +408,7 @@ public class SMCHttpUtil {
String status = "";// 响应状态6
PrintWriter out = null;
BufferedReader in = null;
try {
try{
// httpUrlConnection.connect();
// 定义BufferedReader输入流来读取URL的响应数据
in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), "UTF-8"));
@ -428,28 +418,21 @@ public class SMCHttpUtil {
}
// 获得URL的响应状态码
status = new Integer(httpUrlConnection.getResponseCode()).toString();
} catch (Exception e) {
}catch(Exception e) {
e.printStackTrace();
} finally {
}finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
if (out != null) { out.close();}
if (in != null) {in.close();}
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (!status.startsWith("2")) {
if(!status.startsWith("2")) {
System.out.println(response);
throw new Exception("请求结果状态不是200");
}
if (response.contains("error")) {
System.out.println(response);
throw new Exception("请求出现错误");
}
return response;
}
}

View File

@ -68,7 +68,6 @@ spring:
max-idle: 8
min-idle: 0
kafka:
active: false
bootstrap-servers: 192.168.0.103:9092
producer:
# 写入失败时重试次数。当leader节点失效一个repli节点会替代成为leader节点此时可能出现写入失败