|
@@ -0,0 +1,91 @@
|
|
|
+package com.management.platform.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.WechatAccount;
|
|
|
+import com.management.platform.service.UserService;
|
|
|
+import com.management.platform.service.WechatAccountService;
|
|
|
+import com.management.platform.service.impl.QRCodeService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+@RequestMapping("/wxMini")
|
|
|
+public class WxMiniProgramController {
|
|
|
+ private static final String QR_CODE_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WechatAccountService wechatAccountService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QRCodeService qrCodeService;
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("generateQRCode")
|
|
|
+ public ResponseEntity<org.springframework.core.io.Resource> generateQRCode(HttpServletRequest request) {
|
|
|
+ String token = request.getHeader("Token");
|
|
|
+ User user = userService.getById(token);
|
|
|
+
|
|
|
+ WechatAccount wechatAccount = wechatAccountService.getOne(new QueryWrapper<WechatAccount>().eq("company_id", user.getCompanyId()));
|
|
|
+ if (wechatAccount==null){
|
|
|
+ throw new RuntimeException("该公司未配置相关参数");
|
|
|
+ }
|
|
|
+ //token
|
|
|
+ String accessToken = wechatAccountService.getAccessToken(user.getCompanyId(), wechatAccount.getAppId());
|
|
|
+ return qrCodeService.generateQRCodeResponse(accessToken);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量生成小程序码(返回ZIP包)
|
|
|
+ */
|
|
|
+// @RequestMapping("/batch-generate")
|
|
|
+// public ResponseEntity<org.springframework.core.io.Resource> batchGenerateQRCode(HttpServletRequest request) {
|
|
|
+// try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+// ZipOutputStream zos = new ZipOutputStream(baos)) {
|
|
|
+//
|
|
|
+// for (QRCodeRequest request : requests) {
|
|
|
+// byte[] qrCode = qrCodeService.generateQRCode(request);
|
|
|
+//
|
|
|
+// String fileName = "qrcode_" + request.getScene().hashCode() + ".png";
|
|
|
+// zos.putNextEntry(new ZipEntry(fileName));
|
|
|
+// zos.write(qrCode);
|
|
|
+// zos.closeEntry();
|
|
|
+// }
|
|
|
+//
|
|
|
+// zos.finish();
|
|
|
+//
|
|
|
+// ByteArrayResource resource = new ByteArrayResource(baos.toByteArray()) {
|
|
|
+// @Override
|
|
|
+// public String getFilename() {
|
|
|
+// return "qrcodes.zip";
|
|
|
+// }
|
|
|
+// };
|
|
|
+//
|
|
|
+// return ResponseEntity.ok()
|
|
|
+// .contentType(MediaType.parseMediaType("application/zip"))
|
|
|
+// .header(HttpHeaders.CONTENT_DISPOSITION,
|
|
|
+// "attachment; filename=\"" + resource.getFilename() + "\"")
|
|
|
+// .body(resource);
|
|
|
+//
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new RuntimeException("生成ZIP文件失败", e);
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+}
|