function checkauth() { global $_W, $engine; load()->model('mc'); if (!empty($_W['member']) && (!empty($_W['member']['mobile']) || !empty($_W['member']['email']))) { return true; } if (!empty($_W['openid'])) { $fan = mc_fansinfo($_W['openid'], $_W['acid'], $_W['uniacid']); if (_mc_login(array('uid' => intval($fan['uid'])))) { return true; } if (defined('IN_API')) { $GLOBALS['engine']->died("抱歉,您需要先登录才能使用此功能,点击此处 <a href='" . __buildSiteUrl(url('auth/login')) . "'>【登录】</a>"); } } $forward = base64_encode($_SERVER['QUERY_STRING']); if ($_W['isajax']) { $result = array(); $result['url'] = url('auth/login', array('forward' => $forward), true); $result['act'] = 'redirect'; exit(json_encode($result)); } else { header("location: " . url('auth/login', array('forward' => $forward)), true); } exit; }
function checkauth() { global $_W, $engine; load()->model('mc'); if (!empty($_W['member']) && (!empty($_W['member']['mobile']) || !empty($_W['member']['email']))) { return true; } if (!empty($_W['openid'])) { $sql = 'SELECT `fanid`,`openid`,`uid` FROM ' . tablename('mc_mapping_fans') . ' WHERE `uniacid`=:uniacid AND `openid`=:openid'; $pars = array(); $pars[':uniacid'] = $_W['uniacid']; $pars[':openid'] = $_W['openid']; if (defined('IN_API')) { $sql .= ' AND `acid`=:acid'; $pars[':acid'] = $_W['acid']; } $fan = pdo_fetch($sql, $pars); if (!empty($fan) && !empty($fan['uid'])) { if (_mc_login(array('uid' => $fan['uid']))) { return true; } else { $rec = array(); $rec['uid'] = $fan['uid'] = 0; pdo_update('mc_mapping_fans', $rec, array('fanid' => $fan['fanid'])); } } if (defined('IN_API')) { $GLOBALS['engine']->died("抱歉,您需要先登录才能使用此功能,点击此处 <a href='" . __buildSiteUrl(url('auth/login')) . "'>【登录】</a>"); } } $forward = base64_encode($_SERVER['QUERY_STRING']); if ($_W['isajax']) { $result = array(); $result['url'] = url('auth/login', array('forward' => $forward), true); $result['act'] = 'redirect'; exit(json_encode($result)); } else { header("location: " . url('auth/login', array('forward' => $forward)), true); } exit; }
$data['residecity'] = $map_fans['city'] ? $map_fans['city'] . '市' : ''; $data['resideprovince'] = $map_fans['province'] ? $map_fans['province'] . '省' : ''; $data['nationality'] = $map_fans['country']; $data['avatar'] = rtrim($map_fans['headimgurl'], '0') . 132; } pdo_update('mc_members', $data, array('uid' => $_W['member']['uid'])); $user['uid'] = $_W['member']['uid']; } else { $default_groupid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('mc_groups') . ' WHERE uniacid = :uniacid AND isdefault = 1', array(':uniacid' => $_W['uniacid'])); $data = array('uniacid' => $_W['uniacid'], 'salt' => random(8), 'groupid' => $default_groupid, 'createtime' => TIMESTAMP); if (!empty($map_fans)) { $data['nickname'] = $map_fans['nickname']; $data['gender'] = $map_fans['sex']; $data['residecity'] = $map_fans['city'] ? $map_fans['city'] . '市' : ''; $data['resideprovince'] = $map_fans['province'] ? $map_fans['province'] . '省' : ''; $data['nationality'] = $map_fans['country']; $data['avatar'] = rtrim($map_fans['headimgurl'], '0') . 132; } $type == 'email' ? $data['email'] = $username : ($data['mobile'] = $username); $data['password'] = md5($password . $data['salt'] . $_W['config']['setting']['authkey']); pdo_insert('mc_members', $data); $user['uid'] = pdo_insertid(); } if (_mc_login($user)) { exit('success'); } exit('未知错误导致注册失败'); } template('auth/register'); exit; }
} unset($keys, $key); } $_SESSION['acid'] = $_W['acid']; $_SESSION['uniacid'] = $_W['uniacid']; if (!empty($_SESSION['openid'])) { $_W['openid'] = $_SESSION['openid']; $_W['fans'] = mc_fansinfo($_W['openid']); $_W['fans']['from_user'] = $_W['openid']; } if (!empty($_SESSION['uid']) || !empty($_W['fans']) && !empty($_W['fans']['uid'])) { $uid = intval($_SESSION['uid']); if (empty($uid)) { $uid = $_W['fans']['uid']; } _mc_login(array('uid' => $uid)); unset($uid); } if (empty($_W['openid']) && !empty($_SESSION['oauth_openid'])) { $_W['openid'] = $_SESSION['oauth_openid']; $_W['fans'] = array('openid' => $_SESSION['oauth_openid'], 'from_user' => $_SESSION['oauth_openid'], 'follow' => 0); } $oauth_acc = $_W['account']; if (intval($oauth_acc['level']) != 4) { $setting = uni_setting($_W['uniacid'], array('oauth')); $oauth = $setting['oauth']; if (!empty($oauth) && !empty($oauth['status']) && !empty($oauth['account'])) { $oauth_acc = account_fetch($oauth['account']); } unset($setting, $oauth); }
$sql = 'SELECT * FROM ' . tablename('mc_mapping_fans') . " {$where} LIMIT 1"; $mapping = pdo_fetch($sql, $pars); if (!empty($mapping)) { if (empty($_W['acid'])) { $_W['acid'] = $mapping['acid']; } if (!empty($mapping['uid'])) { _mc_login(array('uid' => $mapping['uid'])); } else { $_SESSION['uid'] = '0'; } } unset($mapping, $where, $sql, $pars); } if (!empty($_SESSION['uid'])) { _mc_login(array('uid' => $_SESSION['uid'])); } if (!$_GPC['logout'] && empty($_W['openid']) && ($controller != 'auth' || $controller == 'auth' && !in_array($action, array('forward', 'oauth')))) { $setting = uni_setting($_W['uniacid'], array('oauth')); $oauth = $setting['oauth']; if (!empty($oauth) && !empty($oauth['status']) && !empty($oauth['account'])) { $account = account_fetch($oauth['account']); if (intval($account['level']) == 4 && $_W['container'] == 'wechat') { $state = 'we7sid-' . $_W['session_id']; $_SESSION['dest_url'] = base64_encode($_SERVER['QUERY_STRING']); $url = $_W['siteroot'] . 'app/index.php?c=auth&a=oauth&scope=snsapi_base&i=' . $_W['uniacid']; if (!empty($_W['acid'])) { $url .= "&j={$_W['acid']}"; } $callback = urlencode($url); $forward = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$account['key']}&redirect_uri={$callback}&response_type=code&scope=snsapi_base&state={$state}#wechat_redirect";
public function doMobileRegistMember() { global $_W; load()->func('communication'); if (empty($_W['acid'])) { $_W['acid'] = pdo_fetchcolumn("SELECT acid FROM " . tablename('mc_mapping_fans') . " WHERE uniacid='{$_W['uniacid']}' AND openid = '{$_W['openid']}'"); } $account = account_fetch($_W['acid']); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['account']['acid']); $account['access_token']['token'] = $accObj->fetch_token(); if (empty($account['access_token']['token'])) { return false; } $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $account['access_token']['token'] . "&openid=" . $_W['openid'] . "&lang=zh_CN"; $re = ihttp_get($url); if ($re['code'] == 200) { $userinfo = json_decode($re['content'], true); if ($userinfo['errcode'] == '41001') { } } $rec['tag'] = base64_encode($userinfo); $default_groupid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('mc_groups') . ' WHERE uniacid = :uniacid AND isdefault = 1', array(':uniacid' => $_W['uniacid'])); $data = array('uniacid' => $_W['uniacid'], 'email' => md5($_W['openid']) . '@012wz.com', 'salt' => random(8), 'groupid' => $default_groupid, 'createtime' => TIMESTAMP, 'nickname' => stripslashes($userinfo['nickname']), 'avatar' => trim($userinfo['headimgurl']), 'gender' => $userinfo['sex'], 'nationality' => $userinfo['country'], 'resideprovince' => $userinfo['province'] . '省', 'residecity' => $userinfo['city'] . '市'); $data['password'] = md5($message['from'] . $data['salt'] . $_W['config']['setting']['authkey']); pdo_insert('mc_members', $data); $rec['uid'] = pdo_insertid(); pdo_update('mc_mapping_fans', $rec, array('uniacid' => $_W['uniacid'], 'openid' => $_W['openid'])); _mc_login(array('uid' => intval($rec['uid']))); if (empty($_W['member']['uid'])) { return false; } else { return $_W['member']['uid']; } }