微信应用开发:微信登陆代码
安安 2017-09-27 来源 :网络 阅读 899 评论 0

摘要:本篇微信应用教程将为大家讲解微信登陆代码,看完这篇文章会让你对微信开发编程的知识点有更加清晰的理解和运用。

本篇微信应用教程将为大家讲解微信登陆代码,看完这篇文章会让你对微信开发编程的知识点有更加清晰的理解和运用。

 

摘要: 网页访问 https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=//dopan.net/ceshiweixin.

网页访问
https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=//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


希望这篇微信开发文章可以帮助到你。总之,同学们,你想要的职坐标微信开发频道都能找到!

本文由 @安安 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程