首页 > 编程知识 正文

微信小程序识别二维码跳转,微信小程序提取链接或转二维码

时间:2023-05-06 20:01:15 阅读:263916 作者:1243

需求:生成微信小程序二维码并携带参数,扫码跳转指定页面 获取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); // 文件的ContentType putObjectOptions.setContentType("image/jpeg"); InputStream inputStream = null;//获取file的inputStream try { inputStream = file.getInputStream(); minioClient.putObject("xxx", "images/"+path, inputStream,putObjectOptions);//上传minio 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; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。