需求:生成微信小程序二维码并携带参数,扫码跳转指定页面
获取WxMaService对象
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setMsgDataFormat("JSON");
config.setAppid("appid");
config.setSecret("secret");
config.setToken("");
config.setAesKey("");
WxMaService wxMaService = new WxMaServiceImpl();
wxMaService.setWxMaConfig(config);
生成二维码并上传至minio,返回路径
public Map<String,Object> getQrcode() throws WxErrorException, IOException {
String scene = "spread/"+ 1;
String page = "pages/index/index";
WxMaQrcodeService qrcodeService = wxMaService.getQrcodeService();
File files = qrcodeService.createWxaCodeUnlimit(scene,page);
InputStream inputStream1 = new FileInputStream(files);
MultipartFile file = new MockMultipartFile(files.getName(),inputStream1);
String suffix = FileUtil.getExtensionName(file.getName());
String path = null;
String fileName = FileUtil.fileRename() + "." + suffix;
path = "images" + fileName;
PutObjectOptions putObjectOptions = new PutObjectOptions(file.getSize(), PutObjectOptions.MIN_MULTIPART_SIZE);
putObjectOptions.setContentType("image/jpeg");
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
minioClient.putObject("xxx", "images/"+path, inputStream,putObjectOptions);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
String u = minioClient.getObjectUrl("xxx", "images/"+path).replace("http://127.0.0.1:9000/","https://域名");
Map<String,Object> map = new LinkedHashMap<>();
map.put("url",u);
return map;
}