什么都要ACCESS_TOKEN
那么什么是ACCESS_TOKEN?
ACCESS_TOKEN是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。
获取ACCESS_TOKEN
http请求方式: GET
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
结果:{"access_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","expires_in":7200}
获取用户列表
订阅号:500/天
https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID
*注:一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
获取用户基本信息
订阅号:500000/天
http请求方式: GET
https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
<?php ini_set(‘max_execution_time‘,864000); $APPID = ‘xxxxxxxxxxxxxx‘; $SECRET = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxx‘; $url = ‘https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=‘.$APPID.‘&secret=‘.$SECRET; $json = file_get_contents($url); $array = json_decode($json, true); $access_token = $array[‘access_token‘]; $url = ‘https://api.weixin.qq.com/cgi-bin/user/get?access_token=‘.$access_token; $json = file_get_contents($url); $array = json_decode($json, true); $openids = $array[‘data‘][‘openid‘]; foreach ($openids as $key => $openid) { echo $openid,‘<br>‘; $this->getmember($access_token, $openid); } public function getmember($access_token, $openid) { $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$access_token}&openid={$openid}&lang=zh_CN"; $json = file_get_contents($url); $array = json_decode($json, true); ........................... } ?>
时间: 2024-10-05 13:26:09