package com.tcm.training.admin.app.share.controller;
|
|
import com.tcm.training.admin.app.share.service.AppShareService;
|
import org.springframework.http.CacheControl;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.MediaType;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.concurrent.TimeUnit;
|
|
/**
|
* APP 分享二维码公开图片接口。
|
*/
|
@Validated
|
@RestController
|
@RequestMapping({"/api/open/app-share", "/api/v1/open/app-share"})
|
public class OpenAppShareController {
|
|
private final AppShareService appShareService;
|
|
/**
|
* 注入邀请分享服务。
|
*/
|
public OpenAppShareController(AppShareService appShareService) {
|
this.appShareService = appShareService;
|
}
|
|
/**
|
* 根据邀请码返回二维码 PNG 图片。
|
*/
|
@GetMapping(value = "/qrcode-image", produces = MediaType.IMAGE_PNG_VALUE)
|
public ResponseEntity<byte[]> getQrcodeImage(@RequestParam(value = "inviteCode", required = false) String inviteCode) {
|
byte[] imageBytes = appShareService.generateQrcodeImage(inviteCode);
|
return ResponseEntity.ok()
|
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"app-share-qrcode.png\"")
|
.cacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES).cachePublic())
|
.contentType(MediaType.IMAGE_PNG)
|
.body(imageBytes);
|
}
|
}
|