if (is_file($init)) { require $init; } $actions = array(); $handle = opendir(IA_ROOT . '/app/source/' . $controller); if (!empty($handle)) { while ($dir = readdir($handle)) { if ($dir != '.' && $dir != '..' && strexists($dir, '.ctrl.php')) { $dir = str_replace('.ctrl.php', '', $dir); $actions[] = $dir; } } } if (empty($actions)) { $str = ''; if (uni_is_multi_acid()) { $str = "&j={$_W['acid']}"; } header("location: index.php?i={$_W['uniacid']}{$str}&c=home?refresh"); } if (!in_array($action, $actions)) { $action = $acl[$controller]['default']; } if (!in_array($action, $actions)) { $action = $actions[0]; } require _forward($controller, $action); function _forward($c, $a) { $file = IA_ROOT . '/app/source/' . $c . '/' . $a . '.ctrl.php'; return $file;
function mc_oauth_userinfo($acid = 0) { global $_W; if (isset($_SESSION['userinfo'])) { $userinfo = unserialize(base64_decode($_SESSION['userinfo'])); if (!empty($userinfo['subscribe']) || !empty($userinfo['nickname'])) { return $userinfo; } } if ($_W['container'] != 'wechat') { return array(); } if (!empty($_SESSION['openid']) && intval($_W['account']['level']) >= 3) { $oauth_account = WeAccount::create($_W['account']['oauth']); $userinfo = $oauth_account->fansQueryInfo($_SESSION['openid']); if (!is_error($userinfo) && !empty($userinfo) && is_array($userinfo) && !empty($userinfo['nickname'])) { $userinfo['nickname'] = stripcslashes($userinfo['nickname']); if (!empty($userinfo['headimgurl'])) { $userinfo['headimgurl'] = rtrim($userinfo['headimgurl'], '0') . 132; } $userinfo['avatar'] = $userinfo['headimgurl']; $_SESSION['userinfo'] = base64_encode(iserializer($userinfo)); $fan = mc_fansinfo($_SESSION['openid']); if (!empty($fan)) { $record = array('updatetime' => TIMESTAMP, 'nickname' => stripslashes($userinfo['nickname']), 'follow' => $userinfo['subscribe'], 'followtime' => $userinfo['subscribe_time'], 'tag' => base64_encode(iserializer($userinfo))); pdo_update('mc_mapping_fans', $record, array('openid' => $_SESSION['openid'], 'acid' => $_W['acid'], 'uniacid' => $_W['uniacid'])); } else { $record = array(); $record['updatetime'] = TIMESTAMP; $record['nickname'] = stripslashes($userinfo['nickname']); $record['tag'] = base64_encode(iserializer($userinfo)); $record['openid'] = $_SESSION['openid']; $record['acid'] = $_W['acid']; $record['uniacid'] = $_W['uniacid']; pdo_insert('mc_mapping_fans', $record); } if (!empty($fan['uid']) || !empty($_SESSION['uid'])) { $uid = intval($fan['uid']); if (empty($uid)) { $uid = intval($_SESSION['uid']); } $member = mc_fetch($uid, array('nickname', 'gender', 'residecity', 'resideprovince', 'nationality', 'avatar')); $record = array(); if (empty($member['nickname']) && !empty($userinfo['nickname'])) { $record['nickname'] = stripslashes($userinfo['nickname']); } if (empty($member['gender']) && !empty($userinfo['sex'])) { $record['gender'] = $userinfo['sex']; } if (empty($member['residecity']) && !empty($userinfo['city'])) { $record['residecity'] = $userinfo['city'] . '市'; } if (empty($member['resideprovince']) && !empty($userinfo['province'])) { $record['resideprovince'] = $userinfo['province'] . '省'; } if (empty($member['nationality']) && !empty($userinfo['country'])) { $record['nationality'] = $userinfo['country']; } if (empty($member['avatar']) && !empty($userinfo['headimgurl'])) { $record['avatar'] = $userinfo['headimgurl']; } if (!empty($record)) { pdo_update('mc_members', $record, array('uid' => intval($uid))); } } return $userinfo; } } if (empty($_W['account']['oauth'])) { return error(-1, '未指定网页授权公众号, 无法获取用户信息.'); } if (empty($_W['account']['oauth']['key'])) { return error(-2, '公众号未设置 appId 或 secret.'); } if (intval($_W['account']['oauth']['level']) < 4) { return error(-3, '公众号非认证服务号, 无法获取用户信息.'); } $state = 'we7sid-' . $_W['session_id']; $_SESSION['dest_url'] = urlencode($_W['siteurl']); $unisetting = uni_setting($_W['uniacid']); $str = ''; if (uni_is_multi_acid()) { $str = "&j={$_W['acid']}"; } $url = (!empty($unisetting['oauth']['host']) ? $unisetting['oauth']['host'] . '/' : $_W['siteroot']) . "app/index.php?i={$_W['uniacid']}{$str}&c=auth&a=oauth&scope=userinfo"; $callback = urlencode($url); $oauth_account = WeAccount::create($_W['account']['oauth']); $forward = $oauth_account->getOauthUserInfoUrl($callback, $state); header('Location: ' . $forward); exit; }
function murl($segment, $params = array(), $noredirect = true, $addhost = false) { global $_W; list($controller, $action, $do) = explode('/', $segment); if (!empty($addhost)) { $url = $_W['siteroot'] . 'app/'; } else { $url = './'; } $str = ''; if (uni_is_multi_acid()) { $str = "&j={$_W['acid']}"; } $url .= "index.php?i={$_W['uniacid']}{$str}&"; if (!empty($controller)) { $url .= "c={$controller}&"; } if (!empty($action)) { $url .= "a={$action}&"; } if (!empty($do)) { $url .= "do={$do}&"; } if (!empty($params)) { $queryString = http_build_query($params, '', '&'); $url .= $queryString; if ($noredirect === false) { $url .= '&wxref=mp.weixin.qq.com#wechat_redirect'; } } return $url; }
protected function buildSiteUrl($url) { global $_W; $mapping = array('[from]' => $this->message['from'], '[to]' => $this->message['to'], '[rule]' => $this->rule, '[uniacid]' => $_W['uniacid']); $url = str_replace(array_keys($mapping), array_values($mapping), $url); if (strexists($url, 'http://') || strexists($url, 'https://')) { return $url; } if (uni_is_multi_acid() && strexists($url, './index.php?i=') && !strexists($url, '&j=') && !empty($_W['acid'])) { $url = str_replace("?i={$_W['uniacid']}&", "?i={$_W['uniacid']}&j={$_W['acid']}&", $url); } static $auth; if (empty($auth)) { $pass = array(); $pass['openid'] = $this->message['from']; $pass['acid'] = $_W['acid']; $sql = 'SELECT `fanid`,`salt`,`uid` FROM ' . tablename('mc_mapping_fans') . ' WHERE `acid`=:acid AND `openid`=:openid'; $pars = array(); $pars[':acid'] = $_W['acid']; $pars[':openid'] = $pass['openid']; $fan = pdo_fetch($sql, $pars); if (empty($fan) || !is_array($fan) || empty($fan['salt'])) { $fan = array('salt' => ''); } $pass['time'] = TIMESTAMP; $pass['hash'] = md5("{$pass['openid']}{$pass['time']}{$fan['salt']}{$_W['config']['setting']['authkey']}"); $auth = base64_encode(json_encode($pass)); } $vars = array(); $vars['uniacid'] = $_W['uniacid']; $vars['__auth'] = $auth; $vars['forward'] = base64_encode($url); return $_W['siteroot'] . 'app/' . str_replace('./', '', url('auth/forward', $vars)); }