前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信登陆代码

微信登陆代码

作者头像
似水的流年
发布2019-12-12 16:33:37
1.2K0
发布2019-12-12 16:33:37
举报
文章被收录于专栏:电光石火电光石火

网页访问 https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=http://dopan.net/ceshiweixin.php&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect 保存以下内容至文件,回调至这个网页 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <?php $code = $_GET['code']; $state = $_GET['state']; //换成自己的接口信息 $appid = 'xxx'; $appsecret = 'xxx'; if (empty($code)) $this->error('授权失败'); $token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code'; $token = json_decode(file_get_contents($token_url)); if (isset($token->errcode)) {     echo '<h1>错误:</h1>'.$token->errcode;     echo '<br/><h2>错误信息:</h2>'.$token->errmsg;     exit; } $access_token_url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid='.$appid.'&grant_type=refresh_token&refresh_token='.$token->refresh_token; //转成对象 $access_token = json_decode(file_get_contents($access_token_url)); if (isset($access_token->errcode)) {     echo '<h1>错误:</h1>'.$access_token->errcode;     echo '<br/><h2>错误信息:</h2>'.$access_token->errmsg;     exit; } $user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token->access_token.'&openid='.$access_token->openid.'&lang=zh_CN'; //转成对象 $user_info = json_decode(file_get_contents($user_info_url)); if (isset($user_info->errcode)) {     echo '<h1>错误:</h1>'.$user_info->errcode;     echo '<br/><h2>错误信息:</h2>'.$user_info->errmsg;     exit; } //打印用户信息 echo '<pre>'; print_r($user_info); echo '</pre>'; ?> </body> </html>

如果微信开发的时候碰到了redirect_uri 参数错误的问题,尝试一下方法

如果授权文件目录为www.xxxx.com/xxx/xxx/OAuth2.0.PHP,那么回调域名就要 填www.xxxx.com/xxx/xxx

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-11-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档