This commit is contained in:
张良(004796)
2024-02-05 12:25:57 +08:00
parent df8890abdb
commit 144c5d1335
6 changed files with 140 additions and 0 deletions

View File

@@ -31,4 +31,6 @@ public class ImAppController {
ImResp resp = imService.sendMessage(LoginHelper.getUserId(), imMessageDTO);
return R.ok(resp);
}
}

View File

@@ -0,0 +1,56 @@
package com.ruoyi.web.controller.cai.app;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.yunxin.manager.YunxinManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@RestController
@RequestMapping("/api/yx/im")
@Tag(name = "Yunxin相关的接口")
@Slf4j
public class YxNotifyController {
@Autowired
private YunxinManager yunxinManager;
@PostMapping("/notify")
@Operation(hidden = true)
@SaIgnore
public R<Void> notifyYx(HttpServletRequest request) throws IOException {
String appKey = request.getHeader("AppKey");
String curTime = request.getHeader("CurTime");
String md5 = request.getHeader("MD5");
String checkSum = request.getHeader("CheckSum");
log.info("request headers: AppKey = {}, CurTime = {}, " +
"MD5 = {}, CheckSum = {}", appKey, curTime, md5, checkSum);
String requestBody = readBody(request);
log.info("request body = {}", requestBody);
boolean check = yunxinManager.checkNotify(requestBody, curTime);
if(!check){
log.info("检验失败!");
return R.fail("500",null);
}
return R.ok();
}
private String readBody(HttpServletRequest request) throws IOException {
if (request.getContentLength() > 0) {
byte[] bytes = StreamUtils.copyToByteArray(request.getInputStream());
return new String(bytes, StandardCharsets.UTF_8);
} else
return null;
}
}