微信批量拉取用户信息

    xiaoxiao2021-03-25  104

    注意:微信接口一次只能拉取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); } }                           }

    转载请注明原文地址: https://ju.6miu.com/read-40453.html

    最新回复(0)