首先实现后台管理,显示粉丝管理页面,并把数据上传到数据库
public function index(){
$data=M('mp_friends')->distinct ('openid')->select();
$this->assign('data',$data);
$this->display();
}
获取粉丝
public function getFriends(){
$access_token=getAccess_token();
$url="https://api.weixin.qq.com/cgi-bin/user/get?access_token=$access_token";
$ret=Curl::callWebServer($url, '', 'GET');
$total=$ret['total'];
$count=$ret['count'];
for($i=0;$i <$count ; $i++){
$openid = $ret['data']['openid'][$i];
$data[] = UserManage::getUserInfo($openid);
}
同步粉丝
//同步粉丝
public function sycfriends(){
$mp=getCurrentMp();
$where['mp_id']=$mp['id'];
M('mp_friends')->where($where)->delete();
include APP_PATH . 'LaneWeChat/lanewechat.php';
$ret=UserManage::getFanslist();
$openids=$ret['data']['openid'];
$arr=array();
foreach($openids as $value){
$row=array();
$row['openid']=$value;
$row['lang']='zh-CN';
$arr[]=$row;
}
$ret=UserManage::getManyUserInfo($arr);
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'));
}