微信企业号OAuth2.0验证接口来获取成员的身份信息
<?php $appid = "请输入您企业的appid";
$secret = "请输入您企业的secreat"; if (!isset($_GET['code'])) {
$this->redirect($this->qychat->getOauthRedirect($this->getUrl(), 'STATE', 'snsapi_userinfo', '1000003'));
}
$code = $_GET["code"]; //获取登录进来的用户code header('content-type:text/html;charset=utf-8');//一定要加上这段代码,一定一定切记切记
$get_token_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' . $appid . '&corpsecret=' . $secret . '';
$access_token = json_decode(file_get_contents($get_token_url));
$access_tokens = $access_token->access_token; //print_r( $access_tokens ); $get_Userid = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=' . $access_tokens . '&code=' . $code . '&agentid=1000003';
$userIds = json_decode(file_get_contents($get_Userid));
$users = $userIds->UserId; if ($userIds->UserId) {
//print_r($users );
$url = "http://www.baidu.com/";
echo '<script language="JavaScript">window.location.href="跳转的页面index.html?userId=' . $users . '";</script>';
} else if ($userIds->OpenId) {
//print_r("error");
echo '<script language="JavaScript">alter("您当前未授权,请联系管理员!");</script>';
} /*
$openid = $access_token->openid;
$get_user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_tokens.'&openid='.$openid.'&lang=zh_CN'; //获取用户信息的url
$user_info = json_decode(file_get_contents($get_user_info_url)); //print_r($user_info); $_SESSION['user'] = $user_info;
echo $user_info->nickname;//得到用户信息
echo $user_info->headimgurl;
*/ public
function getOauthRedirect($callback, $state = 'STATE', $scope = 'snsapi_base', $agentid = '')
{
if ($agentid == '') {
$agentid = $this->agentid;
}
$url = self::OAUTH_PREFIX . self::OAUTH_AUTHORIZE_URL . 'appid=' . $this->appid . '&redirect_uri=' . urlencode($callback) . '&response_type=code&scope=' . $scope . '&agentid=' . $agentid . '&state=' . $state . '#wechat_redirect'; return $url; /**
* 跳转url
*/
public
function redirect($url = '/')
{
Header('Location: ' . $url);
exit;
} } ?>
微信企业号OAuth2.0验证接口来获取成员的身份信息的更多相关文章
- 微信公众号开发《一》OAuth2.0网页授权认证获取用户的详细信息,实现自动登陆
原创声明:本文为本人原创作品,绝非他处转账,转载请联系博主 从接触公众号到现在,开发维护了2个公众号,开发过程中遇到很多问题,现在把部分模块功能在这备案一下,做个总结也希望能给其他人帮助 工欲善其事, ...
- 微信企业号OAuth2验证接口实例(使用SpringMVC)
微信企业号OAuth2验证接口(使用SpringMVC) 企业应用中的URL链接(包含自己定义菜单或者消息中的链接).能够通过OAuth2.0来获取员工的身份信息. 注意.此URL的域名,必须全然匹配 ...
- Java反射理解(四)-- 获取成员变量构造函数信息
Java反射理解(四)-- 获取成员变量构造函数信息 步骤 获取成员变量信息: obj.getClass() 获取类类型对象 成员变量也是对象,java.lang.reflect.Field 类中封装 ...
- PHP微信公众平台OAuth2.0网页授权,获取用户信息代码类封装demo(二)
一.这个文件微信授权使用的是OAuth2.0授权的方式.主要有以下简略步骤: 第一步:判断有没有code,有code去第三步,没有code去第二步 第二步:用户同意授权,获取code 第三步:通过co ...
- asp.net 、C#实现微信企业号OAuth2认证
以微信企业号作为入口的应用,几乎都会遇到需要应用系统中个人信息和微信用户关联问题.从而进行其他业务处理.目前所做项目采取在企业号通讯录添加自定义字段存入应用系统用户信息表中唯一标识UserGuid进行 ...
- 微信开发——OAuth2.0授权
微信公众平台最近新推出微信认证,认证后可以获得高级接口权限,其中一个是OAuth2.0网页授权,很多朋友在使用这个的时候失败了或者无法理解其内容,希望我出个教程详细讲解一下,于是便有了这篇文章. 一. ...
- JMeter配置Oauth2.0授权接口访问
本文主要介绍如何使用JMeter配置客户端凭证(client credentials)模式下的请求 OAuth2.0介绍 OAuth 2.0 是一种授权机制,主要用来颁发令牌(token) 客户端凭证 ...
- oauth2.0协议接口-第一篇-api逻辑
开放平台是支持OAuth2.0和RESTful协议的资源分享平台,经过授权的合作伙伴可以读取和写入资讯.用户.文件.数据库等资源. 1.创建数据库表结构 CMSSyncClient(数据同步客户端) ...
- php 微信公众平台OAuth2.0网页授权,获取用户信息代码类封装demo
get_wx_data.php <?php /** * 获取微信用户信息 * @author: Lucky hypo */ class GetWxData{ private $appid = ' ...
随机推荐
- Py打开pkl文件【转载】
转自:https://blog.csdn.net/u010041824/article/details/78391683 1.打开带有中文的pkl文件或者其他字符的文件不能用默认的ascii格式打开, ...
- PHP DDOS的UDP攻击,TCP攻击,和CC攻击的核心代码
网络安全向,请勿用作非法用途 CC攻击模块: <?phpecho “状态 : 正常运行中…..<br>”;echo “================================ ...
- smali加入日志
const-string v0, "aaatag"const-string v1, "msg"invoke-static {v0,v1}, Landroid/u ...
- cocos2d JS-(JavaScript) 静态方法的例子
function User(name, age) { this.name = name; this.age = age; } var user = new User('angela',26); Use ...
- Version Control,Git的下载与安装
一.什么是Version Control(版本控制系统)? ——来自百度百科 以Git为例,是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理.Git 是 Linus ...
- linux文本文件编辑命令
1.cat命令 cat命令用于查看纯文本文件(内容较少的),格式为“cat [选项] [文件]”. Linux系统中有多个用于查看文本内容的命令,每个命令都有自己的特点,比如这个cat命令就是用于查看 ...
- python deque
Deque objects support the following methods: append(x)¶ Add x to the right side of the deque. append ...
- vm虚拟机黑屏解决办法
以管理员打开cmd 输入 netsh winsock reset --------------------- 然后 reboot
- MPI Maelstrom(East Central North America 1996)(poj1502)
MPI Maelstrom 总时间限制: 1000ms 内存限制: 65536kB 描述 BIT has recently taken delivery of their new supercom ...
- GameObject.Find与Transform.Find的区别
1.GameObject.Find 函数原型: public static GameObject Find(string name); 说明:1.GameObject只能查找到active的物体 2. ...