微信黑魔法-专注解决微信开发周边,小程序,公众号,微信机器人等技术分享

How to Login Web Page via Scanning Qrcode of a Wechat Official Account

How to Login Web Page via Scanning Qrcode of a Wechat Official Account

If you are working on how to login web page after scanning qrcode of an offical account on the web page. There are two ways to approach this.

Scan service official account

You can generate the qrcode injected with parameters. then after you scan, there will be an event triggered in your backend. Capture the event and extract the parameter, then do the authentication in the way you want.

The basic workflow:

  1. app frontend request your backend for a session.
  2. app backend call wechat api to generate a qrcode, injecte with any parameter you like.
  3. app frontend show the qrcode.
  4. user scan the qrcode of the service account.
  5. if user did not subscribe, then subscribe the official account.
  6. backend receive the scan event, extract the info and authenticate the user.

Scan subscription official account

In subscription get less programing support, but you can still achieve it by design a random code.

The basic workflow:

  1. app frontend request your backend for a session.
  2. app backend generate a random code.
  3. app frontend show the qrcode of the official account with a random code.
  4. user scan the qrcode of the subscription official account.
  5. if user did not subscribe, then subscribe the official account.
  6. user input the random code in the official account message UI.
  7. backend receive the code and authenticate the user.
  8. attach user info in your db with openid if you want.

Use an open platform to do it in the smart way.

If you doing this for one official account, it is ok. Let’s say if you want to reuse this for multiple official accounts. Maybe can use the open platform way, so you can have only 1 backend to handle multiple accounts. Wechat offer an open platform, here is the get start doc. Register an open platform need to pay 300RMB for verification, more troublesome part is, you need to register a company to be qualified to pay. So maybe using a third party open platform will be a better choice. Such as Dagui Qrcode Tool.

Key take aways