function s_weibo_list_by_uid($uid, $page = 1, $count = 20) { if (s_bad_id($uid) || s_bad_id($page) || s_bad_id($count) || $count > 200) { return false; } //看cache中是否存在 $key = "weibo_list_by_uid#" . $uid . $page . $count; if (false === ($data = s_memcache($key))) { //缓存中没有,请求服务器 $params = array("user_id" => $uid, "count" => $count, "page" => $page); if (false === ($data = s_weibo_http('http://api.t.sina.com.cn/statuses/user_timeline.json', $params))) { return false; } //缓存起来900秒(15分钟) //$mem->set($key, $data, 0, 900); } return $data; }
function s_user_ship($uid) { $data = array(); if (!s_bad_id($uid)) { //微博ID $data['target_id'] = $uid; } else { if (!s_bad_string($uid)) { //微博昵称 $data['target_screen_name'] = $uid; } } if (s_bad_array($data)) { return s_err_arg(); } //2.0接口返回程序未被授权 //return s_weibo_http("https://api.weibo.com/2/friendships/create.json", $data, "post"); return s_weibo_http("http://api.t.sina.com.cn/friendships/show.json", $data); }
function s_weibo_surl($url) { if (s_bad_string($url)) { return false; } //看cache中是否存在 $mkey = 'weibo_surl#surl=' . $url; if (false === ($data = s_memcache($mkey))) { //缓存中没有,请求服务器 $params = array('url_long' => $url); if (false === ($data = s_weibo_http('https://api.weibo.com/2/short_url/shorten.json', $params))) { return false; } //缓存起来一天 s_memcache($mkey, $data, 86400); } return $data; }
function s_user_message($uid, $message, $mid = false) { if (s_bad_id($uid)) { return false; } if (s_bad_string($message)) { return false; } $data = array(); $data['uid'] = $uid; $data['text'] = $message; if (is_int($mid)) { $data['id'] = $mid; } return s_weibo_http("http://i2.api.weibo.com/2/direct_messages/new.json", $data, 'post'); }
function s_user_follow($fuid) { if (s_bad_id($fuid)) { return false; } $data = array("uid" => $fuid); //2.0接口返回程序未被授权 //return s_weibo_http("https://api.weibo.com/2/friendships/create.json", $data, "post"); return s_weibo_http("http://api.t.sina.com.cn/friendships/create/{$fuid}.json", $data, "post"); }
function s_weibo_2id_by_mids($mids, $type = 1) { $is_array = 0; if (is_array($mids)) { sort($mids, SORT_STRING); $mids = implode(',', $mids); $is_array = 1; } if (s_bad_string($mids)) { return false; } //看cache中是否存在 $key = "weibo_2id_by_mids#" . $mids; if (false === ($data = s_memcache($key))) { //缓存中没有,请求服务器 $params = array("mid" => $mids, "type" => $type, "is_batch" => $is_array, "isBase62" => 1); if (false === ($data = s_weibo_http('https://api.weibo.com/2/statuses/queryid.json', $params))) { return false; } //缓存起来24小时 s_memcache($key, $data, 24 * 3600); } if (!$is_array) { //非数组查询,只返回对应的id return $data['id']; } $ret = array(); //数组需要处理下 foreach ($data as &$item) { $ret = array_merge($ret, $item); unset($item); } unset($data); return $ret; }
function s_weibo_topic($key, $page = 1, $size = 10) { if (s_bad_string($key)) { return s_err_arg(); } //看cache中是否存在 $mkey = "weibo_search#" . $uid . $q . $page . $size . $istag . $sort . $start . $end . $sid; if (false === ($data = s_memcache($mkey))) { //缓存中没有,请求服务器 $params = array('sid' => $sid, 'page' => $page, 'count' => $size); if (is_string($q)) { $params['q'] = $q; } if (!s_bad_0id($istag)) { $params['istag'] = $istag; } if (!s_bad_id($uid)) { $params['uid'] = $uid; } if (!s_bad_id($start)) { $params['starttime'] = $start; } if (!s_bad_id($end)) { $params['endtime'] = $end; } if (false === ($data = s_weibo_http('http://i2.api.weibo.com/2/search/statuses.json', $params))) { return false; } //缓存起来60秒 s_memcache($mkey, $data, 60); } return $data; }