PHP implements WeChat development to obtain user information

墨辰丷
Release: 2018-05-29 15:48:27
Original
2760 people have browsed it

This article mainly introduces relevant information on how to obtain user information through php WeChat development. Friends in need can refer to

php WeChat development to obtain user information

The rough algorithm for obtaining user information is

User authorization to log in to a third-party website,

Key point: scope parameter:
snsapi_basic Silent login, no user authorization is required, Only openid can be obtained;
snsapi_userinfo, the user needs to click authorization to obtain openid and all user information;

The first step: get the user's code value first;
The second step: According to Code value is used to obtain access_token. The value of each request is different. If not used, it is updated every five minutes;
Step 3: Obtain user information based on access_token;

1. Obtain code code implementation :

##getcode.php


if(isset($_SESSION['user'])){
              print_r($_SESSION['user']);
              exit;
            }

$appid='wx1d7c6fcd6131143b3';

            $redirect_url="http://www.antfortune.vip/callback.php";
            $scope='snsapi_userinfo';//获取的方式;


            $url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.urlencode($redirect_url).'&response_type=code&scope='.$scope.'&state=123#wechat_redirect';


header("Location:".$url);
Copy after login


2. Obtain access_token and openid based on code


getOpenid.php



Copy after login


The above is the entire content of this article, I hope it will be helpful to everyone’s learning help.


Related recommendations:

[WeChat development] WeChat payment parameter settings [Picture], Xin development payment parameter settings

WeChat payment development process, Xinpay development process

WeChat development code

##

The above is the detailed content of PHP implements WeChat development to obtain user information. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!