通过php获取用户微信openid
2016-02-29 10:34
543 查看
// 基于CI框架 // 访问开始页面 public function url() { // wxAction/oauth2 微信回调地址;微信传入code值,通过该code在wxAction/oauth2请求当前用户微信资料 // account/bind 用户账号与微信号进行绑定 $current_url = site_url('wxAction/oauth2').'?returl=account/bind'; echo 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.W_APPID.'&redirect_uri='.urlencode($current_url).'&response_type=code&scope=snsapi_base&state=123#wechat_redirect'; }
// 微信回调地址,请求当前微信用户资料 public function oauth2() { $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".W_APPID."&secret=".W_APPSECRET."&code=".$_GET['code']."&grant_type=authorization_code"; $content = file_get_contents($url); $ret = json_decode($content, true); if (isset($ret['openid'])) { $this->session->set_userdata('OPENID', $ret['openid']); //跳转回之前的页面 if ($return_url = $this->input->get('returl')) { redirect($return_url); } else { redirect('welcome'); } exit; } else { echo '网络请求繁忙,获取用户信息失败,请稍后再试!'; exit; } }
相关文章推荐
- 助店宝微信商城登录流程图
- 微信js-sdk分享,修改分享内容及链接
- 微信之旅——js安全域名接口
- 微信之旅——微信公众号
- NodeJs 开发微信公众号(一)准备工作
- Android 微信支付
- android Socket实现简单聊天小程序
- 史上最全微信运营思维导图分享
- [微信开发利器]微信内移动前端开发抓包调试工具fiddler使用教程
- 史上最全微信运营思维导图分享
- 微信/QQ机器人的实现
- 微信支付开发 c# SDK JSAPI支付开发的流程和微信大坑
- [简单实用系列] 微信分享
- 小程序:使用正则表达式去除字符串中的非数字元素
- 把一年前的java小程序开始上传,形成知识体系
- 微信开发配置文件详细注释版
- 《C#微信开发系列(3)-获取接口调用凭据》
- 谷歌大脑科学家 Caffe缔造者 贾扬清 微信讲座完整版
- 微信-弹幕是怎么搞出来的,看svg!
- iOS 微信三方登陆