13404089107
2026-04-24 e24c81afde61a58d297f4b378fae95fe3385984e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);
    }
}