Commit 894e1817 by 罗长华

调整路由回调请求逻辑

parent 9194ccbd
......@@ -3,6 +3,8 @@ package com.wecloud.im.service.impl;
import io.geekidea.springbootplus.framework.shiro.signature.SignUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
......@@ -15,7 +17,6 @@ import org.springframework.web.client.RestTemplate;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.id.NanoId;
import cn.hutool.core.util.EscapeUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
......@@ -80,12 +81,10 @@ public class ImCallbackServiceImpl implements ImCallbackService {
if (StringUtils.isNotBlank(subscribeUrl)) {
String appKey = application.getAppKey();
String appSecret = application.getAppSecret();
String callbackUrl = buildCallbackUrl(subscribeUrl, appKey, appSecret);
try {
ResponseEntity<Object> response = restTemplate.postForEntity(callbackUrl, buildMsgBody(conversation,
message),
Object.class);
ResponseEntity<Object> response = restTemplate.postForEntity(subscribeUrl,
buildMsgBody(conversation, message), Object.class, buildUriVariables(appKey, appSecret));
// 同步在线状态时需要接收服务提供应答,只要有 HTTP 应答码 200 即认为状态已经同步
if (response.getStatusCode().equals(HttpStatus.OK)) {
// do nothing
......@@ -126,8 +125,6 @@ public class ImCallbackServiceImpl implements ImCallbackService {
if (StringUtils.isNotBlank(subscribeUrl)) {
String appKey = application.getAppKey();
String appSecret = application.getAppSecret();
String callbackUrl = buildCallbackUrl(subscribeUrl, appKey, appSecret);
ClientOnlineStatusChangeDto body = ClientOnlineStatusChangeDto.builder()
.userId(client.getClientId())
......@@ -137,7 +134,7 @@ public class ImCallbackServiceImpl implements ImCallbackService {
.clientIp(clientIp)
.build();
try {
ResponseEntity<Object> response = restTemplate.postForEntity(callbackUrl, body, Object.class);
ResponseEntity<Object> response = restTemplate.postForEntity(subscribeUrl, body, Object.class, buildUriVariables(appKey, appSecret));
// 同步在线状态时需要接收服务提供应答,只要有 HTTP 应答码 200 即认为状态已经同步
if (response.getStatusCode().equals(HttpStatus.OK)) {
// do nothing
......@@ -158,14 +155,19 @@ public class ImCallbackServiceImpl implements ImCallbackService {
* @param
* @Return
*/
private String buildCallbackUrl(String subscribeUrl, String appKey, String appSecret) {
private Map<String, String> buildUriVariables(String appKey, String appSecret) {
Map<String, String> uriVariables = new HashMap<>();
// 计算 Signature (数据签名)
String nonce = NanoId.randomNanoId();
String date = DateUtil.formatHttpDate(new Date());
String signature = SignUtils.buildSignature(appKey, appSecret, nonce, date);
String finalUrl =
subscribeUrl + "?appKey=" + appKey + "&nonce=" + nonce + "&date=" + date + "&signature=" + EscapeUtil.escape(signature);
return finalUrl;
uriVariables.put("appKey", appKey);
uriVariables.put("nonce", nonce);
uriVariables.put("date", date);
uriVariables.put("signature", signature);
return uriVariables;
}
private Boolean isNeedSync(ImConversation conversation, ImMessage message) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment