public function do_api_login() { $api_info = es_session::get("api_user_info"); if (!$api_info) { app_redirect_preview(); } if (!$_POST) { app_redirect(APP_ROOT . "/"); } foreach ($_POST as $k => $v) { $_POST[$k] = strim($v); } $ajax = intval($_REQUEST['ajax']); if (!check_ipop_limit(get_client_ip(), "user_do_api_login", 5)) { showErr("提交太快", $ajax); } require_once APP_ROOT_PATH . "system/libs/user.php"; $result = do_login_user($_POST['email'], $_POST['user_pwd']); if ($result['status']) { $s_user_info = es_session::get("user_info"); $GLOBALS['db']->query("update " . DB_PREFIX . "user set " . $api_info['field'] . " = '" . $api_info['id'] . "'," . $api_info['token_field'] . " = '" . $api_info['token'] . "'," . $api_info['secret_field'] . " = '" . $api_info['secret'] . "'," . $api_info['url_field'] . " = '" . $api_info['url'] . "' where id = " . $s_user_info['id']); $GLOBALS['db']->query("delete from " . DB_PREFIX . "user_weibo where user_id = " . intval($s_user_info['id']) . " and weibo_url = '" . $api_info['url'] . "'"); update_user_weibo(intval($s_user_info['id']), $api_info['url']); if ($ajax == 0 && trim(app_conf("INTEGRATE_CODE")) == '') { $redirect = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : url("index"); app_redirect($redirect); } else { $jump_url = get_gopreview(); if ($ajax == 1) { $return['status'] = 1; $return['info'] = "登录成功"; $return['data'] = $result['msg']; $return['jump'] = $jump_url; ajax_return($return); } else { $GLOBALS['tmpl']->assign('integrate_result', $result['msg']); showSuccess("登录成功", $ajax, $jump_url); } } } else { if ($result['data'] == ACCOUNT_NO_EXIST_ERROR) { $err = "会员不存在"; } if ($result['data'] == ACCOUNT_PASSWORD_ERROR) { $err = "密码错误"; } showErr($err, $ajax); } }
public function unbind() { if (!$GLOBALS['user_info']) { app_redirect(url("user#login")); } $class_name = strim($_REQUEST['c']); $api_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "api_login class_name='" . $class_name . "'"); if ($api_info['is_weibo'] == 1) { $class_name_update = strtolower($class_name); update_user_weibo($GLOBALS['user_info']['id'], $GLOBALS['user_info'][$class_name . '_url'], 2); //删除微博 $GLOBALS['db']->query("update " . DB_PREFIX . "user set " . $class_name_update . "_id = ''," . $class_name_update . "_url = '' where id = " . intval($GLOBALS['user_info']['id']), "SILENT"); } else { require_once APP_ROOT_PATH . "system/api_login/" . $class_name . "_api.php"; $class_name = $class_name . "_api"; $o = new $class_name($api_info); $o->unset_api(); } app_redirect(url("settings#bind")); }
public function callback() { require_once APP_ROOT_PATH . 'system/api_login/sina/saetv2.ex.class.php'; es_session::start(); //$sina_keys = es_session::get("sina_keys"); $o = new SaeTOAuthV2($this->api['config']['app_key'], $this->api['config']['app_secret']); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; if ($this->api['config']['app_url'] == "") { $app_url = get_domain() . APP_ROOT . "/api_callback.php?c=Sina"; } else { $app_url = $this->api['config']['app_url']; } $keys['redirect_uri'] = $app_url; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { print_r($e); exit; } } $c = new SaeTClientV2($this->api['config']['app_key'], $this->api['config']['app_secret'], $token['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $msg = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 //name,url,province,city,avatar,token,field,token_field(授权的字段),sex,secret_field(授权密码的字段),scret,url_field(微博地址的字段) $api_data['name'] = $msg['name']; $api_data['url'] = "http://weibo.com/" . $msg['profile_url']; $location = $msg['location']; $location = explode(" ", $location); $api_data['province'] = $location[0]; $api_data['city'] = $location[1]; $api_data['avatar'] = $msg['http://tp2.sinaimg.cn/3048107865/180/0/1']; $api_data['field'] = 'sina_id'; $api_data['token'] = $token['access_token']; $api_data['token_field'] = "sina_token"; $api_data['secret'] = ""; $api_data['secret_field'] = "sina_secret"; $api_data['url_field'] = "sina_url"; if ($msg['gender'] == 'm') { $api_data['sex'] = 1; } else { if ($msg['gender'] == 'f') { $api_data['sex'] = 0; } else { $api_data['sex'] = -1; } } if ($msg['name'] != "") { es_session::set("api_user_info", $api_data); } $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where sina_id = '" . $api_data['name'] . "' and sina_id <> ''"); if ($user_data) { es_session::delete("api_user_info"); $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_token = '" . $api_data['token'] . "',login_ip = '" . get_client_ip() . "',login_time= " . get_gmtime() . ",sina_url = '" . $api_data['url'] . "' where id =" . $user_data['id']); update_user_weibo($user_data['id'], $api_data['url']); //更新微博 es_session::set("user_info", $user_data); app_redirect_preview(); } else { if ($GLOBALS['user_info']) { update_user_weibo($GLOBALS['user_info']['id'], $api_data['url']); //更新微博 $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_id = '" . $api_data['name'] . "',sina_token = '" . $api_data['token'] . "',sina_url = '" . $api_data['url'] . "' where id =" . intval($GLOBALS['user_info']['id'])); app_redirect(url("settings#bind")); } else { app_redirect(url("user#api_register")); } } }
public function callback() { es_session::start(); require_once APP_ROOT_PATH . 'system/api_login/Tencent/Tencent.php'; OAuth::init($this->api['config']['app_key'], $this->api['config']['app_secret']); $code = strim($_REQUEST['code']); $openid = strim($_REQUEST['openid']); $openkey = strim($_REQUEST['openkey']); if ($this->api['config']['app_url'] == "") { $app_url = get_domain() . APP_ROOT . "/api_callback.php?c=Tencent"; } else { $app_url = $this->api['config']['app_url']; } $token_url = OAuth::getAccessToken($code, $app_url); $result = Http::request($token_url); $result = preg_replace('/[^\\x20-\\xff]*/', "", $result); //清除不可见字符 $result = iconv("utf-8", "utf-8//ignore", $result); //UTF-8转码 parse_str($result, $result_arr); $access_token = $result_arr['access_token']; $refresh_token = $result_arr['refresh_token']; $name = $result_arr['name']; $nick = $result_arr['nick']; es_session::set("t_access_token", $access_token); es_session::set("t_openid", $openid); es_session::set("t_openkey", $openkey); if (es_session::get("t_access_token") || es_session::get("t_openid") && es_session::get("t_openkey")) { $r = Tencent::api('user/info'); $r = json_decode($r, true); if ($r['errcode'] != 0) { showErr("腾讯微博返回出错"); } //name,url,province,city,avatar,token,field,token_field(授权的字段),sex,secret_field(授权密码的字段),scret,url_field(微博地址的字段) $api_data['name'] = $r['data']['name']; $api_data['url'] = "http://t.qq.com/" . $r['data']['name']; $location = $r['data']['location']; $location = explode(" ", $location); $api_data['province'] = $location[1]; $api_data['city'] = $location[2]; $api_data['avatar'] = $r['data']['head']; $api_data['field'] = 'tencent_id'; $api_data['token'] = $access_token; $api_data['token_field'] = "tencent_token"; $api_data['secret'] = $openkey; $api_data['secret_field'] = "tencent_secret"; $api_data['url_field'] = "tencent_url"; if ($r['data']['sex'] == '1') { $api_data['sex'] = 1; } else { if ($r['data']['sex'] == '2') { $api_data['sex'] = 0; } else { $api_data['sex'] = -1; } } if ($api_data['name'] != "") { es_session::set("api_user_info", $api_data); } $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where tencent_id = '" . $openid . "' and tencent_id <> ''"); if ($user_data) { es_session::delete("api_user_info"); $GLOBALS['db']->query("update " . DB_PREFIX . "user set tencent_token = '" . $api_data['token'] . "',tencent_secret = '" . $api_data['secret'] . "',login_ip = '" . get_client_ip() . "',login_time= " . get_gmtime() . ",tencent_url = '" . $api_data['url'] . "' where id =" . $user_data['id']); update_user_weibo($user_data['id'], $api_data['url']); //更新微博 es_session::set("user_info", $user_data); app_redirect_preview(); } else { if ($GLOBALS['user_info']) { update_user_weibo($GLOBALS['user_info']['id'], $api_data['url']); //更新微博 $GLOBALS['db']->query("update " . DB_PREFIX . "user set tencent_id = '" . $openid . "',tencent_token = '" . $api_data['token'] . "',tencent_secret = '" . $api_data['secret'] . "',tencent_url = '" . $api_data['url'] . "' where id =" . intval($GLOBALS['user_info']['id'])); app_redirect(url("settings#bind")); } else { app_redirect(url("user#api_register")); } } } }
public function unbind() { if (!$GLOBALS['user_info']) { app_redirect(url("user#login")); } $class_name = strtolower(strim($_REQUEST['c'])); update_user_weibo($GLOBALS['user_info']['id'], $GLOBALS['user_info'][$class_name . '_url'], 2); //删除微博 $GLOBALS['db']->query("update " . DB_PREFIX . "user set " . $class_name . "_id = ''," . $class_name . "_url = '' where id = " . intval($GLOBALS['user_info']['id']), "SILENT"); app_redirect(url("settings#bind")); }