There is no WeChat official account to enable H5 to activate WeChat scanning function

September 30, 2021 2359 points heat 3 people like it 1 comment

We all know that WeChat scanning is very common. It is basically used to scan the code to focus on WeChat, scan the code for payment, and open the access directly if the QR code to be scanned is a link, and display text directly if it is not a link.

However, sometimes we need to call and scan our own web pages, and then process the results according to our own needs. What should we do? Some students thought it strange that there was such a demand. In fact, there are many such use scenarios, such as:

  • Scan the barcode on the express bill to check its progress
  • The production progress can be queried in the progress system according to the barcode on the production order
  • Shipment system stock in/stock out scanning
  • Scan the QR code of url type but do not open it. Only the value of one parameter after the url is intercepted
  • Scan the code to get or exchange coupons, etc

    。。。

    See the following application effect.

     https://img2.sycdn.imooc.com/5b42068700012bbf02800560.jpg

Is it convenient? It is not so simple to call WeChat to scan your own web pages according to the usual steps. First, there must be a WeChat public account, which must also be submitted for authentication. We all know that it is not only necessary to register a WeChat public service account, but also necessary to submit a certificate, which is 300 yuan a year. The prerequisite for registration and certification is enterprise identity.

There are two methods to call the interface, as follows:

Scheme I (recommended):

 <a href=" http://sao315.com/w/api/saoyisao?redirect_uri= Website to receive results ">Scan</a>

Scheme II:

 <a href=" http://sao315.com/w/api/saoyisao ">Scan</a>

The above two schemes can be used. The first scheme is to attach the scanning results to the specified URL and then open it. The second scheme is to automatically obtain the origin address by the interface, which is sometimes inaccurate. For example, some https can not obtain the origin URL, and some use various frameworks such as webpack. Therefore, the first scheme is recommended.

The result is mainly obtained from the qrresult parameter in the url. Method reference:

 <script> if (location.href.indexOf("qrresult=")>-1) alert(decodeURIComponent(location.href.split("qrresult=")[1])); // This data can be processed in your program </script>

Put the above code on your web page, upload it to the server or virtual machine, and then visit the website in WeChat, you can scan it successfully, and your domain name does not need to be filed, even the IP address can be used! Test address 1 (the test needs to be opened in WeChat):
http://www.jiujiujin.net/testsaoyisao.htm
This item is suitable for adding scanning in your own web page. For example, you need to enter the express bill number in the form.

Test address 2 (the test needs to be opened in WeChat):
http://sao315.com/w/api/saoyisao?redirect_uri=http://www.jiujiujin.net/wuliu.htm
This is suitable for setting "Scan" in the WeChat menu, and then the URL points to the above URL, where redirect_uri can be changed to the address where you need to receive the QR code data. The above example is to scan the express bill number and display the logistics information.

 

Reprinted from @ Lost Rainbow Sea

Gcod

If life is just like the first sight, what is the sad autumn wind painting fan

Article comments

  • Flow card

    This function is very useful

    November 24, 2021