首先官方开发文档参考:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html

生成的二维码类型有两种:

1:永久有效,但有数量限制

POST https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN
POST https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN

2:永久有效,但无数量限制

POST https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN

我这边用的是第二个,首先需要获得ACCESS_TOKEN

public String token(String appid,String secret) throws IOException {id = 2L;CloseableHttpClient httpClient = HttpClients.createDefault();String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+ appid +"&secret="+secret;HttpPost post = new HttpPost(url);CloseableHttpResponse response =httpClient.execute(post);String string = EntityUtils.toString(response.getEntity());System.out.println(string);response.close();httpClient.close();return string;
}

第二步就是调用接口了

public String QR(String access_token) throws IOException {   int count = 0;//双引号个数
//字符串处理,截取这边不做json转换,当然你可以拿去自己改成自己想用的for (int i = 0; i < string.length(); i++) {String s = string.substring(i, i + 1);if ("\"".equals(s)) {count++;}}List<String> list = new ArrayList<String>();for (int i = 0; i < count; i = i + 2) {string = string.substring(string.indexOf("\"") + 1, string.length());String strTemp = string.substring(0, string.indexOf("\""));string = string.substring(strTemp.length() + 1);list.add(strTemp);}String access_token = list.get(1);RestTemplate rest = new RestTemplate();InputStream inputStream = null;OutputStream outputStream = null;Long sceneStr = null;//传入的参数try {String url1 = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+ access_token;Map<String,Object> param = new HashMap<>();param.put("page", "pages/unit/unit");跳转的页面param.put("scene", sceneStr);param.put("width", 430);param.put("auto_color", true);param.put("is_hyaline", true);MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();HttpEntity requestEntity = new HttpEntity(param, headers);ResponseEntity<byte[]> entity = rest.exchange(url1, HttpMethod.POST, requestEntity, byte[].class, new    Object[0]);byte[] result = entity.getBody();inputStream = new ByteArrayInputStream(result);UUID uuid = UUID.randomUUID();String filePathName = fileProperties.QRFilePath + uuid + ".png";//文件存储路径File file = new File(filePathName);if (!file.exists()){file.createNewFile();}outputStream = new FileOutputStream(file);int len = 0;byte[] buf = new byte[1024];while ((len = inputStream.read(buf, 0, 1024)) != -1) {outputStream.write(buf, 0, len);}outputStream.flush();} catch (Exception e) {e.getMessage();} finally {if(inputStream != null){try {inputStream.close();} catch (IOException e) {e.printStackTrace();}}if(outputStream != null){try {outputStream.close();} catch (IOException e) {e.printStackTrace();}}}return filePathName;
}

生成微信小程序指定页面二维码相关推荐

  1. 小程序指定页面二维码生成

    小程序生成指定页面二维码 小程序生成海报分享传播,需要生成分享页面的二维码,用户扫描这个二维码即可进入分享的这个小程序页面,对于分享者更具有指向性:也可生成"太阳码"参阅太阳码生成 ...

  2. uniapp微信小程序获取页面二维码(带有参数)

    1. 生成页面二维码(后端生成,前端需要将二维码写入文件管理器) // 获取带参数的小程序码async function getCodeImage() {let param = { id: 12345 ...

  3. 微信小程序条码、二维码生成模块

    代码地址如下: http://www.demodashi.com/demo/13994.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.c ...

  4. 微信小程序获取扫描二维码后携带的参数

    微信小程序获取扫描二维码后携带的参数 1.decodeURIComponent解析生成二维码的链接. /*** 生命周期函数--监听页面加载*/onLoad: function(options) {i ...

  5. 微信小程序扫描普通二维码跳转到小程序指定页面

    这个功能的逻辑是什么呢? 二维码就相当于是一个链接 相当于我们点击一个链接跳转到另一个页面 只不过这里是扫码的形式 如何操作 1.首先我们需要在微信公众平台的开发管理-->开发设置,找到(扫普通 ...

  6. 微信小程序扫普通二维码跳转

    最近一需求,是要做小程序扫普通二维码跳转.看了看微信文档一头雾水,写的不是很清楚. 官方文档传送门:https://developers.weixin.qq.com/miniprogram/intro ...

  7. 转【微信小程序 四】二维码生成/扫描二维码

    原文:https://blog.csdn.net/xbw12138/article/details/75213274 前端  二维码生成  二维码要求:每分钟刷新一次,模拟了个鸡肋,添加了个按分钟显示 ...

  8. 【微信小程序 四】二维码生成/扫描二维码

    前端 二维码生成 二维码要求:每分钟刷新一次,模拟了个鸡肋,添加了个按分钟显示的时间加在二维码中,起到刷新的作用,在onshow中每次打开界面就会刷新显示 var QR = require(" ...

  9. 基于JavaSSM和微信小程序的智能二维码门禁管理系统

    目录 1 引言 2 2 系统需求分析 2 2.1开发环境 2 2.2关键技术 2 2.2.1 Spring 框架 2 2.2.2 Spring MVC 框架 3 2.2.3 Mybatis 3 2.2 ...

最新文章

  1. dht11温湿度传感器c语言程序_手把手教你DIY一款性价比爆棚的温湿度计!
  2. 谷歌正式开源Model Search!自动优化并识别AI模型,最佳模版唾手可得
  3. 调研机构称明年全球数据中心基础设施支出将增长6%
  4. 【看这里】网易云信 IM 红包上线啦!最快3小时集成红包功能
  5. 微软发布Azure Pipelines,开源项目可无限制使用CI/CD
  6. ServletContext(核心内容)
  7. iframe悬浮在html上_HTML Iframe
  8. EL表达式(web作业)
  9. PowerDesigner15使用时的十五个问题
  10. 美团脱颖而出的经验_2016年脱颖而出的7个很棒的小开源项目
  11. bellman ford优先队列优化简介模板
  12. 使用WindowsHooks库制作和使用全局钩子
  13. 电视盒子内存测试软件,目前最强的电视盒子?当贝超级盒子B1测评考验!
  14. cruzer php sandisk 闪迪u盘量产工具_sandisk量产工具(闪迪U盘量产工具) 1.4
  15. 体温枪PCBA设计生产流程
  16. 子网掩码的作用和用法
  17. 树莓派 Pico Clion开发
  18. EXCEL 单元格如何显示输入的首个单引号字符
  19. Numpy piecewise报错
  20. 利用线程池来处理Excel导出功能

热门文章

  1. Thunder团队第三周 - Scrum会议1
  2. API网易考拉,根据ID取商品详情
  3. Unity热更新系列之一: bundle打包和打包策略
  4. Error: Your CLT does not support macOS 11.0. 1.00
  5. 全球最大的已泄漏密码库现可公开访问下载:你的密码有人泄漏过吗?
  6. 因为发现很多家长其实没有真的明白美音和英音的区别,所以写了这篇文章
  7. JS 基础(11月1日)
  8. datanode无法启动Block pool ID needed, but service not yet registered with NN
  9. OC 血压计 蓝牙BLE4.0 链接踩坑开发
  10. Python VTK numpy数据3D可视化