C # develop WeChat portals and applications (45) -- scan the QR code to log on to WeChat,

Source: Internet
Author: User

C # development portal and application (45) -- scan the QR code to log on,

In the previous article "C # development portal and application (41) -- code scanning and logon Processing Based on Open platforms", we introduced the process of code scanning and direct logon Based on Open Platform interfaces. This article introduces some improvements and solutions to scan the QR code to facilitate application in real projects.

1. Scan the QR code for Logon Configuration

In the preceding scan code logon process, I introduced the coexistence of account logon and scan code logon. Sometimes we may just want to allow users to scan the code to log on, that is, Account Login is not required. In this case, we can implement configuration.
For example, in a system application that is based on, I configured to allow only scanning for logon.
That is, we can configure the QR code generated by scanning the QR code on Other Logon interfaces, as shown below.


In the implemented code, we mainly use JS to control the interface display.
Generally, at the initial stage of development, we can allow account and password logon and scan code logon. Once the relevant account information is configured, we only need to scan the code to log on and block account and password logon.


The HTML code layer we need to deal with is to add an openLoginDiv to display the QR code for scanning logon.

The JS Code processing is as follows: Read the relevant information directly from the background and build a QR code on JS.

2. User scan code binding and Cancellation

Before users can log on by scanning the QR code, we need to record the user's ID in the background, that is, we need to set a function on the system for users to scan the binding, at the same time, you should also set a function to unbind the expired users.
On the QR code connection in the user list, click to scan and bind the user. In this way, the user can scan the QR code to log on directly without entering the account password.


Once the user is successfully bound, the client will find a successful binding page, as shown below.


If you have bound one of the users and then scanned the code to bind them to another user, you will be prompted to avoid repeated account binding.

In addition, if you have already bound a QR code, you can unbind it on the management interface. This allows you to unbind user accounts from the association.


The JS Code used to bind and unbind the QR code is to call the interface through JQuery.

The Process Code for unbinding the scan code is very simple. You only need to know the openid and unionid of the corresponding user record in the background.
The specific MVC controller or API code is as follows.

In the underlying BLL code, we only need to update the specified two fields. The code for clearing them is as follows.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.