Current location - Quotes Website - Personality signature - Teach you step by step how to use WeChat to scan! Three-minute package
Teach you step by step how to use WeChat to scan! Three-minute package

This is my first time to develop a public account. I thought I could just copy and paste the official WeChat documents, but I didn’t expect that I was naive and crawled through one pit and fell into another! It took me an entire afternoon to do such a simple thing, so I wrote this article, hoping it can help everyone!

Step one: introduce weixin-js-sdk

Directly in the html file, use script to introduce:

or

Step 2: Permission verification configuration

Please obtain important information about timestamp, nonceStr, and signature based on your official account information. It should be noted that when debugging is set to true, the configuration success or failure information will automatically pop up, which can be used during debugging.

Step 3: Call the scan interface

We start to call the scan interface at the required button and click the event, such as:

Done A judgment process, the check is only for WeChat browser, other browsers cannot call:

Step 4: Real device test

During the real device test, it keeps prompting:

p>

errMsg:config:invalid signature

In Chinese, it is called signature invalid.

The reason for the search is because the data obtained by my signature is different from the data obtained by the official WeChat js interface signature verification tool. It is obvious that there is a problem with the obtained signature. It is because of my url configuration and front-end adjustment. It is caused by the inconsistent URL of the interface.

Step 5: Apple mobile phone test

Apple mobile phone real machine test, the error message is:

the permission value is offline verifying

< p> Translated into Chinese: Permission values ??are being verified offline

The reason for this error is that config was not executed correctly.

I continued to check the signature problem, and finally found that the background interface field was written incorrectly. I felt like crying but the signature information was still wrong.

Step 6: Android works normally, but Apple clicks have no response.

When I tested it on Android, it turned out to be fine. The scanning results were displayed perfectly, so I thought it was going to be fine. When testing on ios, I found that nothing happened when I clicked.

I spent a long time looking for the reason, it was caused by different window.location.href.

Test results:

Android: /doc/offiaccount/OA_Web_Apps/JS-SDK.html#4