PHP获取微信公众号网页授权和用户信息(code、access_token、openid等)

讲解用户在微信客户端中访问第三方网页,公众号可以通过微信网页授权机制,来获取用户基本信息,进而实现业务逻辑。

获取code、access_token、openid、用户昵称、地区、性别、头像等

官方文档
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Web_Developer_Tools.html#1

开发步骤
1、引导用户进入授权页面同意授权,获取code
2、通过code换取网页授权access_token(与基础支持中的access_token不同)
3、如果需要,开发者可以刷新网页授权access_token,避免过期
4、通过网页授权access_token和openid获取用户基本信息(支持UnionID机制)

第一步:php获取网页授权

<?php
$url  = "";
$canshu = "";
$url = "https://open.weixin.qq.com/connect/oauth2/authorize";
$canshu = $canshu . "?appid=wx377e4ee3875*****e";
$canshu = $canshu . "&redirect_uri=".urlencode("http://www.yaoyiwangluo.com/php/wx2.php");
$canshu = $canshu . "&response_type=code";
$canshu = $canshu . "&scope=snsapi_userinfo";
$canshu = $canshu . "&state=123#wechat_redirect";
$url = $url . $canshu;
echo $url;

header("Location:$url");
?>

欢饮收看视频实战
https://edu.csdn.net/course/detail/27129
在这里插入图片描述

黄菊华老师QQ:45157718

发布了305 篇原创文章 · 获赞 45 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/u013818205/article/details/103609018