php之微信登陆
来源:互联网 发布:田村正和 知乎 编辑:程序博客网 时间:2024/04/29 16:21
微信登陆和qq登陆一样,只是微信登陆少一个不走,access_token和openid是同时获取的。
class weixinClass{
protected $appid = "";
protected $callback = "";
protected $appkey = "";
public function __construct()
{
require(dirname(__FILE__) . '/oauth.config.php');
$this->appid = $wx['appid'];
$this->callback = urlencode($wx['callback']);
$this->appkey = $wx['appkey'];
}
public function wx_login(){
$response_type = "code";
$scope = "snsapi_login";
//-------生成唯一随机串防CSRF攻击
$_SESSION['state'] = md5(uniqid(rand(), TRUE));
$login_url = "https://open.weixin.qq.com/connect/qrconnect?appid=".$this->appid.
"&redirect_uri=".$this->callback.
"&response_type=".$response_type.
"&scope=".$scope.
"&state=".$_SESSION['state']."#wechat_redirect";
header("Location:$login_url");
}
public function wx_callback(){
//--------验证state防止CSRF攻击
if($_REQUEST['state'] == $_SESSION['state']){
$grant_type = "authorization_code";
$code = $_REQUEST['code'];
$token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid.
"&secret=".$this->appkey.
"&code=".$code.
"&grant_type=".$grant_type;
$response = file_get_contents($token_url);
$params = json_decode($response, true);
if (isset($params->error))
{
echo "<h3>error:</h3>" . $msg->error;
echo "<h3>msg :</h3>" . $msg->error_description;
exit;
}
return $params;
}
else
{
return "";
}
}
function get_user_info($access_token, $openid)
{
if(!empty($access_token) && !empty($openid))
{
$user_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token.
"&openid=".$openid;
$response = file_get_contents($user_url);
$params = json_decode($response, true);
if (isset($params->error))
{
echo "<h3>error:</h3>" . $msg->error;
echo "<h3>msg :</h3>" . $msg->error_description;
exit;
}
return $params;
}else
{
return "";
}
}
}
- php之微信登陆
- php微信扫描关注登陆
- PHP微信第三方扫码登陆
- php 网站微信第三方登陆
- 第三方登录之微信登陆
- 微信小程序之详细微信登陆
- web开发第三方登陆之微信登陆
- PHP微信扫描登陆(模拟微信企业号平台登陆)
- 微信登陆 (微信PC扫码授权登陆) 简单的php代码
- 微信登陆 (微信PC扫码授权登陆) 简单的php代码
- php 微信模拟登陆 获取用户列表 群发消息
- PHP实现微信网页登陆授权开发
- 微信网页登陆授权示例-php版
- php 微信模拟登陆 获取用户列表 群发消息
- 微信登陆网页
- 微信登陆
- 微信联合登陆
- Android微信登陆
- mvc简单的下载
- PDO防注入原理分析以及使用PDO的注意事项
- 关于大型网站技术演进的思考(一)--存储的瓶颈(1)
- 管理经济学
- unburn修改root密码
- php之微信登陆
- Android游戏之屏幕类TestScreen和游戏类AndroidGame设计
- web.xml配置详解
- Status:Server sent passive reply with unroutable address. Using server address instead.
- struts2标签的日期转换问题
- 第三方应用整合ucenter
- 给按钮控件贴图的方法
- JavaScript基础
- Android----关于4.Keystore was tampered with, or password was incorrect的问题