Now most of the micro-stations are through the user's micro-mail OpenID to achieve automatic login. In my previous development, the user clicks a menu, the public number returns a picture and text, the user clicks this picture and text can automatically login micro-station. But if you have an advanced interface, you can click on the menu, open the Web page can get this OpenID, to achieve automatic login.
It has been mentioned here that you have to have the privileges of the Advanced Interface (service number, enterprise number) to open the developer mode.
1. Set Callback address ↑
In the micro-credit public platform backstage "developer Center" under "Advanced Interface" under "OAuth2.0 Web page Authorization", followed by a "modified", after the click Will pop up to fill out the Callback Address dialog box. Specifically how to authorize, please click here to learn. The "modify" of this place can occur only after you have advanced interface permissions.
Note that here is the domain name, not with http://URL, and the explanation is very clear, "Authorization callback domain name configuration specification for the full domain name", that is, with the WWW and without a different two domain names. So I am here to fill in the following image of the domain name.
In this place in the diagram above, select the way to open the link to create the menu. OK, then put the above link in:
Https://open.weixin.qq.com/connect/oauth2/authorize?appid={in the micro-credit public platform background to get this appid}&redirect_uri={you fill in the callback domain under the address} &response_type=code&scope=snsapi_base&state=1#wechat_redirect
Creating a menu is OK.
Of course, you may just need to add this link to your own micro-trust admin.
3. Get Openid↑ on callback page
Careful you may have found that the link address above contains parameter scope=snsapi_base, rather than scope=snsapi_userinfo, because using the former does not require the user to click an authorization button, jump directly to the callback page, and the latter need to click the authorization button, However, it is good to click on the authorization button, one can not pay attention to the public number can also authorize, the second is authorized to get users of some information, such as nicknames, sex, location. But we are in order to use OpenID to log in, so direct selection of the former can be.
Click on the menu, after the micro-authorize processing, will jump to your submission of the callback address (here needs to be reminded that the callback address is best not with parameters, such as Xxx/?callback=from_weixin, because the micro-letter jump to your callback address also with parameters, And this parameter is what you need). Micro-mail jumps to the following URL:
Callback Address/?code=code&state=1
The code above can be obtained by $_get[' code ', using the code value and AppID to obtain OpenID and Access_token.
Here's how to do this with PHP:
The code is as follows |
Copy Code |
If ($_get[' code ']) { $code = $_get[' code '; $data = Get_by_curl (' https://api.weixin.qq.com/sns/ Oauth2/access_token?appid=appid&secret=appsrc&code= '. $code. ' &grant_type=authorization_code '); $data = Json_decode ($data); $openid = $data->openid; $access _token = $data->access_token; } function Get_by_curl ($url, $post = False) { $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1); if ($post) { curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $post); } $result = curl_exec ($ch); Curl_close ($ch); return $result; } |
This allows for OpenID and access_token, using these values, we can also use the micro-trust public platform to obtain user basic information API interface to obtain user basic information.