Home > WeChat Applet > Mini Program Development > How to obtain QR code from WeChat applet

How to obtain QR code from WeChat applet

不言
Release: 2018-06-26 16:55:51
Original
4271 people have browsed it

This article mainly introduces the relevant information on the detailed explanation of the example of obtaining the QR code by the WeChat applet. Friends in need can refer to the following

The detailed explanation of the example of obtaining the QR code by the WeChat applet

Theory:

Interface A: Suitable for business scenarios that require a small number of codes Interface address: (Permanently valid, limited quantity, enter the corresponding path Page)

https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN
  path  String   不能为空,最大长度 128 字节
  width  Int   430(默认)   二维码的宽度
  auto_color 。。
  line_color 。。
Copy after login

Interface B: Suitable for business scenarios that require an extremely large number of codes or are only used temporarily (valid permanently, There is no limit to the quantity, and the homepage will be opened uniformly)

http://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN
  scene  String 最大32个可见字符
  width  Int   430(默认)   二维码的宽度
Copy after login

//开发者需在首页根据获取的码中 scene 字段的值,再做处理逻辑。如下示例
Page({
 onLoad: function(options) {
  var scene = options.scene
 }
})
Copy after login

Interface C : Suitable for business scenarios that require a small number of codes (permanently valid, limited quantity, enter the page corresponding to the path)

https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN
  path  String   不能为空,最大长度 128 字节
  width  Int   430(默认)   二维码的宽度
Copy after login

Bug & Tip

  tip:调用接口,POST传参。
  tip:通过该接口,仅能生成已发布的小程序的二维码。
  tip:可以在开发者工具预览时生成开发版的带参二维码。
  tip:接口A加上接口C,总共生成的码数量限制为100,000,请谨慎调用。
  tip: POST 参数需要转成 json 字符串,不支持 form 表单提交。
  tip: auto_color line_color 参数仅对小程序码生效。
Copy after login

Code

1. The interface requires access_token, which is the globally unique interface calling credential for the official account.

2. The storage of access_token must reserve at least 512 characters of space.

3. The validity period of access_token is currently 2 hours and needs to be refreshed regularly. Repeated acquisition will cause the last access_token to become invalid.

wx.request({
 // 获取token
 url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential',
 data: {
  appid: '***',
  secret: '***'
 },
 success(res) {
  wx.request({
   // 调用接口C
   url: 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=' + res.data.access_token,
   method: 'POST',
   data: {
    "path": "pages/meiTuan/meiTuan",
    "width": 430
   },
   success(res) {
    // res是二进制流,后台获取后,直接保存为图片,然后将图片返回给前台
    // 后台二进制怎么转图片?我也不会后台,学会了再贴代码
   }
  })
 }
})
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to Gesture Unlocking in WeChat Mini Program Development

WeChat Mini Program Train Ticket Inquiry Code

Design code for the password input box in the WeChat applet

##

The above is the detailed content of How to obtain QR code from WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template