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 :
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);
getOpenid.php <?php //获取用户openid $appid="your appid"; $appsecret="your appsecret"; $code=$_GET['code']; function getOpenID($appid,$appsecret,$code){ $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=". $appsecret."&code=".$code."&grant_type=authorization_code"; $weixin=file_get_contents($url);//通过code换取网页授权access_token $jsondecode=json_decode($weixin); //对JSON格式的字符串进行编码 $array = get_object_vars($jsondecode);//转换成数组 $openid = $array['openid'];//输出openid return $openid; } echo getOpenID($appid,$appsecret,$code);
[WeChat development] WeChat payment parameter settings [Picture], Xin development payment parameter settings
WeChat payment development process, Xinpay development process
##
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use