微信批量拉取用户信息

注意:微信接口一次只能拉取10000个用户

           调用的函数本例无

直接代码: 
//一次性只能拉取到10000个人
public  function  synchronous()//dad
    {   
        set_time_limit(0);//设置超时  
        //$access_token = $obj->get_access_token();  
        $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$this->access_token;
        $ress = $this->obj->http_curl($url);
if($ress['total']>10000) {   //如果人数超过10000则重复提取
   $openidList[] = $ress['data']['openid'];
do{
$next_openid = $ress['next_openid'];
$str = "&next_openid=".$next_openid;
   $url="https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$this->access_token.$str;
   $ress = $this->obj->http_curl($url);
$openidList[] = $ress['data']['openid'];
}while(!empty($next_openid));

//将分别取出的数组合并
$i = 1;
$k = $i-1;
$list =  count( $openidList )
do{
$openidList[$i] = array_merge($openidlList[$k],$openidList[$i]);
$i+ = 1;
$k = $i-1;
}while( $i < $list );

$openidLists =$openidList[$list-1];


} else {
$openidLists = $ress['data']['openid'];
}
//var_dump($_SESSION);
        //$ress = json_decode($res,true);
        

        $total = $ress['total']; 
        header('Content-type:text/html;charset=utf8');
foreach($openidLists as $r){
$url2 = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$this->access_token."&openid=".$r."&lang=zh_CN";
$res2 =$this->obj->http_curl($url2);
            //$res2 = json_decode($resa,true);
$result = M('member')->getByOpenid($r);
$tagid_list = implode(',',$res2['tagid_list']);
if(!$result) {
$data = array(
 'subscribe' => $res2['subscribe'],
 'openid' => $res2['openid'],
 'nickname' => $res2['nickname'],
 'sex' => $res2['sex'],
 'language' => $res2['language'],
 'city' => $res2['city'],
 'province' => $res2['province'],
 'country' => $res2['country'],
 'subscribe_time' => $res2['subscribe_time'],
 'remark' => $res2['remark'],
 'headimgurl' => $res2['headimgurl'],
 'groupid' => $res2['groupid'],
 'tagid_list' => $tagid_list
);
$info = M('member')->add($data);
}
}
                     
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值