Skip to main content

微信服务查询所有分组信息 代码

查询所有分组 很简单

如下

/**************
* 查询所有分组
**************/

//第一步:获取access_token
$appid = ''; // 是 应用唯一标识
$appSecret = '';
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appSecret";

$result = https_request($url);
$result = json_decode($result, true);

$access_token = empty($result['access_token']) ? '' : $result['access_token'];

if(!empty($access_token))
{
//第二步:查询所有分组
$url2 = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=$access_token";
$result2 = https_request($url2);
$result2 = json_decode($result2, true);
echo"<pre>";
print_r($result2);
echo"</pre>";
}

function https_request($url, $data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}