|
|
@@ -1,7 +1,7 @@
|
|
|
package com.etotem.cfc.controller;
|
|
|
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
-import com.etotem.cfc.service.QrCodeService;
|
|
|
+import com.etotem.cfc.service.WechatService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -10,27 +10,34 @@ import javax.annotation.Resource;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-@Tag(name = "通用工具", description = "通用工具接口(二维码等)")
|
|
|
+@Tag(name = "通用工具", description = "通用工具接口(小程序码生成等)")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/common")
|
|
|
public class CommonController {
|
|
|
|
|
|
@Resource
|
|
|
- private QrCodeService qrCodeService;
|
|
|
+ private WechatService wechatService;
|
|
|
|
|
|
- @Operation(summary = "生成二维码(通用)")
|
|
|
+ @Operation(summary = "生成小程序码(通用)")
|
|
|
@PostMapping("/qrcode")
|
|
|
public Result<Map<String, Object>> generateQrCode(@RequestBody Map<String, String> body) {
|
|
|
- String content = body.get("content");
|
|
|
- if (content == null || content.trim().isEmpty()) {
|
|
|
- return Result.error("内容不能为空");
|
|
|
+ String type = body.get("type");
|
|
|
+ String referralCode = body.get("referralCode");
|
|
|
+
|
|
|
+ if (!"register".equals(type)) {
|
|
|
+ return Result.error("不支持的二维码类型");
|
|
|
+ }
|
|
|
+ if (referralCode == null || referralCode.trim().isEmpty()) {
|
|
|
+ return Result.error("referralCode 不能为空");
|
|
|
}
|
|
|
- String qrBase64 = qrCodeService.generateQrCodeBase64(content.trim());
|
|
|
- if (qrBase64 == null) {
|
|
|
- return Result.error("生成二维码失败");
|
|
|
+
|
|
|
+ try {
|
|
|
+ String base64 = wechatService.generateWxacode("ref=" + referralCode.trim(), "pages/invite/join");
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("qrCodeBase64", "data:image/png;base64," + base64);
|
|
|
+ return Result.success(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return Result.error("生成二维码失败: " + e.getMessage());
|
|
|
}
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("qrCodeBase64", "data:image/png;base64," + qrBase64);
|
|
|
- return Result.success(result);
|
|
|
}
|
|
|
}
|