openid에 따라 사용자의 기본 정보를 가져와 데이터베이스에 저장합니다

2433 단어 open
    // openid ( )
public function loadConcerners()
{
$openidarr=$this->getOpenIds();
$concernerbaseinfolist=array();
$concernerbaseinfo=array();
$rs=M('weixin_concerner');
foreach($openidarr as $key=>$value){
$accesstoken=$this->getAccessToken();
$wxurl="https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$accesstoken."&openid=".$value."&lang=zh_CN
";
$result=$this->https_request($wxurl,null);
$arr=json_decode($result,true);

$concernerbaseinfo['subscribe']=$arr['subscribe'];
$concernerbaseinfo['openid']=$arr['openid'];
$concernerbaseinfo['nickname']=$arr['nickname'];
$concernerbaseinfo['sex']=$arr['sex'];
$concernerbaseinfo['language']=$arr['language'];
$concernerbaseinfo['city']=$arr['city'];
$concernerbaseinfo['province']=$arr['province'];
$concernerbaseinfo['country']=$arr['country'];
$concernerbaseinfo['headimgurl']=$arr['headimgurl'];
$concernerbaseinfo['subscribe_time']=$arr['subscribe_time'];
$concernerbaseinfo['unionid']=$arr['unionid'];
$concernerbaseinfo['remark']=$arr['remark'];
$concernerbaseinfo['groupid']=$arr['groupid'];

if(!$rs->where(array("openid"=>$value))->count())
{
$rs->add($concernerbaseinfo);
}
array_push($concernerbaseinfolist,$concernerbaseinfo);
}
session('concernerbaseinfolist',$concernerbaseinfolist);
$infolist=session('concernerbaseinfolist');
}
// openid
public function getOpenIds()
{
$accessoken=$this->getAccessToken();
$wxurl="https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$accessoken;
$result=$this->https_request($wxurl,null);
$arr= json_decode($result,true);
$openidarr=$arr['data']['openid'];
return $openidarr;
}

좋은 웹페이지 즐겨찾기