|
@@ -9,6 +9,7 @@ import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.im.dto.*;
|
|
|
import com.fs.im.service.IImService;
|
|
|
import com.tencentyun.TLSSigAPIv2;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -18,6 +19,7 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class ImServiceImpl implements IImService {
|
|
|
String account="system";//管理员帐号
|
|
@@ -25,23 +27,44 @@ public class ImServiceImpl implements IImService {
|
|
|
ConfigUtil configUtil;
|
|
|
@Override
|
|
|
public MsgResponseDTO sendMsg(MsgDTO msg) {
|
|
|
+ log.info("开始发送消息,消息内容: {}", msg);
|
|
|
+
|
|
|
int random = (int)(Math.random()*10000000);
|
|
|
- msg.setMsgRandom( random);
|
|
|
+ msg.setMsgRandom(random);
|
|
|
+ log.info("生成随机数: {}", random);
|
|
|
+
|
|
|
FsSysConfig fsConfig = configUtil.getSysConfig();
|
|
|
TLSSigAPIv2 api = new TLSSigAPIv2(fsConfig.getSdkAppId(), fsConfig.getSdkAppKey());
|
|
|
- String sign=api.genUserSig(account,180*86400);
|
|
|
- String url="https://console.tim.qq.com/v4/openim/sendmsg?sdkappid="+fsConfig.getSdkAppId()+"&identifier="+account+"&usersig="+sign+"&random="+random+"&contenttype=json";
|
|
|
+ String sign = api.genUserSig(account, 180*86400);
|
|
|
+ log.info("生成用户签名: {}", sign);
|
|
|
+
|
|
|
+ String url = "https://console.tim.qq.com/v4/openim/sendmsg?sdkappid=" + fsConfig.getSdkAppId() + "&identifier=" + account + "&usersig=" + sign + "&random=" + random + "&contenttype=json";
|
|
|
+ log.info("准备调用HTTP接口,URL: {}", url);
|
|
|
+
|
|
|
// 添加请求头信息
|
|
|
- Map<String, String > heads = new HashMap<>();
|
|
|
+ Map<String, String> heads = new HashMap<>();
|
|
|
// 使用json发送请求,下面的是必须的
|
|
|
heads.put("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ log.info("请求头: {}", heads);
|
|
|
+
|
|
|
+ String requestBody = JSONUtil.toJsonStr(msg);
|
|
|
+ log.info("请求体: {}", requestBody);
|
|
|
+
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
HttpResponse response = HttpRequest.post(url)
|
|
|
.headerMap(heads, false)
|
|
|
- .body(String.valueOf(JSONUtil.toJsonStr(msg)))
|
|
|
+ .body(requestBody)
|
|
|
.timeout(5 * 60 * 1000)
|
|
|
.execute();
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ log.info("HTTP请求响应状态码: {}", response.getStatus());
|
|
|
+ log.info("HTTP请求响应体: {}", response.body());
|
|
|
+ log.info("HTTP请求耗时: {}ms", endTime - startTime);
|
|
|
+
|
|
|
+ MsgResponseDTO responseDTO = JSONUtil.toBean(response.body(), MsgResponseDTO.class);
|
|
|
+ log.info("消息发送响应: {}", responseDTO);
|
|
|
|
|
|
- MsgResponseDTO responseDTO=JSONUtil.toBean(response.body(),MsgResponseDTO.class);
|
|
|
return responseDTO;
|
|
|
|
|
|
}
|
|
@@ -49,44 +72,68 @@ public class ImServiceImpl implements IImService {
|
|
|
@Override
|
|
|
public AccountImportResultDTO accountImport(AccountImportDTO dto) {
|
|
|
int random = (int)(Math.random()*10000000);
|
|
|
-
|
|
|
+ log.info("开始账号导入,请求参数: {}", dto);
|
|
|
FsSysConfig fsConfig = configUtil.getSysConfig();
|
|
|
TLSSigAPIv2 api = new TLSSigAPIv2(fsConfig.getSdkAppId(), fsConfig.getSdkAppKey());
|
|
|
- String sign=api.genUserSig(account,180*86400);
|
|
|
- String url="https://console.tim.qq.com/v4/im_open_login_svc/account_import?sdkappid="+fsConfig.getSdkAppId()+"&identifier="+account+"&usersig="+sign+"&random="+random+"&contenttype=json";
|
|
|
+ String sign = api.genUserSig(account, 180*86400);
|
|
|
+ String url = "https://console.tim.qq.com/v4/im_open_login_svc/account_import?sdkappid=" + fsConfig.getSdkAppId() + "&identifier=" + account + "&usersig=" + sign + "&random=" + random + "&contenttype=json";
|
|
|
+
|
|
|
+ log.info("准备调用腾讯IM接口,URL: {}", url);
|
|
|
// 添加请求头信息
|
|
|
- Map<String, String > heads = new HashMap<>();
|
|
|
+ Map<String, String> heads = new HashMap<>();
|
|
|
// 使用json发送请求,下面的是必须的
|
|
|
heads.put("Content-Type", "application/json;charset=UTF-8");
|
|
|
+
|
|
|
+ log.info("HTTP请求头: {}", heads);
|
|
|
+
|
|
|
+ String requestBody = JSONUtil.toJsonStr(dto);
|
|
|
+ log.info("HTTP请求体: {}", requestBody);
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
HttpResponse response = HttpRequest.post(url)
|
|
|
.headerMap(heads, false)
|
|
|
- .body(String.valueOf(JSONUtil.toJsonStr(dto)))
|
|
|
+ .body(requestBody)
|
|
|
.timeout(5 * 60 * 1000)
|
|
|
.execute();
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ log.info("HTTP响应状态码: {}", response.getStatus());
|
|
|
+ log.info("HTTP响应体: {}", response.body());
|
|
|
+ log.info("HTTP请求耗时: {}ms", endTime - startTime);
|
|
|
+ AccountImportResultDTO responseDTO = JSONUtil.toBean(response.body(), AccountImportResultDTO.class);
|
|
|
|
|
|
- AccountImportResultDTO responseDTO=JSONUtil.toBean(response.body(),AccountImportResultDTO.class);
|
|
|
+ log.info("账号导入完成,结果: {}", responseDTO);
|
|
|
return responseDTO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AccountCheckResultDTO accountCheck(AccountCheckDTO dto) {
|
|
|
+ log.info("开始账号检查,请求参数: {}", dto);
|
|
|
int random = (int)(Math.random()*10000000);
|
|
|
-
|
|
|
+ log.info("生成随机数: {}", random);
|
|
|
FsSysConfig fsConfig = configUtil.getSysConfig();
|
|
|
TLSSigAPIv2 api = new TLSSigAPIv2(fsConfig.getSdkAppId(), fsConfig.getSdkAppKey());
|
|
|
- String sign=api.genUserSig(account,180*86400);
|
|
|
- String url="https://console.tim.qq.com/v4/im_open_login_svc/account_check?sdkappid="+fsConfig.getSdkAppId()+"&identifier="+account+"&usersig="+sign+"&random="+random+"&contenttype=json";
|
|
|
+ String sign = api.genUserSig(account, 180*86400);
|
|
|
+ log.info("生成用户签名: {}", sign);
|
|
|
+ String url = "https://console.tim.qq.com/v4/im_open_login_svc/account_check?sdkappid=" + fsConfig.getSdkAppId() + "&identifier=" + account + "&usersig=" + sign + "&random=" + random + "&contenttype=json";
|
|
|
+ log.info("准备调用HTTP接口,URL: {}", url);
|
|
|
// 添加请求头信息
|
|
|
- Map<String, String > heads = new HashMap<>();
|
|
|
+ Map<String, String> heads = new HashMap<>();
|
|
|
// 使用json发送请求,下面的是必须的
|
|
|
heads.put("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ log.info("请求头: {}", heads);
|
|
|
+ String requestBody = JSONUtil.toJsonStr(dto);
|
|
|
+ log.info("请求体: {}", requestBody);
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
HttpResponse response = HttpRequest.post(url)
|
|
|
.headerMap(heads, false)
|
|
|
- .body(String.valueOf(JSONUtil.toJsonStr(dto)))
|
|
|
+ .body(requestBody)
|
|
|
.timeout(5 * 60 * 1000)
|
|
|
.execute();
|
|
|
-
|
|
|
- AccountCheckResultDTO responseDTO=JSONUtil.toBean(response.body(),AccountCheckResultDTO.class);
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ log.info("HTTP请求响应状态码: {}", response.getStatus());
|
|
|
+ log.info("HTTP请求响应体: {}", response.body());
|
|
|
+ log.info("HTTP请求耗时: {}ms", endTime - startTime);
|
|
|
+ AccountCheckResultDTO responseDTO = JSONUtil.toBean(response.body(), AccountCheckResultDTO.class);
|
|
|
+ log.info("账号检查响应: {}", responseDTO);
|
|
|
return responseDTO;
|
|
|
}
|
|
|
|