Javascript-WeChat public account development, how to keep users logged on

Source: Internet
Author: User
When a user binds an openid to a business account, how does one keep the user logged on? After changing the phone number? How is the access_token used for webpage Authorization User Information cached and maintained? Is it stored in seesion? When will the session become invalid? (For example, if you close your browser on the PC end, you can bind your openid to your business account once. How can you keep the user in the logon status? After changing the phone number?
How is the access_token used for webpage Authorization User Information cached and maintained? Is it stored in seesion?
When will the session become invalid? (For example, close the browser on the PC end)

Reply content:

When a user binds an openid to a business account, how does one keep the user logged on? After changing the phone number?
How is the access_token used for webpage Authorization User Information cached and maintained? Is it stored in seesion?
When will the session become invalid? (For example, close the browser on the PC end)

When a user binds an openid to a business account, how does one keep the user logged on? After changing the phone number?

  • Method 1: Authenticate the account and use the OAuth interface to obtain the user's openid through the interface each time before entering, then read the relationship from your database and write it into the user's logon status.

  • Method 2: the user can click the menu or send a keyword to obtain the user's openid. At this time, a link or text message is returned. After the user clicks it, the user can obtain the openid in get mode, then read the relationship from your database and write it to the user logon status.

Recommendation Method 1 is officially used for commercial products.
Recommended method 2 when you are playing.

How is the access_token used for webpage Authorization User Information cached and maintained? Is it stored in seesion?

The access_token used for webpage Authorization User information isMust be cached, This has a daily interface frequency limit, so you must cache this.
There are cache services such as Memcache or redis, or ...... You can also save it to a file.
Session is generally used for user sessions. It is not guaranteed to be available here, or it is strange to do so. Add it to other friends.

When will the session become invalid? (For example, close the browser on the PC end)

The session has nothing to do with PC ..
I don't know when the session expires. It has something to do with your server settings.
There is a strange way of expiration for cookies. In the old version that was a long time ago, there were no headers, and the window was often closed.

Above.

1st problem: openid is bound to the business account. Is there any association between openid and the user's logon status? The openid account has a unique ing relationship with each public account. Even if you do not pay attention to it again, the openid between this user account and your public account remains unchanged.
2nd problems: access_token can be cached and maintained in many ways. I usually use memcache first (for example, sinaapp development, set an expiration time for the key, less than 7200 ), or xml files, or even some websites use databases.
3rd problems: the public account interface is a stateless session and does not have a session status. If it refers to the session opened in a self-developed website, the failure is when you close the webpage.
However, this situation may be caused by your mobile phone's permission or ban on the background. For example, if you did not close the webpage, But you scaled the window to the background, the process was cleared by the security software, at this time, it will also become invalid.

In fact, the landlord wants to ask the user to keep the user in the logon status after the account is bound.

There seems to be no good way. The session is stateless. If you want to make the user feel that the user is logged on all the time, the system must perform an interaction in the middle, in the custom menu, you can achieve this by automatically replying to the keyword. Others do not find a good solution. Without interaction, you cannot know who the user is.

Logon (all third-party logins) does not exist. To obtain user information, you must pass the openid through the interface. (For details, see auth2.0 ).
Access_token must be saved to the database instead of session. You can use refresh_token to refresh access_token (after successful authorization, only access_token and refresh_token will be given at the same time ).
You must first understand the logon process.

The code is obtained through the webpage authorization interface in exchange for the openid, which is then transmitted from the backend to the front-end and stored locally. Each time a user accesses a backend interface with an openid, how can he determine that the openid has been bound to a business account is logged on by default. If the front-end does not get the openid, it will go through the web page authorization interface again to finally get the openid. This is the case for the time being.

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.