function __construct() { global $_W; $user_agent = $_SERVER['HTTP_USER_AGENT']; if (strpos($user_agent, 'MicroMessenger') === true) { $openid = $_W['fans']['from_user']; if (empty($openid)) { $this->pub_fans = o2::getOuser(); if (empty($this->pub_fans['openid'])) { message('获取信息失败,请确保是认证服务号或者借用授权的AppId和AppSecret正确'); } $fans = pdo_fetch('SELECT * FROM' . tablename('fans') . " WHERE weid = :weid AND from_user = :from_user", array(':weid' => $_W['weid'], ':from_user' => $this->pub_fans['openid'])); $user = array('nickname' => emoji_unified_to_html($this->pub_fans['nickname']), 'gender' => $this->pub_fans['sex'], 'residecity' => $this->pub_fans['city'], 'resideprovince' => $this->pub_fans['province'], 'nationality' => $this->pub_fans['country'], 'avatar' => $this->pub_fans['headimgurl']); if (empty($fans)) { $user['createtime'] = TIMESTAMP; $user['weid'] = $_W['weid']; $user['from_user'] = $this->pub_fans['openid']; pdo_insert('fans', $user); } else { pdo_update('fans', $user, array('weid' => $_W['weid'], 'from_user' => $this->pub_fans['openid'])); } } else { $this->pub_fans = o2::getFans($openid); } } //print_r($this->pub_fans); //exit(); }