获取当前登录用户及其所关注用户的最新微博消息。和用户登录 http://weibo.com 后在“我的首页”中看到的内容相同。同friends_timeline()
对应API:{@link http://open.weibo.com/wiki/2/statuses/home_timeline statuses/home_timeline}
对应API:{@link http://open.weibo.com/wiki/2/statuses/home_timeline statuses/home_timeline}
public home_timeline ( integer $page = 1, integer $count = 50, integer $since_id, integer $max_id, integer $base_app, integer $feature ) : array | ||
$page | integer | 指定返回结果的页码。根据当前登录用户所关注的用户数及这些被关注用户发表的微博数,翻页功能最多能查看的总记录数会有所不同,通常最多能查看1000条左右。默认值1。可选。 |
$count | integer | 每次返回的记录数。缺省值50,最大值200。可选。 |
$since_id | integer | 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。 |
$max_id | integer | 若指定此参数,则返回ID小于或等于max_id的微博消息。可选。 |
$base_app | integer | 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 |
$feature | integer | 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。 |
return | array |
/** * 从Callback返回时 */ public function callback() { if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WB_CALLBACK_URL; try { $token = $this->sina->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { $_SESSION['token'] = $token; setcookie('weibojs_' . $this->sina->client_id, http_build_query($token)); $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 $_SESSION['token']['name'] = $user['name']; echo "\n\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\twindow.opener.callback_exec('Sina' , {$uid} , '{$user['name']}',false);\n\t\t\t\t\t\twindow.close();\n\t\t\t\t\t</script>"; } else { echo '授权失败'; } }
public function weibocallback($code) { $cfg = K::$system->config->get('connect'); if (defined('IN_MOBILE')) { $mobile = K::$system->config->get('mobile'); $callback = $mobile['url'] . '/' . K::M('helper/link')->mklink('passport:weibocallback'); } else { $site = K::$system->config->get('site'); $callback = $site['siteurl'] . '/' . K::M('helper/link')->mklink('passport:weibocallback'); } if (empty($cfg['weibo_is_open'])) { $this->err->add('很抱歉网站管理员还未开启微博登录功能', 201); return false; } $keys = array(); $keys['code'] = $code; $keys['redirect_uri'] = $callback; $o = new SaeTOAuthV2($cfg['weibo_app_id'], $cfg['weibo_app_key']); try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { $this->err->add($e->getMessage(), 201); return false; } $c = new SaeTClientV2($cfg['weibo_app_id'], $cfg['weibo_app_key'], $token['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 return $this->login($uid, $user_message); }
private function getUserName() { $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); return $user_message['screen_name']; }
/** * 獲取用戶信息 * @param type $access_token * @return type * Array ( [id] => 3767777785 [idstr] => 3767777785 [class] => 1 * [screen_name] => soqugame [name] => soqugame * [province] => 11 [city] => 1 [location] => 北京 东城区 [description] => [url] => * [profile_image_url] => http://tp2.sinaimg.cn/3767777785/50/0/1 * [profile_url] => u/3767777785 [domain] => [weihao] => [gender] => m [followers_count] => 3 [friends_count] => 18 [statuses_count] => 0 [favourites_count] => 0 [created_at] => Tue Sep 03 16:48:05 +0800 2013 [following] => [allow_all_act_msg] => [geo_enabled] => 1 [verified] => 1 [verified_type] => 2 [remark] => [ptype] => 0 [allow_all_comment] => 1 [avatar_large] => http://tp2.sinaimg.cn/3767777785/180/0/1 [avatar_hd] => http://tp2.sinaimg.cn/3767777785/180/0/1 [verified_reason] => 上海搜趣广告有限公司 [follow_me] => [online_status] => 0 [bi_followers_count] => 0 [lang] => zh-cn [star] => 0 [mbtype] => 0 [mbrank] => 0 [block_word] => 0 ) */ public function getUser($access_token) { $c = new SaeTClientV2($this->_params['WB_AKEY'], $this->_params['WB_SKEY'], $access_token); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 return $user_message; }
function getUserInfo() { require_once dirname(__FILE__) . "/API/saetv2.ex.class.php"; $token = ISession::get('token'); $c = new SaeTClientV2(ISession::get('apiKey'), ISession::get('apiSecret'), $token['access_token']); $ms = $c->home_timeline(); $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); $userInfo = array(); $userInfo['id'] = $uid; $userInfo['name'] = isset($user_message['screen_name']) ? $user_message['screen_name'] : ''; return $userInfo; }
public function callback() { $appkey = $this->config->get('weibo_login_appkey'); $appsecret = $this->config->get('weibo_login_appsecret'); $callback_url = $this->url->link('extension/module/weibo_login/callback', '', true); $this->load->language('extension/module/weibo_login'); $data['text_weibo_login'] = $this->language->get('text_weibo_login'); include_once DIR_SYSTEM . 'library/weibo/saetv2.ex.class.php'; $o = new SaeTOAuthV2($appkey, $appsecret); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = $callback_url; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { //setcookie( 'weibojs_'.$o->client_id, http_build_query($token) ); $c = new SaeTClientV2($appkey, $appsecret, $token['access_token']); $ms = $c->home_timeline(); $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); $this->session->data['weibo_login_access_token'] = $token['access_token']; $this->session->data['weibo_login_uid'] = $uid; if ($this->customer->login_weibo($this->session->data['weibo_login_access_token'], $this->session->data['weibo_login_uid'])) { unset($this->session->data['guest']); // Default Shipping Address $this->load->model('account/address'); if ($this->config->get('config_tax_customer') == 'payment') { $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); } if ($this->config->get('config_tax_customer') == 'shipping') { $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); } $this->response->redirect($this->url->link('account/account', '', 'SSL')); } else { $this->session->data['weibo_login_warning'] = sprintf($this->language->get('text_weibo_login_warning'), $this->config->get('config_name')); $this->response->redirect($this->url->link('account/login', '', 'SSL')); } } else { echo $this->language->get('text_weibo_fail'); } }
function sina_oauth_back() { require_once APPPATH . 'libraries/sina/saetv2.ex.class.php'; $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); $back_url = base_url() . 'index.php?c=oauth&m=sina_oauth_back'; if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = $back_url; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 if ($user_message['gender'] == 'm') { $user_data['tu_gender'] = 0; } else { $user_data['tu_gender'] = 1; } $user_data['tu_weibo_nickname'] = $user_message['screen_name']; $user_data['tu_source'] = 0; $weibo_user_check = $this->tickets->select('users', $user_data); if ($weibo_user_check) { $final_user = $weibo_user_check[0]; } else { $save_dir = 'api_images'; $image = $user_message['avatar_large']; $image_new_name = $this->generate_code(10) . '.jpg'; $image = $this->getImage($image, $save_dir, $image_new_name, 1); $user_data['tu_portrait'] = $image['save_path']; $user_data['tu_created'] = date('Y-m-d H:i:s'); $result = $this->tickets->insert('users', $user_data); $temp_user = $this->tickets->select('users', array('tu_id' => $result)); $final_user = $temp_user[0]; } setcookie('user_cookie', serialize($final_user), time() + 3600 * 24, '/'); redirect('/main/index'); }
function userInfo($token) { $c = new SaeTClientV2($this->sina_akey, $this->sina_skey, $token); $home = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $me = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 $user['id'] = $me['id']; $user['type'] = $this->type; $user['uname'] = $me['name']; $user['province'] = $me['province']; $user['city'] = $me['city']; $user['location'] = $me['location']; $user['email'] = $me['data']['email']; $user['userface'] = str_replace($user['id'] . '/50/', $user['id'] . '/180/', $me['profile_image_url']); $user['sex'] = $me['gender'] == 'm' ? 1 : 0; return $user; }
function callback() { import("Org.Util.saetv2"); $o = new \SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WB_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { session("token", $token); //$_SESSION['token'] = $token setcookie('weibojs_' . $o->client_id, http_build_query($token)); $c = new \SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 //var_dump($user_message);die; session("username", $user_message["screen_name"]); session("c_img", $user_message["profile_image_url"]); echo session('username'); ?> success ,<a href="http://www.sutuijian.com">come on</a> <?php } else { ?> default。 <?php } }
public function callback() { global_run(); require_once APP_ROOT_PATH . 'system/api_login/sina/saetv2.ex.class.php'; //$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 = SITE_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; showErr("授权失败,错误信息:" . $e->getMessage()); die; } } $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获取用户等基本信息 if (intval($msg['error_code']) != 0) { showErr("授权失败,错误代码:" . $msg['error_code']); die; } $msg['field'] = 'sina_id'; $msg['sina_token'] = $token['access_token']; es_session::set("api_user_info", $msg); if (!$msg['name']) { app_redirect(url("index")); exit; } //print_r($msg);die(); $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where sina_id = '" . $msg['id'] . "' and sina_id <> '' and is_effect=1 and is_delete=0"); $is_bind = intval(es_session::get("is_bind")); if ($user_data) { $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_token = '" . $token['access_token'] . "',login_ip = '" . CLIENT_IP . "',login_time= " . NOW_TIME . " where id =" . $user_data['id']); es_session::delete("api_user_info"); if ($is_bind) { if (intval($user_data['id']) != intval($GLOBALS['user_info']['id'])) { showErr("该帐号已经被别的会员绑定过,请直接用帐号登录", 0, url("index", "uc_account")); } else { require_once APP_ROOT_PATH . "system/model/user.php"; load_user($user_data['id'], true); es_session::set("user_info", $user_data); app_redirect(url("index", "uc_account")); } } else { require_once APP_ROOT_PATH . "system/model/user.php"; auto_do_login_user($user_data['user_name'], $user_data['user_pwd'], $from_cookie = false); app_redirect(url("index", "index")); } } elseif ($is_bind == 1 && $GLOBALS['user_info']) { //当有用户身份且要求绑定时 $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_id= '" . $msg['id'] . "', sina_token ='" . $token['access_token'] . "' where id =" . $GLOBALS['user_info']['id']); require_once APP_ROOT_PATH . "system/model/user.php"; load_user($GLOBALS['user_info']['id'], true); app_redirect(url("index", "uc_account")); } else { $user_info = $this->create_user(); require_once APP_ROOT_PATH . "system/model/user.php"; auto_do_login_user($user_info['user_name'], $user_info['user_pwd'], $from_cookie = false); app_redirect(url("index", "index")); } }
public function sendwb() { // 获取消息正文 发晒单 bask 写心情 mood /* * if(isset($this->request->post['bask']) && ($this->request->post['bask'])) { $message_text = $this->request->post['bask']; $message_flag = 1; } else if(isset($this->request->post['mood']) && ($this->request->post['mood'])) { $message_text = $this->request->post['mood']; $message_flag = 2; } else { $message_text = ''; $message_flag = 0; } //获取图片url地址 $this->session->data['token'] if(isset($this->request->post['image']) && ($this->request->post['image'])) { $imgurl = $this->request->post['image']; } else { $imgurl = ''; } //获取视频url地址 if(isset($this->reuqest->post['video']) && ($this->request->post['video'])) { $videourl = $this->request->post['video']; } else { $videourl = ''; } //之前已经登录微博并授权 if (isset($_SESSION['token'])) { } //未登录微博授权 else { include_once(DIR_SYSTEM . 'weibo/config.php'); include_once(DIR_SYSTEM . 'weibo/saetv2.ex.class.php'); if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WBS_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } else { echo "<script language=\"javascript\">window.open ('https://api.weibo.com/oauth2/authorize?client_id=".WB_AKEY."&redirect_uri=".WBS_CALLBACK_URL."&response_type=code','newwindow','height=440,width=630,top=150,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')</script>"; } } */ include_once DIR_SYSTEM . 'weibo/config.php'; include_once DIR_SYSTEM . 'weibo/saetv2.ex.class.php'; $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); // 之前未登录微博授权 if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WBS_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); // $this->session->data['token'] = $token; } catch (OAuthException $e) { } } if (isset($token) && !empty($token)) { $this->session->data['token'] = $token; $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); /* * var_dump($token); var_dump($uid_get); */ $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); // 根据ID获取用户等基本信息 // 图片微博 if (isset($this->session->data['wb']['imgurl'])) { $ret = $c->upload($this->session->data['wb']['message_text'] . ' @信恩世通CNstorm', $this->session->data['wb']['imgurl']); } else { // 文字微博 $ret = $c->update($this->session->data['wb']['message_text'] . ' @信恩世通CNstorm'); } // 返回信息 $msg = ''; if (isset($ret['error_code']) && $ret['error_code'] > 0) { $err = '微博同步失败,'; if ($ret['error_code'] == 20003) { $msg = $err . "用户不存在"; } elseif ($ret['error_code'] == 20005) { $msg = $err . "目前仅支持JPG、GIF、PNG的图片"; } elseif ($ret['error_code'] == 20006) { $msg = $err . "图片太大"; } elseif ($ret['error_code'] == 20012) { $msg = $err . "输入文字太长,请不要超过140字"; } elseif ($ret['error_code'] == 20015) { $msg = $err . "账号、IP或应用非法,暂时无法完成此操作"; } elseif ($ret['error_code'] == 20016) { $msg = $err . "发布内容过于频繁"; } elseif ($ret['error_code'] == 20017) { $msg = $err . "提交相似的信息"; } elseif ($ret['error_code'] == 20018) { $msg = $err . "包含非法网址"; } elseif ($ret['error_code'] == 20019) { $msg = $err . "提交相同的信息"; } elseif ($ret['error_code'] == 20020) { $msg = $err . "包含广告信息"; } elseif ($ret['error_code'] == 20021) { $msg = $err . "包含非法内容"; } elseif ($ret['error_code'] == 20022) { $msg = $err . "此IP地址上的行为异常"; } elseif ($ret['error_code'] == 20032) { $msg = "发布成功,目前服务器可能会有延迟,请耐心等待1-2分钟"; } else { $msg = "微博同步失败"; } } else { unset($this->session->data['wb']['message_text']); if (isset($this->session->data['wb']['imgurl'])) { unset($this->session->data['wb']['imgurl']); } $msg = "微博同步成功"; } echo <<<Eof <script type="text/javascript"> var i = 3; function check(){ if(i>0){ i = i - 1; document.getElementById("time").innerHTML = i; setTimeout("check()",1000); }else{ window.opener = null; window.close(); } } setTimeout("check()",1000); </script> <body> <div><p>{$msg}</p></div> <div>本页面<span id="time">3</span>秒后自动关闭</div> <div><p><a href="http://www.weibo.com/" target="_blank">查看微博</a></p></div> <a href="javascript:window.opener=null;window.close();">直接关闭本页面</a> </body> Eof; } }
<?php session_start(); include_once 'config.php'; include_once 'saetv2.ex.class.php'; $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $c->set_debug(DEBUG_MODE); $ms = $c->home_timeline(); // done //var_dump($ms); $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>新浪微博V2接口演示程序-Powered by Sina App Engine</title> </head> <body> <?php echo $user_message['screen_name']; ?> ,您好! <h2 align="left">发送新微博</h2> <form action="" > <input type="text" name="text" style="width:300px" /> <input type="submit" />
public function public_sina_login() { define('WB_AKEY', pc_base::load_config('system', 'sina_akey')); define('WB_SKEY', pc_base::load_config('system', 'sina_skey')); define('WEB_CALLBACK', APP_PATH . 'index.php?m=member&c=index&a=public_sina_login&callback=1'); pc_base::load_app_class('saetv2.ex', '', 0); $this->_session_start(); if (isset($_GET['callback']) && trim($_GET['callback'])) { $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WEB_CALLBACK; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { $_SESSION['token'] = $token; } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $me = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 if (CHARSET != 'utf-8') { $me['name'] = iconv('utf-8', CHARSET, $me['name']); $me['location'] = iconv('utf-8', CHARSET, $me['location']); $me['description'] = iconv('utf-8', CHARSET, $me['description']); $me['screen_name'] = iconv('utf-8', CHARSET, $me['screen_name']); } if (!empty($me['id'])) { //检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面 $where = array('connectid' => $me['id'], 'from' => 'sina'); $r = $this->db->get_one($where); //connect用户已经绑定本站用户 if (!empty($r)) { //读取本站用户信息,执行登录操作 $password = $r['password']; $this->_init_phpsso(); $synloginstr = $this->client->ps_member_synlogin($r['phpssouid']); $userid = $r['userid']; $groupid = $r['groupid']; $username = $r['username']; $nickname = empty($r['nickname']) ? $username : $r['nickname']; $this->db->update(array('lastip' => ip(), 'lastdate' => SYS_TIME, 'nickname' => $me['name']), array('userid' => $userid)); if (!$cookietime) { $get_cookietime = param::get_cookie('cookietime'); } $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0); $cookietime = $_cookietime ? TIME + $_cookietime : 0; $phpcms_auth = sys_auth($userid . "\t" . $password, 'ENCODE', get_auth_key('login')); param::set_cookie('auth', $phpcms_auth, $cookietime); param::set_cookie('_userid', $userid, $cookietime); param::set_cookie('_username', $username, $cookietime); param::set_cookie('_groupid', $groupid, $cookietime); param::set_cookie('cookietime', $_cookietime, $cookietime); param::set_cookie('_nickname', $nickname, $cookietime); $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?m=member&c=index'; showmessage(L('login_success') . $synloginstr, $forward); } else { //弹出绑定注册页面 $_SESSION = array(); $_SESSION['connectid'] = $me['id']; $_SESSION['from'] = 'sina'; $connect_username = $me['name']; //加载用户模块配置 $member_setting = getcache('member_setting'); if (!$member_setting['allowregister']) { showmessage(L('deny_register'), 'index.php?m=member&c=index&a=login'); } //获取用户siteid $siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1; //过滤非当前站点会员模型 $modellist = getcache('member_model', 'commons'); foreach ($modellist as $k => $v) { if ($v['siteid'] != $siteid || $v['disabled']) { unset($modellist[$k]); } } if (empty($modellist)) { showmessage(L('site_have_no_model') . L('deny_register'), HTTP_REFERER); } $modelid = 10; //设定默认值 if (array_key_exists($modelid, $modellist)) { //获取会员模型表单 require CACHE_MODEL_PATH . 'member_form.class.php'; $member_form = new member_form($modelid); $this->db->set_model($modelid); $forminfos = $forminfos_arr = $member_form->get(); //万能字段过滤 foreach ($forminfos as $field => $info) { if ($info['isomnipotent']) { unset($forminfos[$field]); } else { if ($info['formtype'] == 'omnipotent') { foreach ($forminfos_arr as $_fm => $_fm_value) { if ($_fm_value['isomnipotent']) { $info['form'] = str_replace('{' . $_fm . '}', $_fm_value['form'], $info['form']); } } $forminfos[$field]['form'] = $info['form']; } } } $formValidator = $member_form->formValidator; } include template('member', 'connect'); } } else { showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login'); } } else { $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); $aurl = $o->getAuthorizeURL(WEB_CALLBACK); include template('member', 'connect_sina'); } }
/** * Action:OAuth 2.0 Signup * @return Response */ public function getOauthSignup() { header("Content-type:text/html;charset=utf-8"); session_start(); include_once app_path('api/weibo/config.php'); include_once app_path('api/weibo/saetv2.ex.class.php'); $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WB_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { $_SESSION['token'] = $token; setcookie('weibojs_' . $o->client_id, http_build_query($token)); $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // Done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); // Get sinformation according user ID $nickname = $user_message['screen_name']; $password = $_SESSION['token']['access_token']; $credentials = array('email' => $uid, 'password' => $password); if (Auth::attempt($credentials)) { // Signin success, redirect to the previous page that was blocked return Redirect::intended(); } else { $user = new User(); $user->email = $uid; $user->password = $_SESSION['token']['access_token']; $user->nickname = $nickname; $user->bound_type = '2'; $user->activated_at = date('Y-m-d H:m:s'); $user->save(); return View::make('authority.oauthSuccess'); } } else { return View::make('authority.signup')->withErrors(array('add' => '注册失败。')); } }
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 = SITE_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; showErr("授权失败,错误信息:" . $e->getMessage()); die; } } $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获取用户等基本信息 if (intval($msg['error_code']) != 0) { showErr("授权失败,错误代码:" . $msg['error_code']); die; } $msg['field'] = 'sina_id'; $msg['sina_token'] = $token['access_token']; es_session::set("api_user_info", $msg); if (!$msg['name']) { app_redirect(url("index")); exit; } $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where sina_id = '" . $msg['id'] . "' and sina_id <> 0"); //print_r($user_data);die(); if ($user_data) { $user_current_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where id = " . intval($user_data['group_id'])); $user_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where score <=" . intval($user_data['score']) . " order by score desc"); if ($user_current_group['score'] < $user_group['score']) { $user_data['group_id'] = intval($user_group['id']); } $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_token = '" . $token['access_token'] . "',login_ip = '" . get_client_ip() . "',login_time= " . get_gmtime() . ",group_id=" . intval($user_data['group_id']) . " where id =" . $user_data['id']); es_session::delete("api_user_info"); $is_bind = intval(es_session::get("is_bind")); if ($is_bind) { if (intval($user_data['id']) != intval($GLOBALS['user_info']['id'])) { showErr("该帐号已经被别的会员绑定过,请直接用帐号登录", 0, url("shop", "uc_center#setweibo")); } else { es_session::set("user_info", $user_data); app_redirect(url("index", "uc_center#setweibo")); } } else { require_once APP_ROOT_PATH . "system/libs/user.php"; auto_do_login_user($user_data['user_name'], md5($user_data['user_pwd'] . "_EASE_COOKIE"), $from_cookie = false); app_recirect_preview(); } } elseif ($is_bind == 1 && $GLOBALS['user_info']) { //当有用户身份且要求绑定时 $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_id= '" . intval($msg['id']) . "', sina_token ='" . $token['access_token'] . "' where id =" . $GLOBALS['user_info']['id']); app_redirect(url("index", "uc_center#setweibo")); } else { $this->create_user(); app_redirect(get_gopreview()); } }
<?php session_start(); include_once 'config.php'; include_once 'saetv2.ex.class.php'; // do{ $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(1, 50, 0, 0, 0, 0); $id = 0; $id = file_get_contents("id.log"); echo $id; var_dump($ms); for ($i = 0; $i < count($ms['statuses']); $i++) { // if(!empty($ms['statuses'][$i]['retweeted_status'])) // { if (!empty($ms['statuses'][$i]['retweeted_status']['original_pic'])) { echo "==============" . $ms['statuses'][$i]['retweeted_status']['original_pic']; continue; } if (!empty($ms['statuses'][$i]['original_pic'])) { echo ">>>>>>>>>" . $ms['statuses'][$i]['original_pic']; } // else // { // echo "原微博图片太多"; // } // if($ms['statuses'][$i]['retweeted_status']['reposts_count']>50||$ms['statuses'][$i]['retweeted_status']['comments_count']>50); // { // // if($ms['statuses'][$i]['retweeted_status']['id']>$id) // // { // if(strpos($ms['statuses'][$i]['retweeted_status']['text'],"http") > 0){
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 login_weibo() { include_once DIR_SYSTEM . 'weibo/config.php'; include_once DIR_SYSTEM . 'weibo/saetv2.ex.class.php'; $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WB_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if (isset($token) && !empty($token)) { $this->session->data['token'] = $token; setcookie('weibojs_' . $o->client_id, http_build_query($token)); $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $email_get = $c->get_email(); $uid = $uid_get['uid']; if (isset($email_get['error']) || !$email_get['email']) { $email = ""; } else { $email = "&email=" . $email_get['email']; } $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 $uname = isset($user_message['screen_name']) ? $user_message['screen_name'] : ''; $oauthuid = $uid; $sex = $user_message['gender']; $face = $user_message['avatar_large']; $row = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND oauthuid= '" . $uid . "'"); //判定用户是否存在 if (count($row->row) == "0") { $ip = $this->request->server['REMOTE_ADDR']; $info = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip); $info = json_decode($info, true); if ($info['code'] == 0) { $country = $info['data']['country']; } else { $country = ''; } $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($uname) . "', sex = '" . $this->db->escape($sex) . "', salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '******', customer_group_id = 1, ip = '" . $this->db->escape($ip) . "', status = '1', tname= '" . $this->db->escape($uname) . "', approved = 1, `from` = 'weibo', `oauthuid` = '" . $oauthuid . "', `face` = '" . $face . "', regtime = UNIX_TIMESTAMP(NOW()), date_added = NOW(),logintime= UNIX_TIMESTAMP(NOW()),country='" . $this->db->escape($country) . "' "); $row2 = $this->db->query("SELECT customer_id FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND oauthuid= '" . $oauthuid . "'"); //SQL 范围 FROM=weibo oauthuid $this->session->data['customer_id'] = $row2->row['customer_id']; $this->jumpurl("/index.php?route=account/reg_mail&code=微博登陆" . $email); } else { $cid = $row->row['customer_id']; $this->session->data['customer_id'] = $cid; if ($row->row['email'] == "") { $this->jumpurl("/index.php?route=account/reg_mail&code=微博登陆" . $email); } else { unset($this->session->data['guest']); $this->db->query("UPDATE " . DB_PREFIX . "customer SET logintime = UNIX_TIMESTAMP(NOW()) WHERE `from` = 'weibo' AND oauthuid= '" . $uid . "' AND oauthuid!='' LIMIT 1"); $this->load->model('log/customer_login'); $this->model_log_customer_login->addInfo($cid, 'weibo'); //添加日志 } if (isset($_COOKIE['taobao_id']) && !empty($_COOKIE['taobao_id'])) { //未登录并下单 $this->jumpurl('/order-snatch.html'); } else { $this->jumpurl("/index.php"); } } } else { print "<script language='javascript'>alert('登录超时,請重试!');</script>"; $this->jumpurl("index.php"); } }
public function login_weibo() { include_once DIR_SYSTEM . 'weibo/config.php'; include_once DIR_SYSTEM . 'weibo/saetv2.ex.class.php'; $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WB_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if (isset($token) && !empty($token)) { $this->session->data['token'] = $token; setcookie('weibojs_' . $o->client_id, http_build_query($token)); $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 $uname = isset($user_message['screen_name']) ? $user_message['screen_name'] : ''; //echo "<div style='display:hidden'>".$uname ."-".$uid."</div>"; $row = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND (firstname = '" . $uname . "' OR tname= '" . $uname . "' OR oauthuid= '" . $uid . "')"); if (count($row->row) == "0") { $this->session->data['from'] = 'weibo'; $this->session->data['nick'] = $uname; $this->session->data['oauthuid'] = $uid; print "<script language='javascript'>alert('登 录成功!请补充注册信息以便我们更好为您服务!');</script>"; $this->jumpurl("index.php?route=account/register&nick=" . $uname . "&oauthuid=" . $uid); } else { //weibo.oauthuid为空时,修改成oauthuid if ($row->row['oauthuid'] == "") { $this->db->query("UPDATE " . DB_PREFIX . "customer SET oauthuid= '" . $uid . "' WHERE `from` = 'weibo' AND firstname = '" . $uname . "' LIMIT 1"); } unset($this->session->data['guest']); $row2 = $this->db->query("SELECT `customer_id` FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND oauthuid= '" . $uid . "'"); if (empty($row2->row['customer_id'])) { //customer_id查询为空时,说明是weibo初次登录,需完善注册信息 guanzhiqiang 20150601 $this->session->data['from'] = 'weibo'; $this->session->data['nick'] = $uname; $this->session->data['oauthuid'] = $uid; print "<script language='javascript'>alert('登录成功!请补充注册信息以便我们更好为您服务');</script>"; //$this->jumpurl("/index.php?route=account/register&nick=" . $uname . "&oauthuid=" . $user->openid."&face=".$userinfo['figureurl_qq_2']); $this->jumpurl("index.php?route=account/register&nick=" . $uname . "&oauthuid=" . $uid); } $cids = $row2->row; $cid = $cids['customer_id']; $this->session->data['customer_id'] = $cid; if ($cid == 248) { $row3 = $this->db->query("SELECT `blog` FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND firstname = '" . $uname . "' OR tname= '" . $uname . "' OR oauthuid= '" . $uid . "'"); $cids1 = $row3->row; $loginlog = $cids1['blog']; $loginlog .= ',' . time(); $this->db->query("UPDATE " . DB_PREFIX . "customer SET logintime ='" . time() . "',blog='" . $loginlog . "' WHERE `from` = 'weibo' AND oauthuid= '" . $uid . "' AND oauthuid!='' LIMIT 1"); } else { $this->db->query("UPDATE " . DB_PREFIX . "customer SET logintime ='" . time() . "' WHERE `from` = 'weibo' AND oauthuid= '" . $uid . "' AND oauthuid!='' LIMIT 1"); } if (isset($_COOKIE['taobao_id']) && !empty($_COOKIE['taobao_id'])) { //未登录并下单 $this->jumpurl('/order-snatch.html'); } else { $this->jumpurl("/index.php"); } } } else { // print("<script language='javascript'>alert('网络忙,请稍后重试!');</script>"); print "<script language='javascript'>alert('登入成功!');</script>"; $this->jumpurl("index.php"); } }
function weibo_login() { global $_G; if (!$_G[setting][weibo_appkey] || !$_G[setting][weibo_appsecret]) { msg('抱歉,站点未开启微博登录', 'error', 'm=member&a=login'); return false; } $url = ROOT_PATH . 'web/lib/weibo_login/'; $callback = $_G['siteurl'] . URL . 'm=member&a=weibo_login'; include_once $url . 'saetv2.ex.class.php'; $o = new SaeTOAuthV2($_G[setting][weibo_appkey], $_G[setting][weibo_appsecret]); $code_url = $o->getAuthorizeURL($callback); if (isset($_GET['code']) && $_GET['code']) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = $callback; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } if (!$token) { msg('授权失败'); } $_SESSION['token'] = $token; setcookie('weibojs_' . $o->client_id, http_build_query($token)); $c = new SaeTClientV2($_G[setting][weibo_appkey], $_G[setting][weibo_appsecret], $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $info = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 if ($info[error_code]) { msg('登录接口返回错误,错误信息:' . $info[error]); } if (!$info[id]) { msg('获取用户信息失败'); } $member = array('username' => $info[screen_name], 'address' => $info[location], 'content' => $info[description], 'picurl' => $info[profile_image_url], 'groupid' => 21, 'login_name' => 'weibo', 'login_id' => $uid); $this->login_callback($member); } else { header("Location:" . $code_url); echo '<script type="text/javascript">window.location.href = "' . $code_url . '";</script>'; exit; } }
public function login_weibo() { include_once DIR_SYSTEM . 'weibo/config.php'; include_once DIR_SYSTEM . 'weibo/saetv2.ex.class.php'; $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WB_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if (isset($token) && !empty($token)) { $this->session->data['token'] = $token; setcookie('weibojs_' . $o->client_id, http_build_query($token)); $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 $uname = isset($user_message['screen_name']) ? $user_message['screen_name'] : ''; $row = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND firstname = '" . $uname . "' OR tname= '" . $uname . "' OR oauthuid= '" . $uid . "'"); if (count($row->row) == "0") { $this->session->data['from'] = 'weibo'; print "<script language='javascript'>alert('登录成功!请补充注册信息以便我们更好为您服务!');</script>"; $this->jumpurl("index.php?route=account/register&nick=" . $uname . "&oauthuid=" . $uid); } else { unset($this->session->data['guest']); $row2 = $this->db->query("SELECT `customer_id` FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND firstname = '" . $uname . "' OR tname= '" . $uname . "' OR oauthuid= '" . $uid . "'"); $cids = $row2->row; $cid = $cids['customer_id']; $this->session->data['customer_id'] = $cid; if ($cid == 248) { $row3 = $this->db->query("SELECT `blog` FROM " . DB_PREFIX . "customer WHERE `from` = 'weibo' AND firstname = '" . $uname . "' OR tname= '" . $uname . "' OR oauthuid= '" . $uid . "'"); $cids1 = $row3->row; $loginlog = $cids1['blog']; $loginlog .= ',' . time(); $this->db->query("UPDATE " . DB_PREFIX . "customer SET logintime ='" . time() . "',blog='" . $loginlog . "' WHERE `from` = 'weibo' AND firstname = '" . $uname . "' OR tname= '" . $uname . "' OR oauthuid= '" . $uid . "'"); } else { $this->db->query("UPDATE " . DB_PREFIX . "customer SET logintime ='" . time() . "' WHERE `from` = 'weibo' AND firstname = '" . $uname . "' OR tname= '" . $uname . "' OR oauthuid= '" . $uid . "'"); } $this->jumpurl("index.php"); } } else { // print("<script language='javascript'>alert('网络忙,请稍后重试!');</script>"); print "<script language='javascript'>alert('登入成功!');</script>"; $this->jumpurl("index.php"); } }