码迷,mamicode.com
首页 > 微信 > 详细

[微信开发]之拉取粉丝数据

时间:2015-10-14 12:48:12      阅读:541      评论:0      收藏:0      [点我收藏+]

标签:

什么都要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);
        ...........................
    }
?>


[微信开发]之拉取粉丝数据

标签:

原文地址:http://my.oschina.net/AStar/blog/516952

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!