微信开发——粉丝同步

首先获取当先使用的公众号和初始化

  public function _initialize(){
        $mp=getCurrentMp();
        if (empty($mp)) {
                $this->error('无使用的公众号',U('mp/index'));
                exit;
        }else{
                $this->mp=$mp;
        }
        }1
    public function index(){
                $mp=$this->mp;
                $where['mp_id']=$mp['id'];
                $se=M('mp_friends')->select();
                $this->assign('se',$se);
                $this->display();
}

获取

getAccess_token
public static function getFansList($next_openid=''){  
       //获取ACCESS_TOKEN  
       $accessToken = getAccess_token();  
       if(empty($next_openid)){  
           $queryUrl = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token='.$accessToken;  
       }else{  
           $queryUrl = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token='.$accessToken.'&next_openid='.$next_openid;  
       }  
       return Curl::callWebServer($queryUrl, '', 'GET');  
   }  


调用封装好的框架,做好准备工作,开始同步,存入数据库,在浏览器可以显示

 public function getFriends(){
            $mp=$this->mp;
            $where['mp_id']=$mp['id'];
            M('mp_friends')->where($where)->delete();
            include_once APP_PATH.'LaneWeChat/lanewechat.php';
            $ret=UserManage::getFansList();
            // print_r($ret);
            // exit;
            $openids=$ret['data']['openid'];
            // print_r($openid);
            // exit;
            $arr=array();
            foreach ($openids as  &$value) {
                $row=array();
                    $row['openid']=$value;
                    $row['lang']='zh-CN';
                    $arr[]=$row;
            }
            // print_r($arr);
            // exit;
            $ret=UserManage::getManyUserInfo($arr);
            // print_r($ret);
            // exit;
            if (isset($ret['user_info_list'])) {
                    $data=$ret['user_info_list'];
                    foreach ($data as &$value) {
                            $value['mp_id']=$mp['id'];
                            $value['tagid_list']=json_encode($value['tagid_list']);
                    }
                    M('mp_friends')->addAll($data);
            }
           $this->success('同步完成',U('index'));
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值