赞
踩
- /**
- * 获取不限制的小程序码(没有数量限制)
- *
- * @param accessToken
- * @param page
- * @return
- */
- public void getUnlimitedQRCode(String filePath, String scene, String accessToken, String page) {
-
- try (OutputStream os = new FileOutputStream(new File(filePath))) {
- //调用微信接口生成二维码
- URL url = new URL(wxUrl + "/wxa/getwxacodeunlimit?access_token=" + accessToken);
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- httpURLConnection.setRequestMethod("POST");// 提交模式
- // 发送POST请求必须设置如下两行
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- // 获取URLConnection对象对应的输出流
- PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
- // 发送请求参数
- JSONObject paramJson = new JSONObject();
- //这就是你二维码里携带的参数 String型 名称不可变
- paramJson.put("scene", scene);
- //注意该接口传入的是page而不是path
- paramJson.put("page", page);
- //这是设置扫描二维码后跳转的页面
- paramJson.put("width", 430);
- printWriter.write(paramJson.toString());
- // flush输出流的缓冲
- printWriter.flush();
-
- //开始获取数据
- BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
- int len;
- byte[] arr = new byte[1024];
- while ((len = bis.read(arr)) != -1) {
- os.write(arr, 0, len);
- os.flush();
- }
- os.close();
- bis.close();
- log.info("生成二维码成功,{}", filePath);
- } catch (Exception e) {
- log.error("getUnlimitedQRCode error", e);
- throw new BizException(BizCodeEnum.WX_QR_CODE_ERROR);
- }
-
- }

参数说明: filePath 文件路径
scene 可以放参数
accessToken 调用微信小程序凭证,不懂获取的去看官方文档
page 页面路径 如 pages/task/mybook
说明:
以上是官网链接,可以自行查看
不懂的可以留言告诉我
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。