快手 移动应用 WebHook 接入指南https://mp.kuaishou.com/platformDocs/openAbility/webHook/accessGuide.html
上代码
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 快手业务接口
*/
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/kuaishou")
public class KuaishouController {
@SaIgnore
@PostMapping("/callback")
public ResponseEntity<JSONObject> callback(@RequestBody String body, HttpServletRequest request, HttpServletResponse response) {
log.info("快手回调消息来源:{}", body);
log.info("快手回调消息:{}", request.toString());
//解析请求体
JSONObject json = JSONUtil.parseObj(body);
String messageId = json.get("message_id", String.class);
//返回体
JSONObject result = new JSONObject();
//回调事件类型
String event = json.get("event", String.class);
//测试事件
if ("TEST".equals(event)) {
result.putOnce("result", 1);
result.putOnce("message_id", messageId);
} else if ("AUTHORIZE".equals(event)) {
//TODO 授权事件
} else if ("UN_AUTHORIZE".equals(event)) {
//TODO 解除授权事件
}
return ResponseEntity.ok(result);
}
}
官方一共提供了3种 回调事件,用处不大。有发布能力,直播能力,好歹也整个回调。