频道栏目
首页 > 资讯 > 使用技巧 > 正文

微信第三方登录接口

16-01-15        来源:[db:作者]  
收藏   我要投稿
      随着手机微信的崛起,腾讯发布的微信联登确实很诱惑pc端的伙伴们,现在就说说在pc端用微信扫一扫实现微信第三方登陆的方式。

 
   第一步:获取AppID  AppSecret (不做解释,自己去微信公众平台申请)

第二步:生成扫描二维码,获取code
第三步:通过code获取access_token
https://api.weixin.qq.com/sns/oauth2/access_token?appid=AppID&secret=AppSecret&code=00294221aeb06261d5966&grant_type=authorization_code
第四步:因接口频率有次数限制,如果需要,刷新access_token
https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=AppID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN
 
     第步:通过access_token和openid获取用户的基础信息,包括头像、昵称、性别、地区
https://api.weixin.qq.com/sns/userinfo?access_token=bezXEiiBSKSxW0eoblIewFNHqAG-PyW9OqI_L81E4ZCi2cFpfoJTyQc0xKlPPCtqK1kLJfiRbVrpoOVLw7fjpqh52bn7C68SHa2HSgYsVPXZPvJvtayDa57-_7TeHYw&openid=o39YsbmuV_bIPGpj1MTe


这是接口在线调试工具:
http://mp.weixin.qq.com/debug/
这是错误码说明文档:
http://mp.weixin.qq.com/wiki/17/fa4e1434e57290788bde25603fa2fcbd.html 
另外需要特别注意,如果开发者有在多个公众号,或在公众号、移动应用之间统一用户帐号的需求,需要前往微信开放平台(open.weixin.qq.com)绑定公众号后,才可利用UnionID机制来满足上述需求,文档:
http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html

嗯~ 嗯~ 也不是很难·· 祝各位顺利!
 
 
'text' , 'name'=>'APP_KEY', 'value'=>''),
        array('type'=>'text' , 'name' => 'APP_SECRET' , 'value' => ''),
    );
}
 
 
if (!defined('WEBSITE'))
{
    include_once(dirname(__FILE__).'/oath2.class.php');
    class website extends oath2
    {
        function website()
        {
            $this->app_key = APP_KEY;
            $this->app_secret = APP_SECRET;
             
            $this->scope = 'snsapi_login';
            //by tiandi authorizeURL是用来PHP打开微信登录时用,JS调用则不用authorizeURL。
            $this->authorizeURL = 'https://open.weixin.qq.com/connect/qrconnect';
 
            $this->tokenURL = 'https://api.weixin.qq.com/sns/oauth2/access_token';
            $this->refreshtokenURL = 'https://api.weixin.qq.com/sns/oauth2/refresh_token';
            $this->userURL = 'https://api.weixin.qq.com/sns/userinfo';
            $this->meth = 'GET';
        }
 
        function Code2Token($code)
        {
            $params  = 'appid='.$this->app_key.'&secret='.$this->app_secret.'&code='.$code.
                '&grant_type=authorization_code';
            $tokenurl = $this->tokenURL."?". $params;
            $token = $this->http($tokenurl, 'GET');
            $token = json_decode($token , true);
            return $token;
        }
 
        function GetRefreshToken($token)
        {
            $params  = 'appid='.$this->app_key.'&grant_type=refresh_token&refresh_token='.$token;
            $tokenurl = $this->refreshtokenURL."?". $params;
            $token = $this->http($tokenurl, 'GET');
            $token = json_decode($token , true);
            return $token;
        }
         
        function Getinfo($token,$openid)
        {
            $params = 'access_token='.$token.'&openid='.$openid;
            $userurl = $this->userURL."?". $params;
            $userinfo = $this->http($userurl, 'GET');
            return json_decode($userinfo , true);
        }
    }
}

 

 
相关TAG标签
上一篇:微信支付
下一篇:微信客户端自带的Js Api:WeixinJSBridge
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站