The method in this article will include the subscription number and service number as well as custom menu scenarios, regardless of whether there is advanced interface permissions, there is a way to obtain basic user information, without the need to impersonate the login.
The combination of third-party websites is a frequent solution for many customers. Here's a brief introduction to getting basic information about a user and logging in directly to a third-party website.
When the public is concerned about a number, a unique OpenID is created, and we need to use it to request the server to get the basic information of the user, including the avatar, nickname, etc.
Please refer to the development documentation for more detailed instructions.
The steps to get are as follows:
1 First step: User agrees to authorize, get code
2 Step Two: Redeem the code for Web authorization Access_token
3 Step Three: Refresh Access_token (if needed)
4 Fourth Step: Pull user information (requires scope is snsapi_userinfo)
5 attached: Verify that the authorization voucher (Access_token) is valid
First, in the public platform-the Developer Center: Web page Licensing access to basic user information: Click "Modify", configure the page callback domain name
Second, the user authorized to obtain code
Required Resources:
$appid = ' ***************** ';
$appsecret = ' ************************* ';
Note: Redirect_url is a callback link address for post-authorization redirection, please use UrlEncode to process the link.
Add the configured $url = ' https://open.weixin.qq.com/connect/oauth2/authorize?appid= ' at the site entrance. $appid. ' &redirect_uri=http%3a%2f%2fjixian.c.zmit.cn%2f&response_type=code&scope=snsapi_userinfo&state= 123&connect_redirect=1#wechat_redirect ';
and request access to the appeal URL.
When the user authorizes, the callback set the domain name, and will be in the URL parameter splicing we need the code, we directly with $_get[' code ' to obtain can!
Third, through the code to obtain the website authorization Access_token and OpenID
$token _url = ' https://api.weixin.qq.com/sns/oauth2/access_token?appid= '. $appid. ' &secret= '. $appsecret. ' &code= '. $code. ' &grant_type=authorization_code ';
$token = Json_decode (file_get_contents ($token _url));
$opendid = $token->openid;
$access _token = $token->access_token;
Iv. Obtaining User Information
$info _url = ' https://api.weixin.qq.com/sns/userinfo?access_token= '. $access _token. ' &openid= '. $opendid. ' ⟨=ZH_CN ';
$info = Json_decode (file_get_contents ($info _url));
$data [' name '] = $info->nickname;
$data [' image '] = $info->headimgurl;
Print_r ($info);
Five, when access to the user's OpenID and other information, we can put it into the database, as long as there is OpenID, the equivalent of the user has logged on to the site!
Get user basic information through global access tokens using the Access_token obtained by AppID and Appsecret
1. Users can obtain the user's OpenID when they follow and reply to the message.
gh_b629c48b653e
ollB4jv7LA3tydjviJp5V9qTU_kA
1372307736
event
subscribe
The Fromusername is OpenID.
2. Then use the Access_token interface to request global access Token
Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
return Result:
{"Access_token": "Nu7kr6v9l9tqaqm5ne3otpcttzx797wxw4snd2wl2hhbqlcixldvow2l-se0i-wmollniaylawzhbyhxnjblc_ Kaa092cxkmpj5fpuqno0il7bb0exz5s5qc9umypy-rz2y441w9qgfnmntizwsjsq "," expires_in ": 7200}
3. Get more information about OpenID using the global Access_token
Https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID
Return as follows:
{
"Subscribe": 1,
"OpenID": "OLVPPJQS2BHVZWPJ5A-VTYAX4GLC",
"nickname": "Baby Hedgehog",
"Sex": 1,
"Language": "ZH_CN",
"City": "Shenzhen",
"Province": "Guangdong",
"Country": "China",
"Headimgurl": "http://wx.qlogo.cn/mmopen/ Jcdicrzblrehnnxzrudod9pmibrkis5k2f1tuq7lfjc63pyhaxgxndgmzjgdeuvzyzbfoqtuxaxsdozg6iane5ko9h30kribzgv/0 ",
"Subscribe_time": 1386160805
}
At this point, get the user's basic information.
This approach is best for users who are interested in replying to a message that welcomes the + user nickname, as shown in the response to the following public account. Scan QR code to experience.
The above is the PHP public platform for the development of the user basic information to obtain the entire content, I hope you like.