微信公众号获取用户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);

getUserInfo.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);
在把链接生成二维码,



猜你喜欢

转载自blog.csdn.net/sulinxin/article/details/80273160