微信登录验证


1、步骤

 

 

 

 

 

2、实现

  准备:打开测试账号页,搜索【授权】设置安全回调域名或ip

  

 

 

 

 步骤1:组装url用来获取code (通过开发者工具访问)

https://open.weixin.qq.com/connect/oauth2/authorize?appid=自己的APPID&redirect_uri=http://自己的网址/login.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect

步骤2:创建login.php根据code获取openid和access_token

< ?php
#1.获取code
$code = $_GET['code'];

#2.获取openid和accessiontoken
$apiData = array(
'appid'=>'wx56e3e3d75414b3d0',
'secret'=>'f8ec8178c6dda48d1cb25c07304eff44',
'code'=> $code,
'grant_type'=>'authorization_code'
);
$api = "https://api.weixin.qq.com/sns/oauth2/access_token?".http_build_query($apiData);
$data = json_decode(file_get_contents($api), true);

// echo $data['access_token'];
// echo '<hr/>';
// echo $data['openid'];

# 步骤3:根据openid和access_token获取用户信息
$apiData = array(
'access_token'=> $data['access_token'],
'openid'=> $data['openid'],
'lang'=>'zh_CN'
);
$api = "https://api.weixin.qq.com/sns/userinfo?".http_build_query($apiData);
$data = json_decode(file_get_contents($api), true);

echo '<pre>';
print_r($data);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM