微信公众号获取用户openid

在测试号管理平台修改网页账号,填上自己的毁掉域名

微信网页授权官方文档

index.php



$appid='你的appid';

$redirect_uri = urlencode('http://你的域名或ip/getUserInfo.php');

$url ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";

header("Location:".$url);


getInfoUser.php



$appid = "wx8e87904d5555c9a8";

$secret = "045e53ab252477f52c6e1209dff83d43"; $code = $_GET["code"];

//取得openid

$oauth2Url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code";

$rs=file_get_contents($oauth2Url);

print_r($rs);

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容