PHP企业微信授权
1、添加应用菜单。
2、access_token
/**
* 获取token
* @return [type] [description]
*/
public function getToken()
{
$file = "token.txt";
{
$token = file_get_contents($file);
$token = json_decode($token,true);
if(!$token['access_token'] || time()-$token['expires_in'] > 7000)
{
$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=".$this->corpid."&corpsecret=".strtoupper($this->secrect);
$token = $this->GetHttp($url);
$token = json_decode($token,true);
$token['expires_in'] = time();
file_put_contents("token.txt",json_encode($token));
return $token['access_token'];
}
else
{
$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=".$this->corpid."&corpsecret=".strtoupper($this->secrect);
$token = $this->GetHttp($url);
$token = json_decode($token,true);
$token['expires_in'] = time();
file_put_contents("token.txt",json_encode($token));
return $token['access_token'];
}
}
}
3、通过code获取user_ticket。
/**
* 获取code,getToken()返回token,获取user_ticket。
*/
function Code(){
$url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=".$this->gettoken()."&code=".$_GET['code'];
$data = $this->GetHttp($url);
$ticket = json_decode($data,true);
$arr = $this->UserTicket($ticket['user_ticket']);
echo "<pre>";
print_r($arr);
}
4、通过user_ticket获取用户信息。
/**
* user_ticket获取成员详情
*/
function UserTicket($user_ticket = ''){
$url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail?access_token=".$this->getToken();
$data = array(
'user_ticket' => $user_ticket
);
$arr = $this->Curl($url,json_encode($data));
return json_decode($arr,true);
}
最新文章
- 阻止默认事件event.preventDefault();
- Fedora 23安装配置mysql数据库,修改初始密码及登陆
- Web开发流程
- mysql本地可以访问 网络不能访问
- Knockout.Js案例一Introduction
- PHP-Beast V0.6 发布 (PHP源码加密模块)
- 使用Python中的urlparse、urllib抓取和解析网页(一)(转)
- 3、SQL基础整理(分组)
- Python 判断一个字符串是否在列表中任何一个字符串中出现过
- 使用Java Service Wrapper在Linux下配置Tomcat应用
- 【BZOJ】【1087】【SCOI2005】互不侵犯King
- CCF 201403-2	窗口 (STL模拟)
- DevExpress z
- 宁波Uber优步司机奖励政策(2月1日~2月7日)
- winform Label与DataGridView右对齐 分类: WinForm 2014-05-19 20:51 446人阅读 评论(0) 收藏
- Excel操作 Microsoft.Office.Interop.Excel.dll的使用
- bzoj 1066 : [SCOI2007]蜥蜴 网络流
- 如何在windows的DOS窗口中正常显示中文(UTF-8字符)
- socket-详细分析No buffer space available(转)
- sql 生成开始日期到结束日期与开始日期的相差天数