微信企业号,对打开链接的用户进行认证
我这里用的场景,zabbix使用微信报警,有一大堆的人会收到报警,比方说有一个人是知道并会处理报警的,他会对在微信中对报警进行确认,那么此时服务器端需要取得确认人的用户名,,以便告诉大家谁确认了报警,,本例演示了怎么样取这个用户名,代码写的比较搓啊,大神勿喷
<?php
$bbb=$_GET[‘code‘];
$corpid = "";
$corpsecret = "";
$url= "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$corpsecret";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo["access_token"];
$url2= "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=$access_token&code=$bbb";
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url2);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch2);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$UserId = $jsoninfo["UserId"];
echo $UserId;
效果如下