微信公众号开发:用户授权获取用户信息
来源:互联网 发布:php array_push 编辑:程序博客网 时间:2024/05/23 12:42
获取用户授权用户信息中的assesstoken调用不限次数!!!有效期两小时
header("Content-type: text/html; charset=utf-8"); $openid='';$username='';$img='';if($_COOKIE['<span style="font-family: Arial, Helvetica, sans-serif;">openid</span><span style="font-family: Arial, Helvetica, sans-serif;">']){</span>$openid=$_COOKIE['<span style="font-family: Arial, Helvetica, sans-serif;">openid</span><span style="font-family: Arial, Helvetica, sans-serif;">'];</span>$username=$_COOKIE['username'];$img=$_COOKIE['img'];}else{$code = $_GET['code'];$state = $_GET['state'];$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=公众号id&secret=公众号秘钥&code=' . $code . '&grant_type=authorization_code';$result = null;try { $result = curlGet($url); $obj = json_decode($result); $getInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $obj->access_token . "&openid=" . $obj->openid; //微信返回值 $userObj = json_decode(curlGet($getInfoUrl));} catch (Exception $e) { echo $e->getTraceAsString();}//echo $userObj->openid;die;//echo $userObj->openid;die;$openid=$userObj->openid;$username=urlencode(str_replace(array("'", "\\"), array(''), $userObj->nickname));$img=$userObj->headimgurl;setcookie('uid',$userObj->openid,time()+3*24*60*60);setcookie('username',$username,time()+3*24*60*60);setcookie('img',$img,time()+3*24*60*60);}function curlGet($url, $method = 'get', $data = ''){ $ch = curl_init(); $header = "Accept-Charset: utf-8"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $temp = curl_exec($ch); return $temp;}
0 0
- 微信公众号开发:用户授权获取用户信息
- 微信公众号开发-微信网页授权获取用户openid以及用户信息的步骤
- 微信公众号开发-微信网页授权获取用户openid以及用户信息的步骤
- 微信公众号开发授权获取用户信息流程?
- 微信公众号开发之授权获取用户信息
- 微信公众号-获取用户信息(网页授权获取)
- 微信公众号开发(四)--微信网页授权,获取用户信息
- 微信公众号获取用户信息-网页授权
- 微信网页开发授权(获取用户信息) 微信公众平台开发教程(4)
- 微信公众平台开发 网页授权获取用户基本信息
- 微信公众平台开发 网页授权获取用户基本信息
- 微信公众平台开发-网页授权获取用户基本信息
- 微信开发-网页授权获取用户信息
- 微信开发页面授权获取用户信息
- 微信公众号开发_如何获取用户信息?
- 微信公众号开发(二)获取用户信息
- 微信公众号之授权获取用户信息(获取unionid)
- 微信公众号开发二:关于授权网页获取用户微信信息注册用户的开发
- python格式转换
- 仿QQ空间用一个tableview显示多种自定义cell
- 数据持久化-plist
- HTML 颜色名
- centos网络配置
- 微信公众号开发:用户授权获取用户信息
- iOS耗电测试工具--batterydetective
- HandlerThread 的使用
- memcached学习笔记1(windows 7 64bit 环境下安装memcached)
- 配置Apache svn 服务器
- [LeetCode]016-3Sum-Closest
- Android 和 iOS 的区别
- week14---12月8日 JS内置对象——string、Date
- next()与nextLine()