[WeChat Mini Program] About the mini program scene value scene use stepping pit record

Recently, I am working on a small program. To achieve such a function, enter different pages according to different scene values. For example, scan the QR code/small program code to enter page A, and the small program directly searches to enter page B.
Then I started writing according to the needs, and found that the scene values ​​I got were all wrong, and they were all 1001, which is the default scene value of the applet. Because the scene value I got was wrong, I started frantically looking through the official documents, Baidu to find information, and found that they were all written in the same way, and no one encountered this kind of problem. Later, I found out that the code was not written wrong. The scene value obtained in the development version (including real machine debugging and preview) and the trial version has always been virtual or the default value of 1001. The real scene value cannot be obtained, and the correct scene value can only be obtained in the official version . What a big pit, record it. The way to get the scene value is as follows:

// 一定要写在onShow中,因为onLaunch生命周期只第一次会进入,后面场景值一直是旧的,只有放在onShow中才能拿到实时的
App({
    
    
  onLaunch: function () {
    
    
  },
  onShow:function(e){
    
    
    console.log('场景值:', e.scene);
  }
})

Then record the dynamic generation of small program codes. Small programs or QR codes can be dynamically generated and need to call the official interface. Either the front-end or the back-end can be called, but it is best to call the back-end, because the front-end calls to generate small program code interfaces need to configure the domain name of the interface at the domain name of the WeChat public platform, but the domain name https://api.weixin.qq.com of WeChat is not allowed to be configured. The three interfaces for generating dynamic applet codes or QR codes can be viewed and learned on the official website.
Official address: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getQRCode.html

Guess you like

Origin blog.csdn.net/weixin_42342065/article/details/131538838