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

How to obtain QR code from WeChat applet

Jun 26, 2018 pm 04:55 PM
QR code Applets WeChat applet

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu WeChat mini program officially launched

How to create a QR code using wps How to create a QR code using wps Mar 28, 2024 am 09:41 AM

How to create a QR code using wps

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

Implement card flipping effects in WeChat mini programs

WeChat applet implements image upload function WeChat applet implements image upload function Nov 21, 2023 am 09:08 AM

WeChat applet implements image upload function

What is the name of Xianyu WeChat applet? What is the name of Xianyu WeChat applet? Feb 27, 2024 pm 01:11 PM

What is the name of Xianyu WeChat applet?

Implement the drop-down menu effect in WeChat applet Implement the drop-down menu effect in WeChat applet Nov 21, 2023 pm 03:03 PM

Implement the drop-down menu effect in WeChat applet

Use WeChat applet to achieve carousel switching effect Use WeChat applet to achieve carousel switching effect Nov 21, 2023 pm 05:59 PM

Use WeChat applet to achieve carousel switching effect

Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Oct 31, 2023 pm 09:25 PM

Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library

See all articles