微信登陆网页
来源:互联网 发布:暴风影音 mac 10.6 编辑:程序博客网 时间:2024/04/30 14:15
微信开放平台
https://open.weixin.qq.com/cgi-bin/index?t=home/index&lang=zh_CN
微信登陆网站——Oauth class
<?phpclass Oauth{ private $errorMsg; private $appMsg;public function __construct(){$this->errorMsg = array( "20001" => "<h2>配置文件损坏或无法读取,请重新执行intall</h2>", "30001" => "<h2>The state does not match. You may be a victim of CSRF.</h2>", "50001" => "<h2>可能是服务器无法请求https协议</h2>可能未开启curl支持,请尝试开启curl支持,重启web服务器,如果问题仍未解决,请联系我们" );$this->appMsg = array( "appid" => "appid",//微信开放平台申请的网站应用的appid和secret "secret" => "secret", "callback" => "http://www.jenny.com/wechatcallback"//回调地址,一定要加http或者https; );}public function wechat_login(){//-------生成唯一随机串防CSRF攻击$state = md5(uniqid(rand(), TRUE));$_SESSION['state'] = $state;//-------构造请求url$callback = urlencode($this->appMsg['callback']);$login_url = "https://open.weixin.qq.com/connect/qrconnect?appid=".$this->appMsg['appid'] ."&redirect_uri=".$callback."&response_type=code&scope=snsapi_login&state=".$state."#wechat_redirect";header("Location:$login_url");}public function wechat_callback(){$state = $_SESSION['state']; //--------验证state防止CSRF攻击 if($_GET['state'] != $state){ $this->showError("30001"); } //-------请求参数列表if(!empty($_GET['code'])){//dosomething$code = $_GET['code'];$curl = curl_init();$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appMsg['appid']."&secret=".$this->appMsg['secret']."&code=".$code."&grant_type=authorization_code";curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);// 获取的信息以文件流的形式返回$result = curl_exec($curl);curl_close($curl);if( !empty($result)){$result_array = json_decode($result,true);$_SESSION['token'] = $result_array['access_token'];$_SESSION['openid'] = $result_array['openid'];header("location:/user/third?provider=wechat");}else{header("location:/login");}}else{header("location: /login");}} public function showError($code, $description = '$'){ echo "<meta charset=\"UTF-8\">"; if($description == "$"){ die($this->errorMsg[$code]); }else{ echo "<h3>error:</h3>$code"; echo "<h3>msg :</h3>$description"; exit(); } }}?>
微信登陆网站——callback控制文件
require_once($this->lib_wechatoauth_path . 'wechatoauth.php');$oauth = new Oauth();$wechat_token = $oauth->wechat_callback();
微信登陆网站——login控制文件
require_once($this->lib_wechatoauth_path . 'wechatoauth.php');$oauth = new Oauth();$wechat_token = $oauth->wechat_login();
0 0
- 微信登陆网页
- 微信网页版登陆解析
- 微信网页版登陆实现
- 微信授权网页登陆,oauth
- 微信网页二维码授权登陆
- 《五》微信网页登陆授权
- 微信OAuth2网页授权登陆接口
- 微信OAuth2网页授权登陆接口
- QQ网页微信二维码登陆原理分析
- 微信网页授权登陆的一次查错误经历
- 网页版微信和微信公共号扫码登陆原理分析
- PHP实现微信网页登陆授权开发
- 微信网页登陆授权示例-php版
- 微信网页授权登陆如何实现回调多个域名?
- 微信登陆
- 微信联合登陆
- Android微信登陆
- Android 微信登陆
- Flex 获得远程数据
- macos系统用virtualbox安装Linux系统无法设置host-only解决办法
- angularjs坑记录
- 完全卸载VC6.0
- 远程视频监控之硬件篇
- 微信登陆网页
- kafka入门例子 for java
- vb.net DataGridView 改变某个单元格字体的颜色
- Numpy 中tile(A, reps)方法
- 如何使普通用户创建的文件具有超级用户的权限呢
- 反光镜和房管局发过节费改后电饭锅好地方该死的贡献度
- 用三段 140 字符以内的代码生成一张 1024×1024 的图片
- poj 1006
- 单词、字符串儿翻转,栈实现!