查询所有标签的接口如下。
https:// api.weixin.qq.com/cgi-bin/tags/get?access_token=ACCESS_TOKEN
该接口的核心代码实现如下。
1 $access_token = "-4fPq655nSH7ruHqEIIAxVyDpbRZFL4yPudfMuVhcin5PorYwWiTL7RZNuNlsS w_z_MDK5HCd4IKP0VpPBSLID41kWMOKvT1OBXvgt2UjeG1hZhdBuTF9DpG0XcMAG35ZAVjAIALMH"; 2 3 $url = "https:// api.weixin.qq.com/cgi-bin/tags/get?access_token=$access_token"; 4 $result = https_request($url); 5 var_dump($result); 6 function https_request($url, $data = null) 7 { 8 $curl = curl_init; 9 curl_setopt($curl, CURLOPT_URL, $url);10 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);11 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);12 if (!empty($data)){13 curl_setopt($curl, CURLOPT_POST, 1);14 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);15 }16 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);17 $output = curl_exec($curl);18 curl_close($curl);19 return $output;20 }
上述代码执行后,返回的结果如下。
{ "tags":[ { "id":2, "name":"星标组", "count":2 }, { "id":101, "name":"商家", "count":24 }, { "id":102, "name":"分公司", "count":2 }, { "id":103, "name":"顾客", "count":23 }, { "id":104, "name":"广东", "count":0 }, { "id":105, "name":"深圳", "count":0 } ]}
上述返回结果的参数说明如表6-3所示。
表6-3 查询所有标签结果的参数说明