Blogger Information
Blog 15
fans 0
comment 0
visits 27690
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
微信扫码登陆第三方平台(不能关注公众号)
陈序员的博客
Original
2416 people have browsed it

1、首页要注册微信开放平台账号,邮箱不能和微信公众平台的一样,地址:https://open.weixin.qq.com

2、添加网站应用信息审核,添加公众号信息审核,获取开放平台的appid和密钥

3、有两种获取登陆二维码的办法,我这里使用js实现办法,因为js实现可以将二维码动态的内嵌在自己的网页中,并且可以更改二维码大小及样式,js链接:<script src="/static/common/js/lazyload.js"></script>

    代码:

    $(document).ready(function()

     {

         var obj = new WxLogin

         ({

             id:"login_container",    //二维码存放区域的id值

             appid: "",

             scope: "snsapi_login",

             redirect_uri:encodeURIComponent('http://自己的域名链接地址'),   //回调链接,需要encode

             state: "123456",   //携带安全口令

             style: "black",    //二维码黑白风格        black 黑色字体  white 白色字体

             href: ""

         });

     });

4、在回调链接中获取code和state验证,验证通过后根据code获取tokende 的值,"https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->appsecret."&code=".$code."&grant_type=authorization_code"

5、刷新或续期access_token使用,"https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=".$this->appid."&grant_type=refresh_token&refresh_token=".$refresh_token

6、检验授权凭证(access_token)是否有效,"https://api.weixin.qq.com/sns/auth?access_token=".$data['access_token']."&openid=".$data['openid']

7、获取用户信息,"https://api.weixin.qq.com/sns/userinfo?access_token=".$data['access_token']."&openid=".$data['openid']

8,到这步就大功告成了,最后附上curl请求代码

protected function https_request($url, $data = null)

    {

        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, $url);

        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

        if (!empty($data)){

            curl_setopt($curl, CURLOPT_POST, 1);

            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

        }

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        $output = curl_exec($curl);

        curl_close($curl);

        return $output;

    }



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post