There is no wechat public account to realize the function of wechat scanning in H5

September 30, 2021 70 points heat 1 liked it 1 comment

We all know that wechat scanning is very common. It's basically used to scan code, pay attention to wechat, scan code to pay, and in addition, if the QR code to be scanned is a link, you can directly open the access, and the non linked text will be displayed directly.

However, sometimes we need to use a scan on our own webpage, and then process the results according to our own needs. What should we do? Some students feel very strange, how can there be such a demand. In fact, there are many scenarios, such as:

  • Scan the bar code on the express bill to check its progress
  • In the progress system, the production progress can be queried according to the barcode on the production order
  • Delivery system inbound and outbound scanning
  • Scan the QR code of URL type, but do not open it, only intercept the value of a parameter after the URL
  • Scan the code to get or exchange coupons and so on

    。。。

    Take a look at the application below.

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

Is it convenient? If you follow the usual steps to call the scan of wechat in your own webpage, it is not so simple. First of all, 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 number, but also to submit authentication, which is 300 yuan per year. The premise is that the enterprise identity can be registered and certified.

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

Scheme 1 (recommended)

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

Scheme 2:

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

Both of the above two schemes can be used. The first scheme is to attach the scanning results to the specified website address and then open it. The second scheme is to automatically obtain the incoming address by the interface, which is sometimes inaccurate. For example, some of the HTTPS websites can't get the incoming address, and some use various frameworks such as webpack. Therefore, scheme 1 is recommended.

The results are mainly obtained by intercepting the qrresult parameter in the URL

 <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 into your web page, then upload it to the server or virtual machine, and then visit this website in wechat, you can use it and scan it smoothly, and your domain name does not need to be filed, even the IP address can be! Test address 1 (test needs to be opened in wechat)
http://www.jiujiujin.net/testsaoyisao.htm
This item is suitable for adding a scan in your own webpage, such as the express bill number to be entered in the form.

Test address 2 (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 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 review

  • Flow card

    This function is very useful

    November 24, 2021