WeChat public platform access to OpenID

Source: Internet
Author: User
Tags html header openid
The public platform can access the user's OpenID via an interface, but a jump is needed to get the user's information.
I have a user's table in the background, and the user will enter his information into the database, including OpenID, if they follow the public platform. Now to make a simple system, the user to participate in certain activities can earn points, points can be exchanged for gold coins, so on the page need to use OpenID to identify each user.
Now the problem is that the activity has several pages, each page needs to use OpenID, and can not restrict the user from which page to enter, would like to ask if there is no way to store the user OpenID, between the different pages passed?
Ps:session this way is not possible, browser support for the session is a problem, I grabbed a bag to do the test

Reply content:

The public platform can access the user's OpenID via an interface, but a jump is needed to get the user's information.
I have a user's table in the background, and the user will enter his information into the database, including OpenID, if they follow the public platform. Now to make a simple system, the user to participate in certain activities can earn points, points can be exchanged for gold coins, so on the page need to use OpenID to identify each user.
Now the problem is that the activity has several pages, each page needs to use OpenID, and can not restrict the user from which page to enter, would like to ask if there is no way to store the user OpenID, between the different pages passed?
Ps:session this way is not possible, browser support for the session is a problem, I grabbed a bag to do the test

There is no problem with the session support, and the session is not there. The real problem is the support for cookies, all the cookie information stored above is temporary, the exit and re-opening will result in the loss of cookies, which will naturally cause the session to expire.

In a session can fully use the session to save the user's OpenID, if it is to jump between multiple domain names, preferably in a primary domain name of the different two-level domain name, write a cookie when the domain parameters can be set, cross the main domain name will be more troublesome, generally not necessary.

Put Redis in this cache.

Access to user information requires a Web page authorization, a Web page authorization with Silent Authorization (snsapi_base) and user-aware authorization (SNSAPI_USERINFO)
You just have to use a silent authorization for OpenID.

Silent Authorization process:

Users open your page-"Jump to the authorization page-" Jump to the page you set up and get code-"according to code to get OpenID

You can save to the session after you get OpenID, this is absolutely no problem ~

You do the check first:

1. Determine if you really got the OpenID.

2. See if the server has saved session data?

3. Page jump more, the last session is saved in which domain, this to determine!

Problems that may occur:

Because PHP session requires the client's cookies to match (save Phpsessid), if the client has disabled cookies, you can put phpsessid in the URL to pass or write to the HTML header

If the number of activities is not many, you can use the Web page authorization to get OpenID

以snsapi_base为scope发起的网页授权,是用来获取进入页面的用户的openid的

You can get the user's OpenID in this way no matter which page the user comes in from. If you need to pass the user's OpenID on each page after the user enters the page, I remember PHP has a global variable _global, each page contributes the variable, or is placed on a Redis

However, in Java you can put variables in threadlocal, so that you can uniquely determine which user, do not know PHP has a similar method. If multiple users enter at the same time, you want to implement OpenID on each page, how to identify the unique user

Session is no problem, it may be that you made a mistake, there is another solution is to use HTML5 Local storage localstorage, storing cookies is also a way

It's strange that the last thing you said, the built-in browser has a problem with session support, so many of the websites that run in are working.

Support Session No PROBLEM * *

Through a text reply, and then the URL connection with the OpenID, so connected to the page can be.

Come on, take it.: https://github.com/thenbsp/wechat/blob/master/example/oauth.php

  • 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.