跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] PC 端网站使用微信扫码登录

发表于

目前正在开发的业务,有微信小程序端和 PC 网页端两个版本。

小程序端的登录逻辑,是通过调用微信的接口,获取用户的 openid ,把它作为用户的身份标识。

PC 网页端为了开发方便,也想让用户通过微信扫码登录,获取用户在小程序中的 openid ,这样就可以和小程序端共用一套用户身份。

目前的整体流程如下:

  1. PC 网页端调用接口来生成小程序码,然后显示在前端页面中让用户扫码。生成小程序码时,可以传入一个 scene 参数,后端在返回小程序码时,把这个 scene 参数一并返回,前端进行存储。

  2. 微信小程序扫码,拿到 scene 参数,然后把小程序用户的 openid 和 scene 作为 key-value 传给后端存储。

  3. PC 网页端查询后端接口,检查 scene 参数是否有对应的 openid ,是的话就将 openid 存储在前端。

现在的问题是,整体流程都走通了,但是最后一步 PC 网页端查询后端接口,以怎样的间隔轮询接口才是合理的方式?

我目前想的是每隔 5 秒轮询一次,累计轮询 5 次(这个值可以调整)都没能获取到 scene 对应的 openid 的话,就认为用户没有用微信扫码,然后停止轮询,不知道这样合不合适。

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.