Key Code
<html> <head> <title> jsCall WeChat to scan function test </title> <!--Quote WeChatJSLibrary--> <script type="text/javascript" src="/open/js/jweixin-1.0."></script> <!--QuotejQueryLibrary--> <script type="text/javascript" src="/jquery-1.4."></script> </head> <body> <input type="button" value="Scan" > <script type="text/javascript"> //Here [url parameters must be the URL to refer to] $.get("Get the URL of WeChat authentication parameters?url=The URL of the current page", function(data){ var jsondata=$.parseJSON(data); ({ // Turn on debug mode, the return values of all APIs called will be alerted on the client. To view the passed parameters, you can open them on the PC side. The parameter information will be printed through the log and will only be printed on the PC side. debug: false, // Required, unique identification of the official account appId: , // Required to generate a signature time stamp timestamp: "" + , // Required to generate a random string of signatures nonceStr: , // Required, signature signature: , // Required, list of JS interfaces to be used jsApiList: ['checkJsApi', 'scanQRCode'] }); }); (function (res) { alert("An error occurred:" + );//The advantage of this place is that the configuration is wrong, and the pop-up window will be incorrect, and then query according to the WeChat document. }); (function () { ({ jsApiList: ['scanQRCode'], success: function (res) { } }); //Click the button to scan the QR code ('#scanQRCode').onclick = function () { ({ needResult: 1, // The default is 0, the scan result is processed by WeChat, and 1 will directly return the scan result. scanType: ["qrCode"], // You can specify whether to scan the QR code or the 1R code, both are default success: function (res) { var result = ; // When needResult is 1, the result returned by scanning the code alert("Scan results:"+result); = result;//Because I have a link after scanning, and then jump to this page } }); }; }); </script> </body> </html>
Notes:
"Get WeChat authentication parameters"
The premise is that you can have your own WeChat development qualifications and get the correct parameters
- The unique identifier of the official account
- Signed timestamp
- Random signature string
Common errors
config:invalid signature
Solution
"The address of the current web page" -------Haha, it must be that you wrote it wrong, here must be the address of this web page you visited
It's best to test it on the server
Summarize
This is the article about calling WeChat’s QR code scanning function in js. For more related js, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!