├── config.yaml ├── oauth.php ├── 设计数据库.jpg ├── config.php ├── simple.html ├── README.md ├── README ├── xlogin.php ├── 授权解决方案 └── tuchuang.js ├── bookmark.js ├── callback.php ├── upsina.php ├── bookmark.html ├── index.html └── saetv2.ex.class.php /config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: weibotuchuang 3 | version: 3 4 | ... 5 | -------------------------------------------------------------------------------- /oauth.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zythum/weibotuchuang/HEAD/oauth.php -------------------------------------------------------------------------------- /设计数据库.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zythum/weibotuchuang/HEAD/设计数据库.jpg -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 围脖是个好图床 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #围脖是个好图床-Bookmark App# 2 | 貌似围脖真的是个好图床。但是上传是不是挺麻烦的么?可能有时候就想上传张图片贴在某个论坛里就不管了。这张图片的出处啊,存哪里啊什么的都没什么意义。那么你可以使用下 _围脖是个好图床_ 这个小应用。 3 | 4 | --- 5 | 6 | 点击下面体验效果: 7 | 8 | 9 | 10 | --- 11 | + PS. 所有上传的图片会传到 @围脖是个好图床1,2,3 下。这个围脖没有关注和被关注。各位请不要没事关注这个用户。如果你显着硬要去关注页没办法. 12 | + PPS. 请不要连续上传同一张图或者传什么很和谐图。谢谢合作 13 | + PPPS. 应用本体在 14 | 15 | --- 16 | + 感谢: 17 | + 感谢 党和国家 18 | + 感谢 渣浪围脖和sae 19 | + 感谢 @围脖是个好图床1,2,3 20 | + 感谢 MOU 这个文档的mou写导出的 21 | + 感谢 朱一 -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 围脖是个好图床-Bookmark App 2 | 貌似围脖真的是个好图床。但是上传是不是挺麻烦的么?可能有时候就想上传张图片贴在某个论坛里就不管了。这张图片的出处啊,存哪里啊什么的都没什么意义。那么你可以使用下 _围脖是个好图床_ 这个小应用。 3 | 4 | --- 5 | 6 | 点击下面体验效果: 7 | 8 | http://weibotuchuang.sinaapp.com/bookmark.html 9 | 10 | --- 11 | + PS. 所有上传的图片会传到 @围脖是个好图床1,2,3 下。这个围脖没有关注和被关注。各位请不要没事关注这个用户。如果你显着硬要去关注页没办法. 12 | + PPS. 请不要连续上传同一张图或者传什么很和谐图。谢谢合作 13 | + PPPS. 应用本体在 http://weibotuchuang.sinaapp.com 14 | 15 | --- 16 | + 感谢: 17 | + 感谢 党和国家 18 | + 感谢 渣浪围脖和sae 19 | + 感谢 karonl http://karonl.com/ php代码几乎是用的微博图床Beta2 20 | + 感谢 @围脖是个好图床1,2,3 21 | + 感谢 MOU 这个文档的mou写导出的 22 | + 感谢 朱一 -------------------------------------------------------------------------------- /xlogin.php: -------------------------------------------------------------------------------- 1 | getAuthorizeURL( WB_CALLBACK_URL ); 10 | 11 | ?> 12 | 13 | 14 | 15 | 16 | 新浪微博PHP SDK V2版 Demo - Powered by Sina App Engine 17 | 18 | 19 | 20 | 21 |

点击进入授权页面

22 | 23 | 24 | -------------------------------------------------------------------------------- /授权解决方案/tuchuang.js: -------------------------------------------------------------------------------- 1 | /* 2 | 这边使用的是莫大的berserkJS https://github.com/tapir-dream/berserkJS 3 | 找台机器用这个一直跑这段代码就行。 4 | */ 5 | function loop(){ 6 | console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); 7 | console.log(new Date()); 8 | App.webview.open('http://weibotuchuang.sinaapp.com/xlogin.php');//把这里写你的xlogin页 9 | 10 | } 11 | var loadCallback = function(){ 12 | var pos; 13 | console.log(App.webview.getUrl()); 14 | if(/http\:\/\/weibotuchuang\.sinaapp\.com\/xlogin\.php/.test(App.webview.getUrl())){//把这个正则表达式改写成你的xlogin页 15 | console.log('@@@'); 16 | setTimeout(function(){ 17 | pos = App.webview.elementRects('a')[0]; 18 | App.webview.sendMouseEvent(pos); 19 | console.log('!!!!!!!!!!!!!!!!!!!!!!!'); 20 | console.dir(pos); 21 | },2000); 22 | } 23 | if(/api\.weibo\.com/.test(App.webview.getUrl())){ 24 | console.log('授权'); 25 | setTimeout(function(){ 26 | App.webview.execScript(function(){ 27 | document.getElementById('userId').value = "微博帐号";//微博帐号 28 | document.getElementById('passwd').value = "微博密码";//微博密码 29 | }); 30 | pos = App.webview.elementRects('[node-type=submit]')[0]; 31 | App.webview.sendMouseEvent(pos); 32 | console.log('!!!!!!!!!!!!!!!!!!!!!!!'); 33 | console.dir(pos); 34 | },2000); 35 | } 36 | } 37 | var t; 38 | App.webview.clearInterval(t); 39 | t = App.webview.setInterval(loop,20*60*1000); 40 | App.webview.removeEventListener('load',loadCallback); 41 | App.webview.addEventListener('load',loadCallback); 42 | loop(); -------------------------------------------------------------------------------- /bookmark.js: -------------------------------------------------------------------------------- 1 | ;(function(window){ 2 | var d,i,c,clickHandler; 3 | if(window.weibotuchuangbyzythum){ 4 | return false; 5 | } 6 | if(!window.FormData){ 7 | return false; 8 | } 9 | 10 | clickHandler = function(){ 11 | d.parentNode && document.body.removeChild(d); 12 | c.removeEventListener('click',clickHandler); 13 | d = i = c = null; 14 | delete window.weibotuchuangbyzythum; 15 | } 16 | 17 | i = document.createElement('iframe'); 18 | i.setAttribute('width','250'); 19 | i.setAttribute('height','250'); 20 | i.style.cssText = ';border:none;'; 21 | i.src = 'http://weibotuchuang.sinaapp.com'; 22 | 23 | 24 | c = document.createElement('div'); 25 | c.innerHTML = '关闭';//关闭 26 | c.style.cssText = [ 27 | '' 28 | ,'width:40px' 29 | ,'box-shadow:0 0 2px #333' 30 | ,'position:absolute' 31 | ,'top:0' 32 | ,'left:-40px' 33 | ,'line-height:25px' 34 | ,'padding:0' 35 | ,'margin:0' 36 | ,'border-radius:0' 37 | ,'border:none' 38 | ,'background:#515151' 39 | ,'z-index:99999' 40 | ,'text-align:center' 41 | ,'color:#aaa' 42 | ,'cursor:pointer' 43 | ,'' 44 | ].join(';'); 45 | c.addEventListener('click',clickHandler); 46 | 47 | d = document.createElement('div'); 48 | d.style.cssText = [ 49 | '' 50 | ,'width:250px' 51 | ,'height:250px' 52 | ,'box-shadow:0 0 10px #333' 53 | ,'position:fixed' 54 | ,'top:0' 55 | ,'right:0' 56 | ,'z-index:1000000' 57 | ,'font-family:arial,sans-serif' 58 | ,'padding:0' 59 | ,'margin:0' 60 | ,'border-radius:0' 61 | ,'background:#515151' 62 | ,'' 63 | ].join(';'); 64 | d.appendChild(c); 65 | d.appendChild(i); 66 | document.body.appendChild(d); 67 | window.weibotuchuangbyzythum = d; 68 | 69 | })(window); -------------------------------------------------------------------------------- /callback.php: -------------------------------------------------------------------------------- 1 | getAccessToken ( 'code', $keys ); 15 | } catch ( OAuthException $e ) { 16 | } 17 | } 18 | 19 | if ($token) { 20 | $token ['access_time'] = time (); 21 | { // 增加写入数据库的功能 22 | $mysql = new SaeMysql (); 23 | $sql = "SELECT * FROM `token` WHERE uid='" . $token ['uid'] . "' LIMIT 1"; 24 | $data = $mysql->getData ( $sql ); 25 | if (empty ( $data )) { 26 | $sql = "INSERT INTO `token`(`uid` ,`access_time` ,`access_token` ,`expires_in` ,`remind_in`) VALUES('$token[uid]','$token[access_time]','$token[access_token]','$token[expires_in]','$token[remind_in]')"; 27 | $mysql->runSql ( $sql ); 28 | if ($mysql->errno () != 0) { 29 | die ( "Error:" . $mysql->errmsg () ); 30 | } 31 | } elseif (time () >= ($data ['access_time'] + $data ['expires_in'])) { 32 | $sql = "UPDATE `token` SET `access_time`='$token[access_time]', `access_token`='$token[access_token]', `expires_in`='$token[expires_in]', `remind_in`='$token[remind_in]' WHERE `uid`='$token[uid]' LIMIT 1"; 33 | $mysql->runSql ( $sql ); 34 | if ($mysql->errno () != 0) { 35 | die ( "Error:" . $mysql->errmsg () ); 36 | } 37 | } 38 | 39 | $mysql->closeDb (); 40 | } 41 | $_SESSION ['token_ring'] [$token ['uid']] = $token; 42 | // setcookie ( 'weibojs_' . $o->client_id, http_build_query ( $token ) ); 43 | ?> 44 | 授权完成,个人信息已记录。进入你的微博列表页面
45 | 48 | 授权失败。 49 | ';var_dump ( $_SESSION ); 51 | ?> 52 | -------------------------------------------------------------------------------- /upsina.php: -------------------------------------------------------------------------------- 1 | session 11 | $mysql = new SaeMysql (); 12 | 13 | $sql = "SELECT * FROM `token` WHERE `access_time` + `expires_in` >= " . time () . " LIMIT 10"; 14 | $data = $mysql->getData ( $sql ); 15 | foreach ( $data as $key => $val ) { 16 | $_SESSION ['token_ring'] [$val ['uid']] = $val; 17 | } 18 | if ($mysql->errno () != 0) { 19 | die ( "Error:" . $mysql->errmsg () ); 20 | } 21 | 22 | $mysql->closeDb (); 23 | } 24 | 25 | $token = get_live_token (); 26 | $c = new SaeTClientV2 ( WB_AKEY, WB_SKEY, $token ['access_token'] ); 27 | 28 | if (! is_object ( $c ) || empty ( $token )) { 29 | echo '请刷新页面重试,或联系朱一同学,登录后台帐号!喵'; 30 | } else { 31 | if (isset ( $_FILES ['my_uploaded_file'] ['tmp_name'] )){ 32 | $msg1 = $c->upload ( date ( "l dS \of F Y h:i:s A" ), $_FILES ['my_uploaded_file'] ['tmp_name'] ); 33 | } elseif(isset ( $_POST ['my_uploaded_url'] )){ 34 | $msg1 = $c->upload ( date ( "l dS \of F Y h:i:s A" ), $_POST ['my_uploaded_url']); 35 | } 36 | 37 | if (isset ( $msg1 ['original_pic'] ) && ! empty ( $msg1 ['original_pic'] )) { 38 | echo $msg1 ['original_pic']; 39 | } else { 40 | if (in_array ( $msg1 ['error_code'], array (21325, 21326, 21327 ) )) { 41 | unset ( $_SESSION ['token_ring'] [$token ['uid']] ); // 干掉没用的token 42 | } 43 | echo 'error_code: ' . $msg1 ['error_code'] . ', error_description: ' . $msg1; 44 | // echo '喵~上传失败。你上传的真的是图片么?'; 45 | } 46 | 47 | } 48 | 49 | function get_live_token() { 50 | $token = array (); 51 | // 有令牌就进去while了 52 | while ( is_array ( $_SESSION ['token_ring'] ) ) { 53 | $token = array_shift ( $_SESSION ['token_ring'] ); 54 | // 令牌过期了 55 | if (time () > $token ['access_time'] + $token ['expires_in']) { 56 | // 干掉它! 57 | unset ( $token ); 58 | $token = array (); // for gc? fxxk 59 | continue; 60 | } else { 61 | array_push ( $_SESSION ['token_ring'], $token ); 62 | break; // 拿到token了 63 | } 64 | } 65 | return $token; 66 | } 67 | -------------------------------------------------------------------------------- /bookmark.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 围脖是个好图床 6 | 134 | 135 | 136 |

137 | 围脖是个好图床 138 | Bookmark App 139 |

140 | 141 |

貌似围脖真的是个好图床。但是上传是不是挺麻烦的么? 142 | 可能有时候就想上传张图片贴在某个论坛里就不管了。这张图片的出处啊,存哪里啊什么的都没什么意义。那么你可以使用下 围脖是个好图床 这个小应用。

143 |
144 |

拖拽上面的标题或者,这下面的链接到收藏栏。

145 | 146 |

147 | 围脖是个好图床 148 | <— 拖拽到收藏栏

149 | 150 |

或者复制下面的内容存到收藏。

151 | 152 | 153 |

154 |
155 |

PS. 所有上传的图片会传到 @围脖是个好图床1,2,3 下。这个围脖没有关注和被关注。各位请不要没事关注这个用户。如果你显着硬要去关注页没办法。

156 |

PPS. 请不要连续上传同一张图或者传什么很和谐图。谢谢合作

157 |

PPPS. 应用本体在http://weibotuchuang.sinaapp.com

158 |
159 |

感谢:

160 |

感谢 党和国家

161 |

感谢 渣浪围脖和sae

162 |

感谢 karonl http://karonl.com/ php代码几乎是用的微博图床Beta2

163 |

感谢 @围脖是个好图床1,2,3

164 |

感谢 MOU 这个文档的mou写导出的

165 |

感谢 朱一

166 | 167 | 168 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 围脖是个好图床 6 | 100 | 101 | 102 |
103 |
104 | 拖拽图片到这里喵~ 105 |
106 | 107 |
108 |
109 |
110 | 111 | 112 | 113 | 114 | 115 |
116 |
117 |
x
118 |
119 |
120 | 感谢渣浪微博 | code by zythum_朱一 121 |
122 | 217 | 218 | -------------------------------------------------------------------------------- /saetv2.ex.class.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | /** 9 | * @ignore 10 | */ 11 | class OAuthException extends Exception { 12 | // pass 13 | } 14 | 15 | 16 | /** 17 | * 新浪微博 OAuth 认证类(OAuth2) 18 | * 19 | * 授权机制说明请大家参考微博开放平台文档:{@link http://open.weibo.com/wiki/Oauth2} 20 | * 21 | * @package sae 22 | * @author Elmer Zhang 23 | * @version 1.0 24 | */ 25 | class SaeTOAuthV2 { 26 | /** 27 | * @ignore 28 | */ 29 | public $client_id; 30 | /** 31 | * @ignore 32 | */ 33 | public $client_secret; 34 | /** 35 | * @ignore 36 | */ 37 | public $access_token; 38 | /** 39 | * @ignore 40 | */ 41 | public $refresh_token; 42 | /** 43 | * Contains the last HTTP status code returned. 44 | * 45 | * @ignore 46 | */ 47 | public $http_code; 48 | /** 49 | * Contains the last API call. 50 | * 51 | * @ignore 52 | */ 53 | public $url; 54 | /** 55 | * Set up the API root URL. 56 | * 57 | * @ignore 58 | */ 59 | public $host = "https://api.weibo.com/2/"; 60 | /** 61 | * Set timeout default. 62 | * 63 | * @ignore 64 | */ 65 | public $timeout = 30; 66 | /** 67 | * Set connect timeout. 68 | * 69 | * @ignore 70 | */ 71 | public $connecttimeout = 30; 72 | /** 73 | * Verify SSL Cert. 74 | * 75 | * @ignore 76 | */ 77 | public $ssl_verifypeer = FALSE; 78 | /** 79 | * Respons format. 80 | * 81 | * @ignore 82 | */ 83 | public $format = 'json'; 84 | /** 85 | * Decode returned json data. 86 | * 87 | * @ignore 88 | */ 89 | public $decode_json = TRUE; 90 | /** 91 | * Contains the last HTTP headers returned. 92 | * 93 | * @ignore 94 | */ 95 | public $http_info; 96 | /** 97 | * Set the useragnet. 98 | * 99 | * @ignore 100 | */ 101 | public $useragent = 'Sae T OAuth2 v0.1'; 102 | 103 | /** 104 | * print the debug info 105 | * 106 | * @ignore 107 | */ 108 | public $debug = FALSE; 109 | 110 | /** 111 | * boundary of multipart 112 | * @ignore 113 | */ 114 | public static $boundary = ''; 115 | 116 | /** 117 | * Set API URLS 118 | */ 119 | /** 120 | * @ignore 121 | */ 122 | function accessTokenURL() { return 'https://api.weibo.com/oauth2/access_token'; } 123 | /** 124 | * @ignore 125 | */ 126 | function authorizeURL() { return 'https://api.weibo.com/oauth2/authorize'; } 127 | 128 | /** 129 | * construct WeiboOAuth object 130 | */ 131 | function __construct($client_id, $client_secret, $access_token = NULL, $refresh_token = NULL) { 132 | $this->client_id = $client_id; 133 | $this->client_secret = $client_secret; 134 | $this->access_token = $access_token; 135 | $this->refresh_token = $refresh_token; 136 | } 137 | 138 | /** 139 | * authorize接口 140 | * 141 | * 对应API:{@link http://open.weibo.com/wiki/Oauth2/authorize Oauth2/authorize} 142 | * 143 | * @param string $url 授权后的回调地址,站外应用需与回调地址一致,站内应用需要填写canvas page的地址 144 | * @param string $response_type 支持的值包括 code 和token 默认值为code 145 | * @param string $state 用于保持请求和回调的状态。在回调时,会在Query Parameter中回传该参数 146 | * @param string $display 授权页面类型 可选范围: 147 | * - default 默认授权页面 148 | * - mobile 支持html5的手机 149 | * - popup 弹窗授权页 150 | * - wap1.2 wap1.2页面 151 | * - wap2.0 wap2.0页面 152 | * - js js-sdk 专用 授权页面是弹窗,返回结果为js-sdk回掉函数 153 | * - apponweibo 站内应用专用,站内应用不传display参数,并且response_type为token时,默认使用改display.授权后不会返回access_token,只是输出js刷新站内应用父框架 154 | * @return array 155 | */ 156 | function getAuthorizeURL( $url, $response_type = 'code', $state = NULL, $display = NULL ) { 157 | $params = array(); 158 | $params['client_id'] = $this->client_id; 159 | $params['redirect_uri'] = $url; 160 | $params['response_type'] = $response_type; 161 | $params['state'] = $state; 162 | $params['display'] = $display; 163 | return $this->authorizeURL() . "?" . http_build_query($params); 164 | } 165 | 166 | /** 167 | * access_token接口 168 | * 169 | * 对应API:{@link http://open.weibo.com/wiki/OAuth2/access_token OAuth2/access_token} 170 | * 171 | * @param string $type 请求的类型,可以为:code, password, token 172 | * @param array $keys 其他参数: 173 | * - 当$type为code时: array('code'=>..., 'redirect_uri'=>...) 174 | * - 当$type为password时: array('username'=>..., 'password'=>...) 175 | * - 当$type为token时: array('refresh_token'=>...) 176 | * @return array 177 | */ 178 | function getAccessToken( $type = 'code', $keys ) { 179 | $params = array(); 180 | $params['client_id'] = $this->client_id; 181 | $params['client_secret'] = $this->client_secret; 182 | if ( $type === 'token' ) { 183 | $params['grant_type'] = 'refresh_token'; 184 | $params['refresh_token'] = $keys['refresh_token']; 185 | } elseif ( $type === 'code' ) { 186 | $params['grant_type'] = 'authorization_code'; 187 | $params['code'] = $keys['code']; 188 | $params['redirect_uri'] = $keys['redirect_uri']; 189 | } elseif ( $type === 'password' ) { 190 | $params['grant_type'] = 'password'; 191 | $params['username'] = $keys['username']; 192 | $params['password'] = $keys['password']; 193 | } else { 194 | throw new OAuthException("wrong auth type"); 195 | } 196 | 197 | $response = $this->oAuthRequest($this->accessTokenURL(), 'POST', $params); 198 | $token = json_decode($response, true); 199 | if ( is_array($token) && !isset($token['error']) ) { 200 | $this->access_token = $token['access_token']; 201 | $this->refresh_token = $token['refresh_token']; 202 | } else { 203 | throw new OAuthException("get access token failed." . $token['error']); 204 | } 205 | return $token; 206 | } 207 | 208 | /** 209 | * 解析 signed_request 210 | * 211 | * @param string $signed_request 应用框架在加载iframe时会通过向Canvas URL post的参数signed_request 212 | * 213 | * @return array 214 | */ 215 | function parseSignedRequest($signed_request) { 216 | list($encoded_sig, $payload) = explode('.', $signed_request, 2); 217 | $sig = self::base64decode($encoded_sig) ; 218 | $data = json_decode(self::base64decode($payload), true); 219 | if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') return '-1'; 220 | $expected_sig = hash_hmac('sha256', $payload, $this->client_secret, true); 221 | return ($sig !== $expected_sig)? '-2':$data; 222 | } 223 | 224 | /** 225 | * @ignore 226 | */ 227 | function base64decode($str) { 228 | return base64_decode(strtr($str.str_repeat('=', (4 - strlen($str) % 4)), '-_', '+/')); 229 | } 230 | 231 | /** 232 | * 读取jssdk授权信息,用于和jssdk的同步登录 233 | * 234 | * @return array 成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false 235 | */ 236 | function getTokenFromJSSDK() { 237 | $key = "weibojs_" . $this->client_id; 238 | if ( isset($_COOKIE[$key]) && $cookie = $_COOKIE[$key] ) { 239 | parse_str($cookie, $token); 240 | if ( isset($token['access_token']) && isset($token['refresh_token']) ) { 241 | $this->access_token = $token['access_token']; 242 | $this->refresh_token = $token['refresh_token']; 243 | return $token; 244 | } else { 245 | return false; 246 | } 247 | } else { 248 | return false; 249 | } 250 | } 251 | 252 | /** 253 | * 从数组中读取access_token和refresh_token 254 | * 常用于从Session或Cookie中读取token,或通过Session/Cookie中是否存有token判断登录状态。 255 | * 256 | * @param array $arr 存有access_token和secret_token的数组 257 | * @return array 成功返回array('access_token'=>'value', 'refresh_token'=>'value'); 失败返回false 258 | */ 259 | function getTokenFromArray( $arr ) { 260 | if (isset($arr['access_token']) && $arr['access_token']) { 261 | $token = array(); 262 | $this->access_token = $token['access_token'] = $arr['access_token']; 263 | if (isset($arr['refresh_token']) && $arr['refresh_token']) { 264 | $this->refresh_token = $token['refresh_token'] = $arr['refresh_token']; 265 | } 266 | 267 | return $token; 268 | } else { 269 | return false; 270 | } 271 | } 272 | 273 | /** 274 | * GET wrappwer for oAuthRequest. 275 | * 276 | * @return mixed 277 | */ 278 | function get($url, $parameters = array()) { 279 | $response = $this->oAuthRequest($url, 'GET', $parameters); 280 | if ($this->format === 'json' && $this->decode_json) { 281 | return json_decode($response, true); 282 | } 283 | return $response; 284 | } 285 | 286 | /** 287 | * POST wreapper for oAuthRequest. 288 | * 289 | * @return mixed 290 | */ 291 | function post($url, $parameters = array(), $multi = false) { 292 | $response = $this->oAuthRequest($url, 'POST', $parameters, $multi ); 293 | if ($this->format === 'json' && $this->decode_json) { 294 | return json_decode($response, true); 295 | } 296 | return $response; 297 | } 298 | 299 | /** 300 | * DELTE wrapper for oAuthReqeust. 301 | * 302 | * @return mixed 303 | */ 304 | function delete($url, $parameters = array()) { 305 | $response = $this->oAuthRequest($url, 'DELETE', $parameters); 306 | if ($this->format === 'json' && $this->decode_json) { 307 | return json_decode($response, true); 308 | } 309 | return $response; 310 | } 311 | 312 | /** 313 | * Format and sign an OAuth / API request 314 | * 315 | * @return string 316 | * @ignore 317 | */ 318 | function oAuthRequest($url, $method, $parameters, $multi = false) { 319 | 320 | if (strrpos($url, 'http://') !== 0 && strrpos($url, 'https://') !== 0) { 321 | $url = "{$this->host}{$url}.{$this->format}"; 322 | } 323 | 324 | switch ($method) { 325 | case 'GET': 326 | $url = $url . '?' . http_build_query($parameters); 327 | return $this->http($url, 'GET'); 328 | default: 329 | $headers = array(); 330 | if (!$multi && (is_array($parameters) || is_object($parameters)) ) { 331 | $body = http_build_query($parameters); 332 | } else { 333 | $body = self::build_http_query_multi($parameters); 334 | $headers[] = "Content-Type: multipart/form-data; boundary=" . self::$boundary; 335 | } 336 | return $this->http($url, $method, $body, $headers); 337 | } 338 | } 339 | 340 | /** 341 | * Make an HTTP request 342 | * 343 | * @return string API results 344 | * @ignore 345 | */ 346 | function http($url, $method, $postfields = NULL, $headers = array()) { 347 | $this->http_info = array(); 348 | $ci = curl_init(); 349 | /* Curl settings */ 350 | curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 351 | curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent); 352 | curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout); 353 | curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout); 354 | curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); 355 | curl_setopt($ci, CURLOPT_ENCODING, ""); 356 | curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer); 357 | curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader')); 358 | curl_setopt($ci, CURLOPT_HEADER, FALSE); 359 | 360 | switch ($method) { 361 | case 'POST': 362 | curl_setopt($ci, CURLOPT_POST, TRUE); 363 | if (!empty($postfields)) { 364 | curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); 365 | $this->postdata = $postfields; 366 | } 367 | break; 368 | case 'DELETE': 369 | curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE'); 370 | if (!empty($postfields)) { 371 | $url = "{$url}?{$postfields}"; 372 | } 373 | } 374 | 375 | if ( isset($this->access_token) && $this->access_token ) 376 | $headers[] = "Authorization: OAuth2 ".$this->access_token; 377 | 378 | $headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR']; 379 | curl_setopt($ci, CURLOPT_URL, $url ); 380 | curl_setopt($ci, CURLOPT_HTTPHEADER, $headers ); 381 | curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE ); 382 | 383 | $response = curl_exec($ci); 384 | $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); 385 | $this->http_info = array_merge($this->http_info, curl_getinfo($ci)); 386 | $this->url = $url; 387 | 388 | if ($this->debug) { 389 | echo "=====post data======\r\n"; 390 | var_dump($postfields); 391 | 392 | echo '=====info====='."\r\n"; 393 | print_r( curl_getinfo($ci) ); 394 | 395 | echo '=====$response====='."\r\n"; 396 | print_r( $response ); 397 | } 398 | curl_close ($ci); 399 | return $response; 400 | } 401 | 402 | /** 403 | * Get the header info to store. 404 | * 405 | * @return int 406 | * @ignore 407 | */ 408 | function getHeader($ch, $header) { 409 | $i = strpos($header, ':'); 410 | if (!empty($i)) { 411 | $key = str_replace('-', '_', strtolower(substr($header, 0, $i))); 412 | $value = trim(substr($header, $i + 2)); 413 | $this->http_header[$key] = $value; 414 | } 415 | return strlen($header); 416 | } 417 | 418 | /** 419 | * @ignore 420 | */ 421 | public static function build_http_query_multi($params) { 422 | if (!$params) return ''; 423 | 424 | uksort($params, 'strcmp'); 425 | 426 | $pairs = array(); 427 | 428 | self::$boundary = $boundary = uniqid('------------------'); 429 | $MPboundary = '--'.$boundary; 430 | $endMPboundary = $MPboundary. '--'; 431 | $multipartbody = ''; 432 | 433 | foreach ($params as $parameter => $value) { 434 | 435 | if( in_array($parameter, array('pic', 'image')) && $value{0} == '@' ) { 436 | $url = ltrim( $value, '@' ); 437 | $content = file_get_contents( $url ); 438 | $array = explode( '?', basename( $url ) ); 439 | $filename = $array[0]; 440 | 441 | $multipartbody .= $MPboundary . "\r\n"; 442 | $multipartbody .= 'Content-Disposition: form-data; name="' . $parameter . '"; filename="' . $filename . '"'. "\r\n"; 443 | $multipartbody .= "Content-Type: image/unknown\r\n\r\n"; 444 | $multipartbody .= $content. "\r\n"; 445 | } else { 446 | $multipartbody .= $MPboundary . "\r\n"; 447 | $multipartbody .= 'content-disposition: form-data; name="' . $parameter . "\"\r\n\r\n"; 448 | $multipartbody .= $value."\r\n"; 449 | } 450 | 451 | } 452 | 453 | $multipartbody .= $endMPboundary; 454 | return $multipartbody; 455 | } 456 | } 457 | 458 | 459 | /** 460 | * 新浪微博操作类V2 461 | * 462 | * 使用前需要先手工调用saetv2.ex.class.php
463 | * 464 | * @package sae 465 | * @author Easy Chen, Elmer Zhang,Lazypeople 466 | * @version 1.0 467 | */ 468 | class SaeTClientV2 469 | { 470 | /** 471 | * 构造函数 472 | * 473 | * @access public 474 | * @param mixed $akey 微博开放平台应用APP KEY 475 | * @param mixed $skey 微博开放平台应用APP SECRET 476 | * @param mixed $access_token OAuth认证返回的token 477 | * @param mixed $refresh_token OAuth认证返回的token secret 478 | * @return void 479 | */ 480 | function __construct( $akey, $skey, $access_token, $refresh_token = NULL) 481 | { 482 | $this->oauth = new SaeTOAuthV2( $akey, $skey, $access_token, $refresh_token ); 483 | } 484 | 485 | /** 486 | * 获取最新的公共微博消息 487 | * 488 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/public_timeline statuses/public_timeline} 489 | * 490 | * @access public 491 | * @param int $count 单页返回的记录条数,默认为50。 492 | * @param int $page 返回结果的页码,默认为1。 493 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 494 | * @return array 495 | */ 496 | function public_timeline( $page = 1, $count = 50, $base_app = 0 ) 497 | { 498 | $params = array(); 499 | $params['count'] = intval($count); 500 | $params['page'] = intval($page); 501 | $params['base_app'] = intval($base_app); 502 | return $this->oauth->get('statuses/public_timeline', $params);//可能是接口的bug不能补全 503 | } 504 | 505 | /** 506 | * 获取当前登录用户及其所关注用户的最新微博消息。 507 | * 508 | * 获取当前登录用户及其所关注用户的最新微博消息。和用户登录 http://weibo.com 后在“我的首页”中看到的内容相同。同friends_timeline() 509 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/home_timeline statuses/home_timeline} 510 | * 511 | * @access public 512 | * @param int $page 指定返回结果的页码。根据当前登录用户所关注的用户数及这些被关注用户发表的微博数,翻页功能最多能查看的总记录数会有所不同,通常最多能查看1000条左右。默认值1。可选。 513 | * @param int $count 每次返回的记录数。缺省值50,最大值200。可选。 514 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。 515 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的微博消息。可选。 516 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 517 | * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。 518 | * @return array 519 | */ 520 | function home_timeline( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $base_app = 0, $feature = 0 ) 521 | { 522 | $params = array(); 523 | if ($since_id) { 524 | $this->id_format($since_id); 525 | $params['since_id'] = $since_id; 526 | } 527 | if ($max_id) { 528 | $this->id_format($max_id); 529 | $params['max_id'] = $max_id; 530 | } 531 | $params['count'] = intval($count); 532 | $params['page'] = intval($page); 533 | $params['base_app'] = intval($base_app); 534 | $params['feature'] = intval($feature); 535 | 536 | return $this->oauth->get('statuses/home_timeline', $params); 537 | } 538 | 539 | /** 540 | * 获取当前登录用户及其所关注用户的最新微博消息。 541 | * 542 | * 获取当前登录用户及其所关注用户的最新微博消息。和用户登录 http://weibo.com 后在“我的首页”中看到的内容相同。同home_timeline() 543 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/friends_timeline statuses/friends_timeline} 544 | * 545 | * @access public 546 | * @param int $page 指定返回结果的页码。根据当前登录用户所关注的用户数及这些被关注用户发表的微博数,翻页功能最多能查看的总记录数会有所不同,通常最多能查看1000条左右。默认值1。可选。 547 | * @param int $count 每次返回的记录数。缺省值50,最大值200。可选。 548 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。 549 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的微博消息。可选。 550 | * @param int $base_app 是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。默认为0。可选。 551 | * @param int $feature 微博类型,0全部,1原创,2图片,3视频,4音乐. 返回指定类型的微博信息内容。转为为0。可选。 552 | * @return array 553 | */ 554 | function friends_timeline( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $base_app = 0, $feature = 0 ) 555 | { 556 | return $this->home_timeline( $since_id, $max_id, $count, $page, $base_app, $feature); 557 | } 558 | 559 | /** 560 | * 获取用户发布的微博信息列表 561 | * 562 | * 返回用户的发布的最近n条信息,和用户微博页面返回内容是一致的。此接口也可以请求其他用户的最新发表微博。 563 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/user_timeline statuses/user_timeline} 564 | * 565 | * @access public 566 | * @param int $page 页码 567 | * @param int $count 每次返回的最大记录数,最多返回200条,默认50。 568 | * @param mixed $uid 指定用户UID或微博昵称 569 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。 570 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的提到当前登录用户微博消息。可选。 571 | * @param int $base_app 是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。默认为0。 572 | * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。 573 | * @param int $trim_user 返回值中user信息开关,0:返回完整的user信息、1:user字段仅返回uid,默认为0。 574 | * @return array 575 | */ 576 | function user_timeline_by_id( $uid = NULL , $page = 1 , $count = 50 , $since_id = 0, $max_id = 0, $feature = 0, $trim_user = 0, $base_app = 0) 577 | { 578 | $params = array(); 579 | $params['uid']=$uid; 580 | if ($since_id) { 581 | $this->id_format($since_id); 582 | $params['since_id'] = $since_id; 583 | } 584 | if ($max_id) { 585 | $this->id_format($max_id); 586 | $params['max_id'] = $max_id; 587 | } 588 | $params['base_app'] = intval($base_app); 589 | $params['feature'] = intval($feature); 590 | $params['count'] = intval($count); 591 | $params['page'] = intval($page); 592 | $params['trim_user'] = intval($trim_user); 593 | 594 | return $this->oauth->get( 'statuses/user_timeline', $params ); 595 | } 596 | 597 | 598 | /** 599 | * 获取用户发布的微博信息列表 600 | * 601 | * 返回用户的发布的最近n条信息,和用户微博页面返回内容是一致的。此接口也可以请求其他用户的最新发表微博。 602 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/user_timeline statuses/user_timeline} 603 | * 604 | * @access public 605 | * @param string $screen_name 微博昵称,主要是用来区分用户UID跟微博昵称,当二者一样而产生歧义的时候,建议使用该参数 606 | * @param int $page 页码 607 | * @param int $count 每次返回的最大记录数,最多返回200条,默认50。 608 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。 609 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的提到当前登录用户微博消息。可选。 610 | * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。 611 | * @param int $trim_user 返回值中user信息开关,0:返回完整的user信息、1:user字段仅返回uid,默认为0。 612 | * @param int $base_app 是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。默认为0。 613 | * @return array 614 | */ 615 | function user_timeline_by_name( $screen_name = NULL , $page = 1 , $count = 50 , $since_id = 0, $max_id = 0, $feature = 0, $trim_user = 0, $base_app = 0 ) 616 | { 617 | $params = array(); 618 | $params['screen_name'] = $screen_name; 619 | if ($since_id) { 620 | $this->id_format($since_id); 621 | $params['since_id'] = $since_id; 622 | } 623 | if ($max_id) { 624 | $this->id_format($max_id); 625 | $params['max_id'] = $max_id; 626 | } 627 | $params['base_app'] = intval($base_app); 628 | $params['feature'] = intval($feature); 629 | $params['count'] = intval($count); 630 | $params['page'] = intval($page); 631 | $params['trim_user'] = intval($trim_user); 632 | 633 | return $this->oauth->get( 'statuses/user_timeline', $params ); 634 | } 635 | 636 | 637 | 638 | /** 639 | * 批量获取指定的一批用户的timeline 640 | * 641 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/timeline_batch statuses/timeline_batch} 642 | * 643 | * @param string $screen_name 需要查询的用户昵称,用半角逗号分隔,一次最多20个 644 | * @param int $count 单页返回的记录条数,默认为50。 645 | * @param int $page 返回结果的页码,默认为1。 646 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 647 | * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。 648 | * @return array 649 | */ 650 | function timeline_batch_by_name( $screen_name, $page = 1, $count = 50, $feature = 0, $base_app = 0) 651 | { 652 | $params = array(); 653 | if (is_array($screen_name) && !empty($screen_name)) { 654 | $params['screen_name'] = join(',', $screen_name); 655 | } else { 656 | $params['screen_name'] = $screen_name; 657 | } 658 | $params['count'] = intval($count); 659 | $params['page'] = intval($page); 660 | $params['base_app'] = intval($base_app); 661 | $params['feature'] = intval($feature); 662 | return $this->oauth->get('statuses/timeline_batch', $params); 663 | } 664 | 665 | /** 666 | * 批量获取指定的一批用户的timeline 667 | * 668 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/timeline_batch statuses/timeline_batch} 669 | * 670 | * @param string $uids 需要查询的用户ID,用半角逗号分隔,一次最多20个。 671 | * @param int $count 单页返回的记录条数,默认为50。 672 | * @param int $page 返回结果的页码,默认为1。 673 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 674 | * @param int $feature 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。 675 | * @return array 676 | */ 677 | function timeline_batch_by_id( $uids, $page = 1, $count = 50, $feature = 0, $base_app = 0) 678 | { 679 | $params = array(); 680 | if (is_array($uids) && !empty($uids)) { 681 | foreach($uids as $k => $v) { 682 | $this->id_format($uids[$k]); 683 | } 684 | $params['uids'] = join(',', $uids); 685 | } else { 686 | $params['uids'] = $uids; 687 | } 688 | $params['count'] = intval($count); 689 | $params['page'] = intval($page); 690 | $params['base_app'] = intval($base_app); 691 | $params['feature'] = intval($feature); 692 | return $this->oauth->get('statuses/timeline_batch', $params); 693 | } 694 | 695 | 696 | /** 697 | * 返回一条原创微博消息的最新n条转发微博消息。本接口无法对非原创微博进行查询。 698 | * 699 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/repost_timeline statuses/repost_timeline} 700 | * 701 | * @access public 702 | * @param int $sid 要获取转发微博列表的原创微博ID。 703 | * @param int $page 返回结果的页码。 704 | * @param int $count 单页返回的最大记录数,最多返回200条,默认50。可选。 705 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的记录(比since_id发表时间晚)。可选。 706 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的记录。可选。 707 | * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。 708 | * @return array 709 | */ 710 | function repost_timeline( $sid, $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0 ) 711 | { 712 | $this->id_format($sid); 713 | 714 | $params = array(); 715 | $params['id'] = $sid; 716 | if ($since_id) { 717 | $this->id_format($since_id); 718 | $params['since_id'] = $since_id; 719 | } 720 | if ($max_id) { 721 | $this->id_format($max_id); 722 | $params['max_id'] = $max_id; 723 | } 724 | $params['filter_by_author'] = intval($filter_by_author); 725 | 726 | return $this->request_with_pager( 'statuses/repost_timeline', $page, $count, $params ); 727 | } 728 | 729 | /** 730 | * 获取当前用户最新转发的n条微博消息 731 | * 732 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/repost_by_me statuses/repost_by_me} 733 | * 734 | * @access public 735 | * @param int $page 返回结果的页码。 736 | * @param int $count 每次返回的最大记录数,最多返回200条,默认50。可选。 737 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的记录(比since_id发表时间晚)。可选。 738 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的记录。可选。 739 | * @return array 740 | */ 741 | function repost_by_me( $page = 1, $count = 50, $since_id = 0, $max_id = 0 ) 742 | { 743 | $params = array(); 744 | if ($since_id) { 745 | $this->id_format($since_id); 746 | $params['since_id'] = $since_id; 747 | } 748 | if ($max_id) { 749 | $this->id_format($max_id); 750 | $params['max_id'] = $max_id; 751 | } 752 | 753 | return $this->request_with_pager('statuses/repost_by_me', $page, $count, $params ); 754 | } 755 | 756 | /** 757 | * 获取@当前用户的微博列表 758 | * 759 | * 返回最新n条提到登录用户的微博消息(即包含@username的微博消息) 760 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/mentions statuses/mentions} 761 | * 762 | * @access public 763 | * @param int $page 返回结果的页序号。 764 | * @param int $count 每次返回的最大记录数(即页面大小),不大于200,默认为50。 765 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。可选。 766 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的提到当前登录用户微博消息。可选。 767 | * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。 768 | * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博、2:来自微群,默认为0。 769 | * @param int $filter_by_type 原创筛选类型,0:全部微博、1:原创的微博,默认为0。 770 | * @return array 771 | */ 772 | function mentions( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0, $filter_by_source = 0, $filter_by_type = 0 ) 773 | { 774 | $params = array(); 775 | if ($since_id) { 776 | $this->id_format($since_id); 777 | $params['since_id'] = $since_id; 778 | } 779 | if ($max_id) { 780 | $this->id_format($max_id); 781 | $params['max_id'] = $max_id; 782 | } 783 | $params['filter_by_author'] = $filter_by_author; 784 | $params['filter_by_source'] = $filter_by_source; 785 | $params['filter_by_type'] = $filter_by_type; 786 | 787 | return $this->request_with_pager( 'statuses/mentions', $page, $count, $params ); 788 | } 789 | 790 | 791 | /** 792 | * 根据ID获取单条微博信息内容 793 | * 794 | * 获取单条ID的微博信息,作者信息将同时返回。 795 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/show statuses/show} 796 | * 797 | * @access public 798 | * @param int $id 要获取已发表的微博ID, 如ID不存在返回空 799 | * @return array 800 | */ 801 | function show_status( $id ) 802 | { 803 | $this->id_format($id); 804 | $params = array(); 805 | $params['id'] = $id; 806 | return $this->oauth->get('statuses/show', $params); 807 | } 808 | 809 | /** 810 | * 根据微博id号获取微博的信息 811 | * 812 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/show_batch statuses/show_batch} 813 | * 814 | * @param string $ids 需要查询的微博ID,用半角逗号分隔,最多不超过50个。 815 | * @return array 816 | */ 817 | function show_batch( $ids ) 818 | { 819 | $params=array(); 820 | if (is_array($ids) && !empty($ids)) { 821 | foreach($ids as $k => $v) { 822 | $this->id_format($ids[$k]); 823 | } 824 | $params['ids'] = join(',', $ids); 825 | } else { 826 | $params['ids'] = $ids; 827 | } 828 | return $this->oauth->get('statuses/show_batch', $params); 829 | } 830 | 831 | /** 832 | * 通过微博(评论、私信)ID获取其MID 833 | * 834 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/querymid statuses/querymid} 835 | * 836 | * @param int|string $id 需要查询的微博(评论、私信)ID,批量模式下,用半角逗号分隔,最多不超过20个。 837 | * @param int $type 获取类型,1:微博、2:评论、3:私信,默认为1。 838 | * @param int $is_batch 是否使用批量模式,0:否、1:是,默认为0。 839 | * @return array 840 | */ 841 | function querymid( $id, $type = 1, $is_batch = 0 ) 842 | { 843 | $params = array(); 844 | $params['id'] = $id; 845 | $params['type'] = intval($type); 846 | $params['is_batch'] = intval($is_batch); 847 | return $this->oauth->get( 'statuses/querymid', $params); 848 | } 849 | 850 | /** 851 | * 通过微博(评论、私信)MID获取其ID 852 | * 853 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/queryid statuses/queryid} 854 | * 855 | * @param int|string $mid 需要查询的微博(评论、私信)MID,批量模式下,用半角逗号分隔,最多不超过20个。 856 | * @param int $type 获取类型,1:微博、2:评论、3:私信,默认为1。 857 | * @param int $is_batch 是否使用批量模式,0:否、1:是,默认为0。 858 | * @param int $inbox 仅对私信有效,当MID类型为私信时用此参数,0:发件箱、1:收件箱,默认为0 。 859 | * @param int $isBase62 MID是否是base62编码,0:否、1:是,默认为0。 860 | * @return array 861 | */ 862 | function queryid( $mid, $type = 1, $is_batch = 0, $inbox = 0, $isBase62 = 0) 863 | { 864 | $params = array(); 865 | $params['mid'] = $mid; 866 | $params['type'] = intval($type); 867 | $params['is_batch'] = intval($is_batch); 868 | $params['inbox'] = intval($inbox); 869 | $params['isBase62'] = intval($isBase62); 870 | return $this->oauth->get('statuses/queryid', $params); 871 | } 872 | 873 | /** 874 | * 按天返回热门微博转发榜的微博列表 875 | * 876 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/repost_daily statuses/hot/repost_daily} 877 | * 878 | * @param int $count 返回的记录条数,最大不超过50,默认为20。 879 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 880 | * @return array 881 | */ 882 | function repost_daily( $count = 20, $base_app = 0) 883 | { 884 | $params = array(); 885 | $params['count'] = intval($count); 886 | $params['base_app'] = intval($base_app); 887 | return $this->oauth->get('statuses/hot/repost_daily', $params); 888 | } 889 | 890 | /** 891 | * 按周返回热门微博转发榜的微博列表 892 | * 893 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/repost_weekly statuses/hot/repost_weekly} 894 | * 895 | * @param int $count 返回的记录条数,最大不超过50,默认为20。 896 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 897 | * @return array 898 | */ 899 | function repost_weekly( $count = 20, $base_app = 0) 900 | { 901 | $params = array(); 902 | $params['count'] = intval($count); 903 | $params['base_app'] = intval($base_app); 904 | return $this->oauth->get( 'statuses/hot/repost_weekly', $params); 905 | } 906 | 907 | /** 908 | * 按天返回热门微博评论榜的微博列表 909 | * 910 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/comments_daily statuses/hot/comments_daily} 911 | * 912 | * @param int $count 返回的记录条数,最大不超过50,默认为20。 913 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 914 | * @return array 915 | */ 916 | function comments_daily( $count = 20, $base_app = 0) 917 | { 918 | $params = array(); 919 | $params['count'] = intval($count); 920 | $params['base_app'] = intval($base_app); 921 | return $this->oauth->get( 'statuses/hot/comments_daily', $params); 922 | } 923 | 924 | /** 925 | * 按周返回热门微博评论榜的微博列表 926 | * 927 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/hot/comments_weekly statuses/hot/comments_weekly} 928 | * 929 | * @param int $count 返回的记录条数,最大不超过50,默认为20。 930 | * @param int $base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 931 | * @return array 932 | */ 933 | function comments_weekly( $count = 20, $base_app = 0) 934 | { 935 | $params = array(); 936 | $params['count'] = intval($count); 937 | $params['base_app'] = intval($base_app); 938 | return $this->oauth->get( 'statuses/hot/comments_weekly', $params); 939 | } 940 | 941 | 942 | /** 943 | * 转发一条微博信息。 944 | * 945 | * 可加评论。为防止重复,发布的信息与最新信息一样话,将会被忽略。 946 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/repost statuses/repost} 947 | * 948 | * @access public 949 | * @param int $sid 转发的微博ID 950 | * @param string $text 添加的评论信息。可选。 951 | * @param int $is_comment 是否在转发的同时发表评论,0:否、1:评论给当前微博、2:评论给原微博、3:都评论,默认为0。 952 | * @return array 953 | */ 954 | function repost( $sid, $text = NULL, $is_comment = 0 ) 955 | { 956 | $this->id_format($sid); 957 | 958 | $params = array(); 959 | $params['id'] = $sid; 960 | $params['is_comment'] = $is_comment; 961 | if( $text ) $params['status'] = $text; 962 | 963 | return $this->oauth->post( 'statuses/repost', $params ); 964 | } 965 | 966 | /** 967 | * 删除一条微博 968 | * 969 | * 根据ID删除微博消息。注意:只能删除自己发布的信息。 970 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/destroy statuses/destroy} 971 | * 972 | * @access public 973 | * @param int $id 要删除的微博ID 974 | * @return array 975 | */ 976 | function delete( $id ) 977 | { 978 | return $this->destroy( $id ); 979 | } 980 | 981 | /** 982 | * 删除一条微博 983 | * 984 | * 删除微博。注意:只能删除自己发布的信息。 985 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/destroy statuses/destroy} 986 | * 987 | * @access public 988 | * @param int $id 要删除的微博ID 989 | * @return array 990 | */ 991 | function destroy( $id ) 992 | { 993 | $this->id_format($id); 994 | $params = array(); 995 | $params['id'] = $id; 996 | return $this->oauth->post( 'statuses/destroy', $params ); 997 | } 998 | 999 | 1000 | /** 1001 | * 发表微博 1002 | * 1003 | * 发布一条微博信息。 1004 | *
注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。 1005 | *
注意:为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。 1006 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/update statuses/update} 1007 | * 1008 | * @access public 1009 | * @param string $status 要更新的微博信息。信息内容不超过140个汉字, 为空返回400错误。 1010 | * @param float $lat 纬度,发表当前微博所在的地理位置,有效范围 -90.0到+90.0, +表示北纬。可选。 1011 | * @param float $long 经度。有效范围-180.0到+180.0, +表示东经。可选。 1012 | * @param mixed $annotations 可选参数。元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息。每条微博可以包含一个或者多个元数据。请以json字串的形式提交,字串长度不超过512个字符,或者数组方式,要求json_encode后字串长度不超过512个字符。具体内容可以自定。例如:'[{"type2":123}, {"a":"b", "c":"d"}]'或array(array("type2"=>123), array("a"=>"b", "c"=>"d"))。 1013 | * @return array 1014 | */ 1015 | function update( $status, $lat = NULL, $long = NULL, $annotations = NULL ) 1016 | { 1017 | $params = array(); 1018 | $params['status'] = $status; 1019 | if ($lat) { 1020 | $params['lat'] = floatval($lat); 1021 | } 1022 | if ($long) { 1023 | $params['long'] = floatval($long); 1024 | } 1025 | if (is_string($annotations)) { 1026 | $params['annotations'] = $annotations; 1027 | } elseif (is_array($annotations)) { 1028 | $params['annotations'] = json_encode($annotations); 1029 | } 1030 | 1031 | return $this->oauth->post( 'statuses/update', $params ); 1032 | } 1033 | 1034 | /** 1035 | * 发表图片微博 1036 | * 1037 | * 发表图片微博消息。目前上传图片大小限制为<5M。 1038 | *
注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。 1039 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/upload statuses/upload} 1040 | * 1041 | * @access public 1042 | * @param string $status 要更新的微博信息。信息内容不超过140个汉字, 为空返回400错误。 1043 | * @param string $pic_path 要发布的图片路径, 支持url。[只支持png/jpg/gif三种格式, 增加格式请修改get_image_mime方法] 1044 | * @param float $lat 纬度,发表当前微博所在的地理位置,有效范围 -90.0到+90.0, +表示北纬。可选。 1045 | * @param float $long 可选参数,经度。有效范围-180.0到+180.0, +表示东经。可选。 1046 | * @return array 1047 | */ 1048 | function upload( $status, $pic_path, $lat = NULL, $long = NULL ) 1049 | { 1050 | $params = array(); 1051 | $params['status'] = $status; 1052 | $params['pic'] = '@'.$pic_path; 1053 | if ($lat) { 1054 | $params['lat'] = floatval($lat); 1055 | } 1056 | if ($long) { 1057 | $params['long'] = floatval($long); 1058 | } 1059 | 1060 | return $this->oauth->post( 'statuses/upload', $params, true ); 1061 | } 1062 | 1063 | 1064 | /** 1065 | * 指定一个图片URL地址抓取后上传并同时发布一条新微博 1066 | * 1067 | * 对应API:{@link http://open.weibo.com/wiki/2/statuses/upload_url_text statuses/upload_url_text} 1068 | * 1069 | * @param string $status 要发布的微博文本内容,内容不超过140个汉字。 1070 | * @param string $url 图片的URL地址,必须以http开头。 1071 | * @return array 1072 | */ 1073 | function upload_url_text( $status, $url ) 1074 | { 1075 | $params = array(); 1076 | $params['status'] = $status; 1077 | $params['url'] = $url; 1078 | return $this->oauth->post( 'statuses/upload', $params, true ); 1079 | } 1080 | 1081 | 1082 | /** 1083 | * 获取表情列表 1084 | * 1085 | * 返回新浪微博官方所有表情、魔法表情的相关信息。包括短语、表情类型、表情分类,是否热门等。 1086 | *
对应API:{@link http://open.weibo.com/wiki/2/emotions emotions} 1087 | * 1088 | * @access public 1089 | * @param string $type 表情类别。"face":普通表情,"ani":魔法表情,"cartoon":动漫表情。默认为"face"。可选。 1090 | * @param string $language 语言类别,"cnname"简体,"twname"繁体。默认为"cnname"。可选 1091 | * @return array 1092 | */ 1093 | function emotions( $type = "face", $language = "cnname" ) 1094 | { 1095 | $params = array(); 1096 | $params['type'] = $type; 1097 | $params['language'] = $language; 1098 | return $this->oauth->get( 'emotions', $params ); 1099 | } 1100 | 1101 | 1102 | /** 1103 | * 根据微博ID返回某条微博的评论列表 1104 | * 1105 | * 对应API:{@link http://open.weibo.com/wiki/2/comments/show comments/show} 1106 | * 1107 | * @param int $sid 需要查询的微博ID。 1108 | * @param int $page 返回结果的页码,默认为1。 1109 | * @param int $count 单页返回的记录条数,默认为50。 1110 | * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。 1111 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。 1112 | * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。 1113 | * @return array 1114 | */ 1115 | function get_comments_by_sid( $sid, $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0 ) 1116 | { 1117 | $params = array(); 1118 | $this->id_format($sid); 1119 | $params['id'] = $sid; 1120 | if ($since_id) { 1121 | $this->id_format($since_id); 1122 | $params['since_id'] = $since_id; 1123 | } 1124 | if ($max_id) { 1125 | $this->id_format($max_id); 1126 | $params['max_id'] = $max_id; 1127 | } 1128 | $params['count'] = $count; 1129 | $params['page'] = $page; 1130 | $params['filter_by_author'] = $filter_by_author; 1131 | return $this->oauth->get( 'comments/show', $params ); 1132 | } 1133 | 1134 | 1135 | /** 1136 | * 获取当前登录用户所发出的评论列表 1137 | * 1138 | * 对应API:{@link http://open.weibo.com/wiki/2/comments/by_me comments/by_me} 1139 | * 1140 | * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。 1141 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。 1142 | * @param int $count 单页返回的记录条数,默认为50。 1143 | * @param int $page 返回结果的页码,默认为1。 1144 | * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博的评论、2:来自微群的评论,默认为0。 1145 | * @return array 1146 | */ 1147 | function comments_by_me( $page = 1 , $count = 50, $since_id = 0, $max_id = 0, $filter_by_source = 0 ) 1148 | { 1149 | $params = array(); 1150 | if ($since_id) { 1151 | $this->id_format($since_id); 1152 | $params['since_id'] = $since_id; 1153 | } 1154 | if ($max_id) { 1155 | $this->id_format($max_id); 1156 | $params['max_id'] = $max_id; 1157 | } 1158 | $params['count'] = $count; 1159 | $params['page'] = $page; 1160 | $params['filter_by_source'] = $filter_by_source; 1161 | return $this->oauth->get( 'comments/by_me', $params ); 1162 | } 1163 | 1164 | /** 1165 | * 获取当前登录用户所接收到的评论列表 1166 | * 1167 | * 对应API:{@link http://open.weibo.com/wiki/2/comments/to_me comments/to_me} 1168 | * 1169 | * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。 1170 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。 1171 | * @param int $count 单页返回的记录条数,默认为50。 1172 | * @param int $page 返回结果的页码,默认为1。 1173 | * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。 1174 | * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博的评论、2:来自微群的评论,默认为0。 1175 | * @return array 1176 | */ 1177 | function comments_to_me( $page = 1 , $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0, $filter_by_source = 0) 1178 | { 1179 | $params = array(); 1180 | if ($since_id) { 1181 | $this->id_format($since_id); 1182 | $params['since_id'] = $since_id; 1183 | } 1184 | if ($max_id) { 1185 | $this->id_format($max_id); 1186 | $params['max_id'] = $max_id; 1187 | } 1188 | $params['count'] = $count; 1189 | $params['page'] = $page; 1190 | $params['filter_by_author'] = $filter_by_author; 1191 | $params['filter_by_source'] = $filter_by_source; 1192 | return $this->oauth->get( 'comments/to_me', $params ); 1193 | } 1194 | 1195 | /** 1196 | * 最新评论(按时间) 1197 | * 1198 | * 返回最新n条发送及收到的评论。 1199 | *
对应API:{@link http://open.weibo.com/wiki/2/comments/timeline comments/timeline} 1200 | * 1201 | * @access public 1202 | * @param int $page 页码 1203 | * @param int $count 每次返回的最大记录数,最多返回200条,默认50。 1204 | * @param int $since_id 若指定此参数,则只返回ID比since_id大的评论(比since_id发表时间晚)。可选。 1205 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论。可选。 1206 | * @return array 1207 | */ 1208 | function comments_timeline( $page = 1, $count = 50, $since_id = 0, $max_id = 0 ) 1209 | { 1210 | $params = array(); 1211 | if ($since_id) { 1212 | $this->id_format($since_id); 1213 | $params['since_id'] = $since_id; 1214 | } 1215 | if ($max_id) { 1216 | $this->id_format($max_id); 1217 | $params['max_id'] = $max_id; 1218 | } 1219 | 1220 | return $this->request_with_pager( 'comments/timeline', $page, $count, $params ); 1221 | } 1222 | 1223 | 1224 | /** 1225 | * 获取最新的提到当前登录用户的评论,即@我的评论 1226 | * 1227 | * 对应API:{@link http://open.weibo.com/wiki/2/comments/mentions comments/mentions} 1228 | * 1229 | * @param int $since_id 若指定此参数,则返回ID比since_id大的评论(即比since_id时间晚的评论),默认为0。 1230 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的评论,默认为0。 1231 | * @param int $count 单页返回的记录条数,默认为50。 1232 | * @param int $page 返回结果的页码,默认为1。 1233 | * @param int $filter_by_author 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。 1234 | * @param int $filter_by_source 来源筛选类型,0:全部、1:来自微博的评论、2:来自微群的评论,默认为0。 1235 | * @return array 1236 | */ 1237 | function comments_mentions( $page = 1, $count = 50, $since_id = 0, $max_id = 0, $filter_by_author = 0, $filter_by_source = 0) 1238 | { 1239 | $params = array(); 1240 | $params['since_id'] = $since_id; 1241 | $params['max_id'] = $max_id; 1242 | $params['count'] = $count; 1243 | $params['page'] = $page; 1244 | $params['filter_by_author'] = $filter_by_author; 1245 | $params['filter_by_source'] = $filter_by_source; 1246 | return $this->oauth->get( 'comments/mentions', $params ); 1247 | } 1248 | 1249 | 1250 | /** 1251 | * 根据评论ID批量返回评论信息 1252 | * 1253 | * 对应API:{@link http://open.weibo.com/wiki/2/comments/show_batch comments/show_batch} 1254 | * 1255 | * @param string $cids 需要查询的批量评论ID,用半角逗号分隔,最大50 1256 | * @return array 1257 | */ 1258 | function comments_show_batch( $cids ) 1259 | { 1260 | $params = array(); 1261 | if (is_array( $cids) && !empty( $cids)) { 1262 | foreach($cids as $k => $v) { 1263 | $this->id_format($cids[$k]); 1264 | } 1265 | $params['cids'] = join(',', $cids); 1266 | } else { 1267 | $params['cids'] = $cids; 1268 | } 1269 | return $this->oauth->get( 'comments/show_batch', $params ); 1270 | } 1271 | 1272 | 1273 | /** 1274 | * 对一条微博进行评论 1275 | * 1276 | * 对应API:{@link http://open.weibo.com/wiki/2/comments/create comments/create} 1277 | * 1278 | * @param string $comment 评论内容,内容不超过140个汉字。 1279 | * @param int $id 需要评论的微博ID。 1280 | * @param int $comment_ori 当评论转发微博时,是否评论给原微博,0:否、1:是,默认为0。 1281 | * @return array 1282 | */ 1283 | function send_comment( $id , $comment , $comment_ori = 0) 1284 | { 1285 | $params = array(); 1286 | $params['comment'] = $comment; 1287 | $this->id_format($id); 1288 | $params['id'] = $id; 1289 | $params['comment_ori'] = $comment_ori; 1290 | return $this->oauth->post( 'comments/create', $params ); 1291 | } 1292 | 1293 | /** 1294 | * 删除当前用户的微博评论信息。 1295 | * 1296 | * 注意:只能删除自己发布的评论,发部微博的用户不可以删除其他人的评论。 1297 | *
对应API:{@link http://open.weibo.com/wiki/2/statuses/comment_destroy statuses/comment_destroy} 1298 | * 1299 | * @access public 1300 | * @param int $cid 要删除的评论id 1301 | * @return array 1302 | */ 1303 | function comment_destroy( $cid ) 1304 | { 1305 | $params = array(); 1306 | $params['cid'] = $cid; 1307 | return $this->oauth->post( 'comments/destroy', $params); 1308 | } 1309 | 1310 | 1311 | /** 1312 | * 根据评论ID批量删除评论 1313 | * 1314 | * 注意:只能删除自己发布的评论,发部微博的用户不可以删除其他人的评论。 1315 | *
对应API:{@link http://open.weibo.com/wiki/2/comments/destroy_batch comments/destroy_batch} 1316 | * 1317 | * @access public 1318 | * @param string $ids 需要删除的评论ID,用半角逗号隔开,最多20个。 1319 | * @return array 1320 | */ 1321 | function comment_destroy_batch( $ids ) 1322 | { 1323 | $params = array(); 1324 | if (is_array($ids) && !empty($ids)) { 1325 | foreach($ids as $k => $v) { 1326 | $this->id_format($ids[$k]); 1327 | } 1328 | $params['cids'] = join(',', $ids); 1329 | } else { 1330 | $params['cids'] = $ids; 1331 | } 1332 | return $this->oauth->post( 'comments/destroy_batch', $params); 1333 | } 1334 | 1335 | 1336 | /** 1337 | * 回复一条评论 1338 | * 1339 | * 为防止重复,发布的信息与最后一条评论/回复信息一样话,将会被忽略。 1340 | *
对应API:{@link http://open.weibo.com/wiki/2/comments/reply comments/reply} 1341 | * 1342 | * @access public 1343 | * @param int $sid 微博id 1344 | * @param string $text 评论内容。 1345 | * @param int $cid 评论id 1346 | * @param int $without_mention 1:回复中不自动加入“回复@用户名”,0:回复中自动加入“回复@用户名”.默认为0. 1347 | * @param int $comment_ori 当评论转发微博时,是否评论给原微博,0:否、1:是,默认为0。 1348 | * @return array 1349 | */ 1350 | function reply( $sid, $text, $cid, $without_mention = 0, $comment_ori = 0 ) 1351 | { 1352 | $this->id_format( $sid ); 1353 | $this->id_format( $cid ); 1354 | $params = array(); 1355 | $params['id'] = $sid; 1356 | $params['comment'] = $text; 1357 | $params['cid'] = $cid; 1358 | $params['without_mention'] = $without_mention; 1359 | $params['comment_ori'] = $comment_ori; 1360 | 1361 | return $this->oauth->post( 'comments/reply', $params ); 1362 | 1363 | } 1364 | 1365 | /** 1366 | * 根据用户UID或昵称获取用户资料 1367 | * 1368 | * 按用户UID或昵称返回用户资料,同时也将返回用户的最新发布的微博。 1369 | *
对应API:{@link http://open.weibo.com/wiki/2/users/show users/show} 1370 | * 1371 | * @access public 1372 | * @param int $uid 用户UID。 1373 | * @return array 1374 | */ 1375 | function show_user_by_id( $uid ) 1376 | { 1377 | $params=array(); 1378 | if ( $uid !== NULL ) { 1379 | $this->id_format($uid); 1380 | $params['uid'] = $uid; 1381 | } 1382 | 1383 | return $this->oauth->get('users/show', $params ); 1384 | } 1385 | 1386 | /** 1387 | * 根据用户UID或昵称获取用户资料 1388 | * 1389 | * 按用户UID或昵称返回用户资料,同时也将返回用户的最新发布的微博。 1390 | *
对应API:{@link http://open.weibo.com/wiki/2/users/show users/show} 1391 | * 1392 | * @access public 1393 | * @param string $screen_name 用户UID。 1394 | * @return array 1395 | */ 1396 | function show_user_by_name( $screen_name ) 1397 | { 1398 | $params = array(); 1399 | $params['screen_name'] = $screen_name; 1400 | 1401 | return $this->oauth->get( 'users/show', $params ); 1402 | } 1403 | 1404 | /** 1405 | * 通过个性化域名获取用户资料以及用户最新的一条微博 1406 | * 1407 | * 对应API:{@link http://open.weibo.com/wiki/2/users/domain_show users/domain_show} 1408 | * 1409 | * @access public 1410 | * @param mixed $domain 用户个性域名。例如:lazypeople,而不是http://weibo.com/lazypeople 1411 | * @return array 1412 | */ 1413 | function domain_show( $domain ) 1414 | { 1415 | $params = array(); 1416 | $params['domain'] = $domain; 1417 | return $this->oauth->get( 'users/domain_show', $params ); 1418 | } 1419 | 1420 | /** 1421 | * 批量获取用户信息按uids 1422 | * 1423 | * 对应API:{@link http://open.weibo.com/wiki/2/users/show_batch users/show_batch} 1424 | * 1425 | * @param string $uids 需要查询的用户ID,用半角逗号分隔,一次最多20个。 1426 | * @return array 1427 | */ 1428 | function users_show_batch_by_id( $uids ) 1429 | { 1430 | $params = array(); 1431 | if (is_array( $uids ) && !empty( $uids )) { 1432 | foreach( $uids as $k => $v ) { 1433 | $this->id_format( $uids[$k] ); 1434 | } 1435 | $params['uids'] = join(',', $uids); 1436 | } else { 1437 | $params['uids'] = $uids; 1438 | } 1439 | return $this->oauth->get( 'users/show_batch', $params ); 1440 | } 1441 | 1442 | /** 1443 | * 批量获取用户信息按screen_name 1444 | * 1445 | * 对应API:{@link http://open.weibo.com/wiki/2/users/show_batch users/show_batch} 1446 | * 1447 | * @param string $screen_name 需要查询的用户昵称,用半角逗号分隔,一次最多20个。 1448 | * @return array 1449 | */ 1450 | function users_show_batch_by_name( $screen_name ) 1451 | { 1452 | $params = array(); 1453 | if (is_array( $screen_name ) && !empty( $screen_name )) { 1454 | $params['screen_name'] = join(',', $screen_name); 1455 | } else { 1456 | $params['screen_name'] = $screen_name; 1457 | } 1458 | return $this->oauth->get( 'users/show_batch', $params ); 1459 | } 1460 | 1461 | 1462 | /** 1463 | * 获取用户的关注列表 1464 | * 1465 | * 如果没有提供cursor参数,将只返回最前面的5000个关注id 1466 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/friends friendships/friends} 1467 | * 1468 | * @access public 1469 | * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1470 | * @param int $count 单页返回的记录条数,默认为50,最大不超过200。 1471 | * @param int $uid 要获取的用户的ID。 1472 | * @return array 1473 | */ 1474 | function friends_by_id( $uid, $cursor = 0, $count = 50 ) 1475 | { 1476 | $params = array(); 1477 | $params['cursor'] = $cursor; 1478 | $params['count'] = $count; 1479 | $params['uid'] = $uid; 1480 | 1481 | return $this->oauth->get( 'friendships/friends', $params ); 1482 | } 1483 | 1484 | 1485 | /** 1486 | * 获取用户的关注列表 1487 | * 1488 | * 如果没有提供cursor参数,将只返回最前面的5000个关注id 1489 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/friends friendships/friends} 1490 | * 1491 | * @access public 1492 | * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1493 | * @param int $count 单页返回的记录条数,默认为50,最大不超过200。 1494 | * @param string $screen_name 要获取的用户的 screen_name 1495 | * @return array 1496 | */ 1497 | function friends_by_name( $screen_name, $cursor = 0, $count = 50 ) 1498 | { 1499 | $params = array(); 1500 | $params['cursor'] = $cursor; 1501 | $params['count'] = $count; 1502 | $params['screen_name'] = $screen_name; 1503 | return $this->oauth->get( 'friendships/friends', $params ); 1504 | } 1505 | 1506 | 1507 | /** 1508 | * 获取两个用户之间的共同关注人列表 1509 | * 1510 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/in_common friendships/friends/in_common} 1511 | * 1512 | * @param int $uid 需要获取共同关注关系的用户UID 1513 | * @param int $suid 需要获取共同关注关系的用户UID,默认为当前登录用户。 1514 | * @param int $count 单页返回的记录条数,默认为50。 1515 | * @param int $page 返回结果的页码,默认为1。 1516 | * @return array 1517 | */ 1518 | function friends_in_common( $uid, $suid = NULL, $page = 1, $count = 50 ) 1519 | { 1520 | $params = array(); 1521 | $params['uid'] = $uid; 1522 | $params['suid'] = $suid; 1523 | $params['count'] = $count; 1524 | $params['page'] = $page; 1525 | return $this->oauth->get( 'friendships/friends/in_common', $params ); 1526 | } 1527 | 1528 | /** 1529 | * 获取用户的双向关注列表,即互粉列表 1530 | * 1531 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/bilateral friendships/friends/bilateral} 1532 | * 1533 | * @param int $uid 需要获取双向关注列表的用户UID。 1534 | * @param int $count 单页返回的记录条数,默认为50。 1535 | * @param int $page 返回结果的页码,默认为1。 1536 | * @param int $sort 排序类型,0:按关注时间最近排序,默认为0。 1537 | * @return array 1538 | **/ 1539 | function bilateral( $uid, $page = 1, $count = 50, $sort = 0 ) 1540 | { 1541 | $params = array(); 1542 | $params['uid'] = $uid; 1543 | $params['count'] = $count; 1544 | $params['page'] = $page; 1545 | $params['sort'] = $sort; 1546 | return $this->oauth->get( 'friendships/friends/bilateral', $params ); 1547 | } 1548 | 1549 | /** 1550 | * 获取用户的双向关注uid列表 1551 | * 1552 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/bilateral/ids friendships/friends/bilateral/ids} 1553 | * 1554 | * @param int $uid 需要获取双向关注列表的用户UID。 1555 | * @param int $count 单页返回的记录条数,默认为50。 1556 | * @param int $page 返回结果的页码,默认为1。 1557 | * @param int $sort 排序类型,0:按关注时间最近排序,默认为0。 1558 | * @return array 1559 | **/ 1560 | function bilateral_ids( $uid, $page = 1, $count = 50, $sort = 0) 1561 | { 1562 | $params = array(); 1563 | $params['uid'] = $uid; 1564 | $params['count'] = $count; 1565 | $params['page'] = $page; 1566 | $params['sort'] = $sort; 1567 | return $this->oauth->get( 'friendships/friends/bilateral/ids', $params ); 1568 | } 1569 | 1570 | /** 1571 | * 获取用户的关注列表uid 1572 | * 1573 | * 如果没有提供cursor参数,将只返回最前面的5000个关注id 1574 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/ids friendships/friends/ids} 1575 | * 1576 | * @access public 1577 | * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1578 | * @param int $count 每次返回的最大记录数(即页面大小),不大于5000, 默认返回500。 1579 | * @param int $uid 要获取的用户 UID,默认为当前用户 1580 | * @return array 1581 | */ 1582 | function friends_ids_by_id( $uid, $cursor = 0, $count = 500 ) 1583 | { 1584 | $params = array(); 1585 | $this->id_format($uid); 1586 | $params['uid'] = $uid; 1587 | $params['cursor'] = $cursor; 1588 | $params['count'] = $count; 1589 | return $this->oauth->get( 'friendships/friends/ids', $params ); 1590 | } 1591 | 1592 | /** 1593 | * 获取用户的关注列表uid 1594 | * 1595 | * 如果没有提供cursor参数,将只返回最前面的5000个关注id 1596 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/ids friendships/friends/ids} 1597 | * 1598 | * @access public 1599 | * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1600 | * @param int $count 每次返回的最大记录数(即页面大小),不大于5000, 默认返回500。 1601 | * @param string $screen_name 要获取的用户的 screen_name,默认为当前用户 1602 | * @return array 1603 | */ 1604 | function friends_ids_by_name( $screen_name, $cursor = 0, $count = 500 ) 1605 | { 1606 | $params = array(); 1607 | $params['cursor'] = $cursor; 1608 | $params['count'] = $count; 1609 | $params['screen_name'] = $screen_name; 1610 | return $this->oauth->get( 'friendships/friends/ids', $params ); 1611 | } 1612 | 1613 | 1614 | /** 1615 | * 批量获取当前登录用户的关注人的备注信息 1616 | * 1617 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends/remark_batch friendships/friends/remark_batch} 1618 | * 1619 | * @param string $uids 需要获取备注的用户UID,用半角逗号分隔,最多不超过50个。 1620 | * @return array 1621 | **/ 1622 | function friends_remark_batch( $uids ) 1623 | { 1624 | $params = array(); 1625 | if (is_array( $uids ) && !empty( $uids )) { 1626 | foreach( $uids as $k => $v) { 1627 | $this->id_format( $uids[$k] ); 1628 | } 1629 | $params['uids'] = join(',', $uids); 1630 | } else { 1631 | $params['uids'] = $uids; 1632 | } 1633 | return $this->oauth->get( 'friendships/friends/remark_batch', $params ); 1634 | } 1635 | 1636 | /** 1637 | * 获取用户的粉丝列表 1638 | * 1639 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers} 1640 | * 1641 | * @param int $uid 需要查询的用户UID 1642 | * @param int $count 单页返回的记录条数,默认为50,最大不超过200。 1643 | * @param int $cursor false 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1644 | * @return array 1645 | **/ 1646 | function followers_by_id( $uid , $cursor = 0 , $count = 50) 1647 | { 1648 | $params = array(); 1649 | $this->id_format($uid); 1650 | $params['uid'] = $uid; 1651 | $params['count'] = $count; 1652 | $params['cursor'] = $cursor; 1653 | return $this->oauth->get( 'friendships/followers', $params ); 1654 | } 1655 | 1656 | /** 1657 | * 获取用户的粉丝列表 1658 | * 1659 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers} 1660 | * 1661 | * @param string $screen_name 需要查询的用户的昵称 1662 | * @param int $count 单页返回的记录条数,默认为50,最大不超过200。 1663 | * @param int $cursor false 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1664 | * @return array 1665 | **/ 1666 | function followers_by_name( $screen_name, $cursor = 0 , $count = 50 ) 1667 | { 1668 | $params = array(); 1669 | $params['screen_name'] = $screen_name; 1670 | $params['count'] = $count; 1671 | $params['cursor'] = $cursor; 1672 | return $this->oauth->get( 'friendships/followers', $params ); 1673 | } 1674 | 1675 | /** 1676 | * 获取用户的粉丝列表uid 1677 | * 1678 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers} 1679 | * 1680 | * @param int $uid 需要查询的用户UID 1681 | * @param int $count 单页返回的记录条数,默认为50,最大不超过200。 1682 | * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1683 | * @return array 1684 | **/ 1685 | function followers_ids_by_id( $uid, $cursor = 0 , $count = 50 ) 1686 | { 1687 | $params = array(); 1688 | $this->id_format($uid); 1689 | $params['uid'] = $uid; 1690 | $params['count'] = $count; 1691 | $params['cursor'] = $cursor; 1692 | return $this->oauth->get( 'friendships/followers/ids', $params ); 1693 | } 1694 | 1695 | /** 1696 | * 获取用户的粉丝列表uid 1697 | * 1698 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers friendships/followers} 1699 | * 1700 | * @param string $screen_name 需要查询的用户screen_name 1701 | * @param int $count 单页返回的记录条数,默认为50,最大不超过200。 1702 | * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1703 | * @return array 1704 | **/ 1705 | function followers_ids_by_name( $screen_name, $cursor = 0 , $count = 50 ) 1706 | { 1707 | $params = array(); 1708 | $params['screen_name'] = $screen_name; 1709 | $params['count'] = $count; 1710 | $params['cursor'] = $cursor; 1711 | return $this->oauth->get( 'friendships/followers/ids', $params ); 1712 | } 1713 | 1714 | /** 1715 | * 获取优质粉丝 1716 | * 1717 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/followers/active friendships/followers/active} 1718 | * 1719 | * @param int $uid 需要查询的用户UID。 1720 | * @param int $count 返回的记录条数,默认为20,最大不超过200。 1721 | * @return array 1722 | **/ 1723 | function followers_active( $uid, $count = 20) 1724 | { 1725 | $param = array(); 1726 | $this->id_format($uid); 1727 | $param['uid'] = $uid; 1728 | $param['count'] = $count; 1729 | return $this->oauth->get( 'friendships/followers/active', $param); 1730 | } 1731 | 1732 | 1733 | /** 1734 | * 获取当前登录用户的关注人中又关注了指定用户的用户列表 1735 | * 1736 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/friends_chain/followers friendships/friends_chain/followers} 1737 | * 1738 | * @param int $uid 指定的关注目标用户UID。 1739 | * @param int $count 单页返回的记录条数,默认为50。 1740 | * @param int $page 返回结果的页码,默认为1。 1741 | * @return array 1742 | **/ 1743 | function friends_chain_followers( $uid, $page = 1, $count = 50 ) 1744 | { 1745 | $params = array(); 1746 | $this->id_format($uid); 1747 | $params['uid'] = $uid; 1748 | $params['count'] = $count; 1749 | $params['page'] = $page; 1750 | return $this->oauth->get( 'friendships/friends_chain/followers', $params ); 1751 | } 1752 | 1753 | /** 1754 | * 返回两个用户关系的详细情况 1755 | * 1756 | * 如果源用户或目的用户不存在,将返回http的400错误 1757 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/show friendships/show} 1758 | * 1759 | * @access public 1760 | * @param mixed $target_id 目标用户UID 1761 | * @param mixed $source_id 源用户UID,可选,默认为当前的用户 1762 | * @return array 1763 | */ 1764 | function is_followed_by_id( $target_id, $source_id = NULL ) 1765 | { 1766 | $params = array(); 1767 | $this->id_format($target_id); 1768 | $params['target_id'] = $target_id; 1769 | 1770 | if ( $source_id != NULL ) { 1771 | $this->id_format($source_id); 1772 | $params['source_id'] = $source_id; 1773 | } 1774 | 1775 | return $this->oauth->get( 'friendships/show', $params ); 1776 | } 1777 | 1778 | /** 1779 | * 返回两个用户关系的详细情况 1780 | * 1781 | * 如果源用户或目的用户不存在,将返回http的400错误 1782 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/show friendships/show} 1783 | * 1784 | * @access public 1785 | * @param mixed $target_name 目标用户的微博昵称 1786 | * @param mixed $source_name 源用户的微博昵称,可选,默认为当前的用户 1787 | * @return array 1788 | */ 1789 | function is_followed_by_name( $target_name, $source_name = NULL ) 1790 | { 1791 | $params = array(); 1792 | $params['target_screen_name'] = $target_name; 1793 | 1794 | if ( $source_name != NULL ) { 1795 | $params['source_screen_name'] = $source_name; 1796 | } 1797 | 1798 | return $this->oauth->get( 'friendships/show', $params ); 1799 | } 1800 | 1801 | /** 1802 | * 关注一个用户。 1803 | * 1804 | * 成功则返回关注人的资料,目前最多关注2000人,失败则返回一条字符串的说明。如果已经关注了此人,则返回http 403的状态。关注不存在的ID将返回400。 1805 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/create friendships/create} 1806 | * 1807 | * @access public 1808 | * @param int $uid 要关注的用户UID 1809 | * @return array 1810 | */ 1811 | function follow_by_id( $uid ) 1812 | { 1813 | $params = array(); 1814 | $this->id_format($uid); 1815 | $params['uid'] = $uid; 1816 | return $this->oauth->post( 'friendships/create', $params ); 1817 | } 1818 | 1819 | /** 1820 | * 关注一个用户。 1821 | * 1822 | * 成功则返回关注人的资料,目前的最多关注2000人,失败则返回一条字符串的说明。如果已经关注了此人,则返回http 403的状态。关注不存在的ID将返回400。 1823 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/create friendships/create} 1824 | * 1825 | * @access public 1826 | * @param string $screen_name 要关注的用户昵称 1827 | * @return array 1828 | */ 1829 | function follow_by_name( $screen_name ) 1830 | { 1831 | $params = array(); 1832 | $params['screen_name'] = $screen_name; 1833 | return $this->oauth->post( 'friendships/create', $params); 1834 | } 1835 | 1836 | 1837 | /** 1838 | * 根据用户UID批量关注用户 1839 | * 1840 | * 对应API:{@link http://open.weibo.com/wiki/2/friendships/create_batch friendships/create_batch} 1841 | * 1842 | * @param string $uids 要关注的用户UID,用半角逗号分隔,最多不超过20个。 1843 | * @return array 1844 | */ 1845 | function follow_create_batch( $uids ) 1846 | { 1847 | $params = array(); 1848 | if (is_array($uids) && !empty($uids)) { 1849 | foreach($uids as $k => $v) { 1850 | $this->id_format($uids[$k]); 1851 | } 1852 | $params['uids'] = join(',', $uids); 1853 | } else { 1854 | $params['uids'] = $uids; 1855 | } 1856 | return $this->oauth->post( 'friendships/create_batch', $params); 1857 | } 1858 | 1859 | /** 1860 | * 取消关注某用户 1861 | * 1862 | * 取消关注某用户。成功则返回被取消关注人的资料,失败则返回一条字符串的说明。 1863 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/destroy friendships/destroy} 1864 | * 1865 | * @access public 1866 | * @param int $uid 要取消关注的用户UID 1867 | * @return array 1868 | */ 1869 | function unfollow_by_id( $uid ) 1870 | { 1871 | $params = array(); 1872 | $this->id_format($uid); 1873 | $params['uid'] = $uid; 1874 | return $this->oauth->post( 'friendships/destroy', $params); 1875 | } 1876 | 1877 | /** 1878 | * 取消关注某用户 1879 | * 1880 | * 取消关注某用户。成功则返回被取消关注人的资料,失败则返回一条字符串的说明。 1881 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/destroy friendships/destroy} 1882 | * 1883 | * @access public 1884 | * @param string $screen_name 要取消关注的用户昵称 1885 | * @return array 1886 | */ 1887 | function unfollow_by_name( $screen_name ) 1888 | { 1889 | $params = array(); 1890 | $params['screen_name'] = $screen_name; 1891 | return $this->oauth->post( 'friendships/destroy', $params); 1892 | } 1893 | 1894 | /** 1895 | * 更新当前登录用户所关注的某个好友的备注信息 1896 | * 1897 | * 只能修改当前登录用户所关注的用户的备注信息。否则将给出400错误。 1898 | *
对应API:{@link http://open.weibo.com/wiki/2/friendships/remark/update friendships/remark/update} 1899 | * 1900 | * @access public 1901 | * @param int $uid 需要修改备注信息的用户ID。 1902 | * @param string $remark 备注信息。 1903 | * @return array 1904 | */ 1905 | function update_remark( $uid, $remark ) 1906 | { 1907 | $params = array(); 1908 | $this->id_format($uid); 1909 | $params['uid'] = $uid; 1910 | $params['remark'] = $remark; 1911 | return $this->oauth->post( 'friendships/remark/update', $params); 1912 | } 1913 | 1914 | /** 1915 | * 获取当前用户最新私信列表 1916 | * 1917 | * 返回用户的最新n条私信,并包含发送者和接受者的详细资料。 1918 | *
对应API:{@link http://open.weibo.com/wiki/2/direct_messages direct_messages} 1919 | * 1920 | * @access public 1921 | * @param int $page 页码 1922 | * @param int $count 每次返回的最大记录数,最多返回200条,默认50。 1923 | * @param int64 $since_id 返回ID比数值since_id大(比since_id时间晚的)的私信。可选。 1924 | * @param int64 $max_id 返回ID不大于max_id(时间不晚于max_id)的私信。可选。 1925 | * @return array 1926 | */ 1927 | function list_dm( $page = 1, $count = 50, $since_id = 0, $max_id = 0 ) 1928 | { 1929 | $params = array(); 1930 | if ($since_id) { 1931 | $this->id_format($since_id); 1932 | $params['since_id'] = $since_id; 1933 | } 1934 | if ($max_id) { 1935 | $this->id_format($max_id); 1936 | $params['max_id'] = $max_id; 1937 | } 1938 | 1939 | return $this->request_with_pager( 'direct_messages', $page, $count, $params ); 1940 | } 1941 | 1942 | /** 1943 | * 获取当前用户发送的最新私信列表 1944 | * 1945 | * 返回登录用户已发送最新50条私信。包括发送者和接受者的详细资料。 1946 | *
对应API:{@link http://open.weibo.com/wiki/2/direct_messages/sent direct_messages/sent} 1947 | * 1948 | * @access public 1949 | * @param int $page 页码 1950 | * @param int $count 每次返回的最大记录数,最多返回200条,默认50。 1951 | * @param int64 $since_id 返回ID比数值since_id大(比since_id时间晚的)的私信。可选。 1952 | * @param int64 $max_id 返回ID不大于max_id(时间不晚于max_id)的私信。可选。 1953 | * @return array 1954 | */ 1955 | function list_dm_sent( $page = 1, $count = 50, $since_id = 0, $max_id = 0 ) 1956 | { 1957 | $params = array(); 1958 | if ($since_id) { 1959 | $this->id_format($since_id); 1960 | $params['since_id'] = $since_id; 1961 | } 1962 | if ($max_id) { 1963 | $this->id_format($max_id); 1964 | $params['max_id'] = $max_id; 1965 | } 1966 | 1967 | return $this->request_with_pager( 'direct_messages/sent', $page, $count, $params ); 1968 | } 1969 | 1970 | 1971 | /** 1972 | * 获取与当前登录用户有私信往来的用户列表,与该用户往来的最新私信 1973 | * 1974 | * 对应API:{@link http://open.weibo.com/wiki/2/direct_messages/user_list direct_messages/user_list} 1975 | * 1976 | * @param int $count 单页返回的记录条数,默认为20。 1977 | * @param int $cursor 返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。 1978 | * @return array 1979 | */ 1980 | function dm_user_list( $count = 20, $cursor = 0) 1981 | { 1982 | $params = array(); 1983 | $params['count'] = $count; 1984 | $params['cursor'] = $cursor; 1985 | return $this->oauth->get( 'direct_messages/user_list', $params ); 1986 | } 1987 | 1988 | /** 1989 | * 获取与指定用户的往来私信列表 1990 | * 1991 | * 对应API:{@link http://open.weibo.com/wiki/2/direct_messages/conversation direct_messages/conversation} 1992 | * 1993 | * @param int $uid 需要查询的用户的UID。 1994 | * @param int $since_id 若指定此参数,则返回ID比since_id大的私信(即比since_id时间晚的私信),默认为0。 1995 | * @param int $max_id 若指定此参数,则返回ID小于或等于max_id的私信,默认为0。 1996 | * @param int $count 单页返回的记录条数,默认为50。 1997 | * @param int $page 返回结果的页码,默认为1。 1998 | * @return array 1999 | */ 2000 | function dm_conversation( $uid, $page = 1, $count = 50, $since_id = 0, $max_id = 0) 2001 | { 2002 | $params = array(); 2003 | $this->id_format($uid); 2004 | $params['uid'] = $uid; 2005 | if ($since_id) { 2006 | $this->id_format($since_id); 2007 | $params['since_id'] = $since_id; 2008 | } 2009 | if ($max_id) { 2010 | $this->id_format($max_id); 2011 | $params['max_id'] = $max_id; 2012 | } 2013 | $params['count'] = $count; 2014 | $params['page'] = $page; 2015 | return $this->oauth->get( 'direct_messages/conversation', $params ); 2016 | } 2017 | 2018 | /** 2019 | * 根据私信ID批量获取私信内容 2020 | * 2021 | * 对应API:{@link http://open.weibo.com/wiki/2/direct_messages/show_batch direct_messages/show_batch} 2022 | * 2023 | * @param string $dmids 需要查询的私信ID,用半角逗号分隔,一次最多50个 2024 | * @return array 2025 | */ 2026 | function dm_show_batch( $dmids ) 2027 | { 2028 | $params = array(); 2029 | if (is_array($dmids) && !empty($dmids)) { 2030 | foreach($dmids as $k => $v) { 2031 | $this->id_format($dmids[$k]); 2032 | } 2033 | $params['dmids'] = join(',', $dmids); 2034 | } else { 2035 | $params['dmids'] = $dmids; 2036 | } 2037 | return $this->oauth->get( 'direct_messages/show_batch', $params ); 2038 | } 2039 | 2040 | /** 2041 | * 发送私信 2042 | * 2043 | * 发送一条私信。成功将返回完整的发送消息。 2044 | *
对应API:{@link http://open.weibo.com/wiki/2/direct_messages/new direct_messages/new} 2045 | * 2046 | * @access public 2047 | * @param int $uid 用户UID 2048 | * @param string $text 要发生的消息内容,文本大小必须小于300个汉字。 2049 | * @param int $id 需要发送的微博ID。 2050 | * @return array 2051 | */ 2052 | function send_dm_by_id( $uid, $text, $id = NULL ) 2053 | { 2054 | $params = array(); 2055 | $this->id_format( $uid ); 2056 | $params['text'] = $text; 2057 | $params['uid'] = $uid; 2058 | if ($id) { 2059 | $this->id_format( $id ); 2060 | $params['id'] = $id; 2061 | } 2062 | return $this->oauth->post( 'direct_messages/new', $params ); 2063 | } 2064 | 2065 | /** 2066 | * 发送私信 2067 | * 2068 | * 发送一条私信。成功将返回完整的发送消息。 2069 | *
对应API:{@link http://open.weibo.com/wiki/2/direct_messages/new direct_messages/new} 2070 | * 2071 | * @access public 2072 | * @param string $screen_name 用户昵称 2073 | * @param string $text 要发生的消息内容,文本大小必须小于300个汉字。 2074 | * @param int $id 需要发送的微博ID。 2075 | * @return array 2076 | */ 2077 | function send_dm_by_name( $screen_name, $text, $id = NULL ) 2078 | { 2079 | $params = array(); 2080 | $params['text'] = $text; 2081 | $params['screen_name'] = $screen_name; 2082 | if ($id) { 2083 | $this->id_format( $id ); 2084 | $params['id'] = $id; 2085 | } 2086 | return $this->oauth->post( 'direct_messages/new', $params); 2087 | } 2088 | 2089 | /** 2090 | * 删除一条私信 2091 | * 2092 | * 按ID删除私信。操作用户必须为私信的接收人。 2093 | *
对应API:{@link http://open.weibo.com/wiki/2/direct_messages/destroy direct_messages/destroy} 2094 | * 2095 | * @access public 2096 | * @param int $did 要删除的私信主键ID 2097 | * @return array 2098 | */ 2099 | function delete_dm( $did ) 2100 | { 2101 | $this->id_format($did); 2102 | $params = array(); 2103 | $params['id'] = $did; 2104 | return $this->oauth->post('direct_messages/destroy', $params); 2105 | } 2106 | 2107 | /** 2108 | * 批量删除私信 2109 | * 2110 | * 批量删除当前登录用户的私信。出现异常时,返回400错误。 2111 | *
对应API:{@link http://open.weibo.com/wiki/2/direct_messages/destroy_batch direct_messages/destroy_batch} 2112 | * 2113 | * @access public 2114 | * @param mixed $dids 欲删除的一组私信ID,用半角逗号隔开,或者由一组评论ID组成的数组。最多20个。例如:"4976494627, 4976262053"或array(4976494627,4976262053); 2115 | * @return array 2116 | */ 2117 | function delete_dms( $dids ) 2118 | { 2119 | $params = array(); 2120 | if (is_array($dids) && !empty($dids)) { 2121 | foreach($dids as $k => $v) { 2122 | $this->id_format($dids[$k]); 2123 | } 2124 | $params['ids'] = join(',', $dids); 2125 | } else { 2126 | $params['ids'] = $dids; 2127 | } 2128 | 2129 | return $this->oauth->post( 'direct_messages/destroy_batch', $params); 2130 | } 2131 | 2132 | 2133 | 2134 | /** 2135 | * 获取用户基本信息 2136 | * 2137 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/basic account/profile/basic} 2138 | * 2139 | * @param int $uid 需要获取基本信息的用户UID,默认为当前登录用户。 2140 | * @return array 2141 | */ 2142 | function account_profile_basic( $uid = NULL ) 2143 | { 2144 | $params = array(); 2145 | if ($uid) { 2146 | $this->id_format($uid); 2147 | $params['uid'] = $uid; 2148 | } 2149 | return $this->oauth->get( 'account/profile/basic', $params ); 2150 | } 2151 | 2152 | /** 2153 | * 获取用户的教育信息 2154 | * 2155 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/education account/profile/education} 2156 | * 2157 | * @param int $uid 需要获取教育信息的用户UID,默认为当前登录用户。 2158 | * @return array 2159 | */ 2160 | function account_education( $uid = NULL ) 2161 | { 2162 | $params = array(); 2163 | if ($uid) { 2164 | $this->id_format($uid); 2165 | $params['uid'] = $uid; 2166 | } 2167 | return $this->oauth->get( 'account/profile/education', $params ); 2168 | } 2169 | 2170 | /** 2171 | * 批量获取用户的教育信息 2172 | * 2173 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/education_batch account/profile/education_batch} 2174 | * 2175 | * @param string $uids 需要获取教育信息的用户UID,用半角逗号分隔,最多不超过20。 2176 | * @return array 2177 | */ 2178 | function account_education_batch( $uids ) 2179 | { 2180 | $params = array(); 2181 | if (is_array($uids) && !empty($uids)) { 2182 | foreach($uids as $k => $v) { 2183 | $this->id_format($uids[$k]); 2184 | } 2185 | $params['uids'] = join(',', $uids); 2186 | } else { 2187 | $params['uids'] = $uids; 2188 | } 2189 | 2190 | return $this->oauth->get( 'account/profile/education_batch', $params ); 2191 | } 2192 | 2193 | 2194 | /** 2195 | * 获取用户的职业信息 2196 | * 2197 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/career account/profile/career} 2198 | * 2199 | * @param int $uid 需要获取教育信息的用户UID,默认为当前登录用户。 2200 | * @return array 2201 | */ 2202 | function account_career( $uid = NULL ) 2203 | { 2204 | $params = array(); 2205 | if ($uid) { 2206 | $this->id_format($uid); 2207 | $params['uid'] = $uid; 2208 | } 2209 | return $this->oauth->get( 'account/profile/career', $params ); 2210 | } 2211 | 2212 | /** 2213 | * 批量获取用户的职业信息 2214 | * 2215 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/career_batch account/profile/career_batch} 2216 | * 2217 | * @param string $uids 需要获取教育信息的用户UID,用半角逗号分隔,最多不超过20。 2218 | * @return array 2219 | */ 2220 | function account_career_batch( $uids ) 2221 | { 2222 | $params = array(); 2223 | if (is_array($uids) && !empty($uids)) { 2224 | foreach($uids as $k => $v) { 2225 | $this->id_format($uids[$k]); 2226 | } 2227 | $params['uids'] = join(',', $uids); 2228 | } else { 2229 | $params['uids'] = $uids; 2230 | } 2231 | 2232 | return $this->oauth->get( 'account/profile/career_batch', $params ); 2233 | } 2234 | 2235 | /** 2236 | * 获取隐私信息设置情况 2237 | * 2238 | * 对应API:{@link http://open.weibo.com/wiki/2/account/get_privacy account/get_privacy} 2239 | * 2240 | * @access public 2241 | * @return array 2242 | */ 2243 | function get_privacy() 2244 | { 2245 | return $this->oauth->get('account/get_privacy'); 2246 | } 2247 | 2248 | /** 2249 | * 获取所有的学校列表 2250 | * 2251 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/school_list account/profile/school_list} 2252 | * 2253 | * @param array $query 搜索选项。格式:array('key0'=>'value0', 'key1'=>'value1', ....)。支持的key: 2254 | * - province int 省份范围,省份ID。 2255 | * - city int 城市范围,城市ID。 2256 | * - area int 区域范围,区ID。 2257 | * - type int 学校类型,1:大学、2:高中、3:中专技校、4:初中、5:小学,默认为1。 2258 | * - capital string 学校首字母,默认为A。 2259 | * - keyword string 学校名称关键字。 2260 | * - count int 返回的记录条数,默认为10。 2261 | * 参数keyword与capital二者必选其一,且只能选其一。按首字母capital查询时,必须提供province参数。 2262 | * @access public 2263 | * @return array 2264 | */ 2265 | function school_list( $query ) 2266 | { 2267 | $params = $query; 2268 | 2269 | return $this->oauth->get( 'account/profile/school_list', $params ); 2270 | } 2271 | 2272 | /** 2273 | * 获取当前登录用户的API访问频率限制情况 2274 | * 2275 | * 对应API:{@link http://open.weibo.com/wiki/2/account/rate_limit_status account/rate_limit_status} 2276 | * 2277 | * @access public 2278 | * @return array 2279 | */ 2280 | function rate_limit_status() 2281 | { 2282 | return $this->oauth->get( 'account/rate_limit_status' ); 2283 | } 2284 | 2285 | /** 2286 | * OAuth授权之后,获取授权用户的UID 2287 | * 2288 | * 对应API:{@link http://open.weibo.com/wiki/2/account/get_uid account/get_uid} 2289 | * 2290 | * @access public 2291 | * @return array 2292 | */ 2293 | function get_uid() 2294 | { 2295 | return $this->oauth->get( 'account/get_uid' ); 2296 | } 2297 | 2298 | 2299 | /** 2300 | * 更改用户资料 2301 | * 2302 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/basic_update account/profile/basic_update} 2303 | * 2304 | * @access public 2305 | * @param array $profile 要修改的资料。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。 2306 | * 支持修改的项: 2307 | * - screen_name string 用户昵称,不可为空。 2308 | * - gender i string 用户性别,m:男、f:女,不可为空。 2309 | * - real_name string 用户真实姓名。 2310 | * - real_name_visible int 真实姓名可见范围,0:自己可见、1:关注人可见、2:所有人可见。 2311 | * - province true int 省份代码ID,不可为空。 2312 | * - city true int 城市代码ID,不可为空。 2313 | * - birthday string 用户生日,格式:yyyy-mm-dd。 2314 | * - birthday_visible int 生日可见范围,0:保密、1:只显示月日、2:只显示星座、3:所有人可见。 2315 | * - qq string 用户QQ号码。 2316 | * - qq_visible int 用户QQ可见范围,0:自己可见、1:关注人可见、2:所有人可见。 2317 | * - msn string 用户MSN。 2318 | * - msn_visible int 用户MSN可见范围,0:自己可见、1:关注人可见、2:所有人可见。 2319 | * - url string 用户博客地址。 2320 | * - url_visible int 用户博客地址可见范围,0:自己可见、1:关注人可见、2:所有人可见。 2321 | * - credentials_type int 证件类型,1:身份证、2:学生证、3:军官证、4:护照。 2322 | * - credentials_num string 证件号码。 2323 | * - email string 用户常用邮箱地址。 2324 | * - email_visible int 用户常用邮箱地址可见范围,0:自己可见、1:关注人可见、2:所有人可见。 2325 | * - lang string 语言版本,zh_cn:简体中文、zh_tw:繁体中文。 2326 | * - description string 用户描述,最长不超过70个汉字。 2327 | * 填写birthday参数时,做如下约定: 2328 | * - 只填年份时,采用1986-00-00格式; 2329 | * - 只填月份时,采用0000-08-00格式; 2330 | * - 只填某日时,采用0000-00-28格式。 2331 | * @return array 2332 | */ 2333 | function update_profile( $profile ) 2334 | { 2335 | return $this->oauth->post( 'account/profile/basic_update', $profile); 2336 | } 2337 | 2338 | 2339 | /** 2340 | * 设置教育信息 2341 | * 2342 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/edu_update account/profile/edu_update} 2343 | * 2344 | * @access public 2345 | * @param array $edu_update 要修改的学校信息。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。 2346 | * 支持设置的项: 2347 | * - type int 学校类型,1:大学、2:高中、3:中专技校、4:初中、5:小学,默认为1。必填参数 2348 | * - school_id ` int 学校代码,必填参数 2349 | * - id string 需要修改的教育信息ID,不传则为新建,传则为更新。 2350 | * - year int 入学年份,最小为1900,最大不超过当前年份 2351 | * - department string 院系或者班别。 2352 | * - visible int 开放等级,0:仅自己可见、1:关注的人可见、2:所有人可见。 2353 | * @return array 2354 | */ 2355 | function edu_update( $edu_update ) 2356 | { 2357 | return $this->oauth->post( 'account/profile/edu_update', $edu_update); 2358 | } 2359 | 2360 | /** 2361 | * 根据学校ID删除用户的教育信息 2362 | * 2363 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/edu_destroy account/profile/edu_destroy} 2364 | * 2365 | * @param int $id 教育信息里的学校ID。 2366 | * @return array 2367 | */ 2368 | function edu_destroy( $id ) 2369 | { 2370 | $this->id_format( $id ); 2371 | $params = array(); 2372 | $params['id'] = $id; 2373 | return $this->oauth->post( 'account/profile/edu_destroy', $params); 2374 | } 2375 | 2376 | /** 2377 | * 设置职业信息 2378 | * 2379 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/car_update account/profile/car_update} 2380 | * 2381 | * @param array $car_update 要修改的职业信息。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。 2382 | * 支持设置的项: 2383 | * - id string 需要更新的职业信息ID。 2384 | * - start int 进入公司年份,最小为1900,最大为当年年份。 2385 | * - end int 离开公司年份,至今填0。 2386 | * - department string 工作部门。 2387 | * - visible int 可见范围,0:自己可见、1:关注人可见、2:所有人可见。 2388 | * - province int 省份代码ID,不可为空值。 2389 | * - city int 城市代码ID,不可为空值。 2390 | * - company string 公司名称,不可为空值。 2391 | * 参数province与city二者必选其一
2392 | * 参数id为空,则为新建职业信息,参数company变为必填项,参数id非空,则为更新,参数company可选 2393 | * @return array 2394 | */ 2395 | function car_update( $car_update ) 2396 | { 2397 | return $this->oauth->post( 'account/profile/car_update', $car_update); 2398 | } 2399 | 2400 | /** 2401 | * 根据公司ID删除用户的职业信息 2402 | * 2403 | * 对应API:{@link http://open.weibo.com/wiki/2/account/profile/car_destroy account/profile/car_destroy} 2404 | * 2405 | * @access public 2406 | * @param int $id 职业信息里的公司ID 2407 | * @return array 2408 | */ 2409 | function car_destroy( $id ) 2410 | { 2411 | $this->id_format($id); 2412 | $params = array(); 2413 | $params['id'] = $id; 2414 | return $this->oauth->post( 'account/profile/car_destroy', $params); 2415 | } 2416 | 2417 | /** 2418 | * 更改头像 2419 | * 2420 | * 对应API:{@link http://open.weibo.com/wiki/2/account/avatar/upload account/avatar/upload} 2421 | * 2422 | * @param string $image_path 要上传的头像路径, 支持url。[只支持png/jpg/gif三种格式, 增加格式请修改get_image_mime方法] 必须为小于700K的有效的GIF, JPG图片. 如果图片大于500像素将按比例缩放。 2423 | * @return array 2424 | */ 2425 | function update_profile_image( $image_path ) 2426 | { 2427 | $params = array(); 2428 | $params['image'] = "@{$image_path}"; 2429 | 2430 | return $this->oauth->post('account/avatar/upload', $params); 2431 | } 2432 | 2433 | /** 2434 | * 设置隐私信息 2435 | * 2436 | * 对应API:{@link http://open.weibo.com/wiki/2/account/update_privacy account/update_privacy} 2437 | * 2438 | * @param array $privacy_settings 要修改的隐私设置。格式:array('key1'=>'value1', 'key2'=>'value2', .....)。 2439 | * 支持设置的项: 2440 | * - comment int 是否可以评论我的微博,0:所有人、1:关注的人,默认为0。 2441 | * - geo int 是否开启地理信息,0:不开启、1:开启,默认为1。 2442 | * - message int 是否可以给我发私信,0:所有人、1:关注的人,默认为0。 2443 | * - realname int 是否可以通过真名搜索到我,0:不可以、1:可以,默认为0。 2444 | * - badge int 勋章是否可见,0:不可见、1:可见,默认为1。 2445 | * - mobile int 是否可以通过手机号码搜索到我,0:不可以、1:可以,默认为0。 2446 | * 以上参数全部选填 2447 | * @return array 2448 | */ 2449 | function update_privacy( $privacy_settings ) 2450 | { 2451 | return $this->oauth->post( 'account/update_privacy', $privacy_settings); 2452 | } 2453 | 2454 | 2455 | /** 2456 | * 获取当前用户的收藏列表 2457 | * 2458 | * 返回用户的发布的最近20条收藏信息,和用户收藏页面返回内容是一致的。 2459 | *
对应API:{@link http://open.weibo.com/wiki/2/favorites favorites} 2460 | * 2461 | * @access public 2462 | * @param int $page 返回结果的页码,默认为1。 2463 | * @param int $count 单页返回的记录条数,默认为50。 2464 | * @return array 2465 | */ 2466 | function get_favorites( $page = 1, $count = 50 ) 2467 | { 2468 | $params = array(); 2469 | $params['page'] = intval($page); 2470 | $params['count'] = intval($count); 2471 | 2472 | return $this->oauth->get( 'favorites', $params ); 2473 | } 2474 | 2475 | 2476 | /** 2477 | * 根据收藏ID获取指定的收藏信息 2478 | * 2479 | * 根据收藏ID获取指定的收藏信息。 2480 | *
对应API:{@link http://open.weibo.com/wiki/2/favorites/show favorites/show} 2481 | * 2482 | * @access public 2483 | * @param int $id 需要查询的收藏ID。 2484 | * @return array 2485 | */ 2486 | function favorites_show( $id ) 2487 | { 2488 | $params = array(); 2489 | $this->id_format($id); 2490 | $params['id'] = $id; 2491 | return $this->oauth->get( 'favorites/show', $params ); 2492 | } 2493 | 2494 | 2495 | /** 2496 | * 根据标签获取当前登录用户该标签下的收藏列表 2497 | * 2498 | * 对应API:{@link http://open.weibo.com/wiki/2/favorites/by_tags favorites/by_tags} 2499 | * 2500 | * 2501 | * @param int $tid 需要查询的标签ID。' 2502 | * @param int $count 单页返回的记录条数,默认为50。 2503 | * @param int $page 返回结果的页码,默认为1。 2504 | * @return array 2505 | */ 2506 | function favorites_by_tags( $tid, $page = 1, $count = 50) 2507 | { 2508 | $params = array(); 2509 | $params['tid'] = $tid; 2510 | $params['count'] = $count; 2511 | $params['page'] = $page; 2512 | return $this->oauth->get( 'favorites/by_tags', $params ); 2513 | } 2514 | 2515 | 2516 | /** 2517 | * 获取当前登录用户的收藏标签列表 2518 | * 2519 | * 对应API:{@link http://open.weibo.com/wiki/2/favorites/tags favorites/tags} 2520 | * 2521 | * @access public 2522 | * @param int $count 单页返回的记录条数,默认为50。 2523 | * @param int $page 返回结果的页码,默认为1。 2524 | * @return array 2525 | */ 2526 | function favorites_tags( $page = 1, $count = 50) 2527 | { 2528 | $params = array(); 2529 | $params['count'] = $count; 2530 | $params['page'] = $page; 2531 | return $this->oauth->get( 'favorites/tags', $params ); 2532 | } 2533 | 2534 | 2535 | /** 2536 | * 收藏一条微博信息 2537 | * 2538 | * 对应API:{@link http://open.weibo.com/wiki/2/favorites/create favorites/create} 2539 | * 2540 | * @access public 2541 | * @param int $sid 收藏的微博id 2542 | * @return array 2543 | */ 2544 | function add_to_favorites( $sid ) 2545 | { 2546 | $this->id_format($sid); 2547 | $params = array(); 2548 | $params['id'] = $sid; 2549 | 2550 | return $this->oauth->post( 'favorites/create', $params ); 2551 | } 2552 | 2553 | /** 2554 | * 删除微博收藏。 2555 | * 2556 | * 对应API:{@link http://open.weibo.com/wiki/2/favorites/destroy favorites/destroy} 2557 | * 2558 | * @access public 2559 | * @param int $id 要删除的收藏微博信息ID. 2560 | * @return array 2561 | */ 2562 | function remove_from_favorites( $id ) 2563 | { 2564 | $this->id_format($id); 2565 | $params = array(); 2566 | $params['id'] = $id; 2567 | return $this->oauth->post( 'favorites/destroy', $params); 2568 | } 2569 | 2570 | 2571 | /** 2572 | * 批量删除微博收藏。 2573 | * 2574 | * 批量删除当前登录用户的收藏。出现异常时,返回HTTP400错误。 2575 | *
对应API:{@link http://open.weibo.com/wiki/2/favorites/destroy_batch favorites/destroy_batch} 2576 | * 2577 | * @access public 2578 | * @param mixed $fids 欲删除的一组私信ID,用半角逗号隔开,或者由一组评论ID组成的数组。最多20个。例如:"231101027525486630,201100826122315375"或array(231101027525486630,201100826122315375); 2579 | * @return array 2580 | */ 2581 | function remove_from_favorites_batch( $fids ) 2582 | { 2583 | $params = array(); 2584 | if (is_array($fids) && !empty($fids)) { 2585 | foreach ($fids as $k => $v) { 2586 | $this->id_format($fids[$k]); 2587 | } 2588 | $params['ids'] = join(',', $fids); 2589 | } else { 2590 | $params['ids'] = $fids; 2591 | } 2592 | 2593 | return $this->oauth->post( 'favorites/destroy_batch', $params); 2594 | } 2595 | 2596 | 2597 | /** 2598 | * 更新一条收藏的收藏标签 2599 | * 2600 | * 对应API:{@link http://open.weibo.com/wiki/2/favorites/tags/update favorites/tags/update} 2601 | * 2602 | * @access public 2603 | * @param int $id 需要更新的收藏ID。 2604 | * @param string $tags 需要更新的标签内容,用半角逗号分隔,最多不超过2条。 2605 | * @return array 2606 | */ 2607 | function favorites_tags_update( $id, $tags ) 2608 | { 2609 | $params = array(); 2610 | $params['id'] = $id; 2611 | if (is_array($tags) && !empty($tags)) { 2612 | foreach ($tags as $k => $v) { 2613 | $this->id_format($tags[$k]); 2614 | } 2615 | $params['tags'] = join(',', $tags); 2616 | } else { 2617 | $params['tags'] = $tags; 2618 | } 2619 | return $this->oauth->post( 'favorites/tags/update', $params ); 2620 | } 2621 | 2622 | /** 2623 | * 更新当前登录用户所有收藏下的指定标签 2624 | * 2625 | * 对应API:{@link http://open.weibo.com/wiki/2/favorites/tags/update_batch favorites/tags/update_batch} 2626 | * 2627 | * @param int $tid 需要更新的标签ID。必填 2628 | * @param string $tag 需要更新的标签内容。必填 2629 | * @return array 2630 | */ 2631 | function favorites_update_batch( $tid, $tag ) 2632 | { 2633 | $params = array(); 2634 | $params['tid'] = $tid; 2635 | $params['tag'] = $tag; 2636 | return $this->oauth->post( 'favorites/tags/update_batch', $params); 2637 | } 2638 | 2639 | /** 2640 | * 删除当前登录用户所有收藏下的指定标签 2641 | * 2642 | * 删除标签后,该用户所有收藏中,添加了该标签的收藏均解除与该标签的关联关系 2643 | *
对应API:{@link http://open.weibo.com/wiki/2/favorites/tags/destroy_batch favorites/tags/destroy_batch} 2644 | * 2645 | * @param int $tid 需要更新的标签ID。必填 2646 | * @return array 2647 | */ 2648 | function favorites_tags_destroy_batch( $tid ) 2649 | { 2650 | $params = array(); 2651 | $params['tid'] = $tid; 2652 | return $this->oauth->post( 'favorites/tags/destroy_batch', $params); 2653 | } 2654 | 2655 | /** 2656 | * 获取某用户的话题 2657 | * 2658 | * 对应API:{@link http://open.weibo.com/wiki/2/trends trends} 2659 | * 2660 | * @param int $uid 查询用户的ID。默认为当前用户。可选。 2661 | * @param int $page 指定返回结果的页码。可选。 2662 | * @param int $count 单页大小。缺省值10。可选。 2663 | * @return array 2664 | */ 2665 | function get_trends( $uid = NULL, $page = 1, $count = 10 ) 2666 | { 2667 | $params = array(); 2668 | if ($uid) { 2669 | $params['uid'] = $uid; 2670 | } else { 2671 | $user_info = $this->get_uid(); 2672 | $params['uid'] = $user_info['uid']; 2673 | } 2674 | $this->id_format( $params['uid'] ); 2675 | $params['page'] = $page; 2676 | $params['count'] = $count; 2677 | return $this->oauth->get( 'trends', $params ); 2678 | } 2679 | 2680 | 2681 | /** 2682 | * 判断当前用户是否关注某话题 2683 | * 2684 | * 对应API:{@link http://open.weibo.com/wiki/2/trends/is_follow trends/is_follow} 2685 | * 2686 | * @access public 2687 | * @param string $trend_name 话题关键字。 2688 | * @return array 2689 | */ 2690 | function trends_is_follow( $trend_name ) 2691 | { 2692 | $params = array(); 2693 | $params['trend_name'] = $trend_name; 2694 | return $this->oauth->get( 'trends/is_follow', $params ); 2695 | } 2696 | 2697 | /** 2698 | * 返回最近一小时内的热门话题 2699 | * 2700 | * 对应API:{@link http://open.weibo.com/wiki/2/trends/hourly trends/hourly} 2701 | * 2702 | * @param int $base_app 是否基于当前应用来获取数据。1表示基于当前应用来获取数据,默认为0。可选。 2703 | * @return array 2704 | */ 2705 | function hourly_trends( $base_app = 0 ) 2706 | { 2707 | $params = array(); 2708 | $params['base_app'] = $base_app; 2709 | 2710 | return $this->oauth->get( 'trends/hourly', $params ); 2711 | } 2712 | 2713 | /** 2714 | * 返回最近一天内的热门话题 2715 | * 2716 | * 对应API:{@link http://open.weibo.com/wiki/2/trends/daily trends/daily} 2717 | * 2718 | * @param int $base_app 是否基于当前应用来获取数据。1表示基于当前应用来获取数据,默认为0。可选。 2719 | * @return array 2720 | */ 2721 | function daily_trends( $base_app = 0 ) 2722 | { 2723 | $params = array(); 2724 | $params['base_app'] = $base_app; 2725 | 2726 | return $this->oauth->get( 'trends/daily', $params ); 2727 | } 2728 | 2729 | /** 2730 | * 返回最近一周内的热门话题 2731 | * 2732 | * 对应API:{@link http://open.weibo.com/wiki/2/trends/weekly trends/weekly} 2733 | * 2734 | * @access public 2735 | * @param int $base_app 是否基于当前应用来获取数据。1表示基于当前应用来获取数据,默认为0。可选。 2736 | * @return array 2737 | */ 2738 | function weekly_trends( $base_app = 0 ) 2739 | { 2740 | $params = array(); 2741 | $params['base_app'] = $base_app; 2742 | 2743 | return $this->oauth->get( 'trends/weekly', $params ); 2744 | } 2745 | 2746 | /** 2747 | * 关注某话题 2748 | * 2749 | * 对应API:{@link http://open.weibo.com/wiki/2/trends/follow trends/follow} 2750 | * 2751 | * @access public 2752 | * @param string $trend_name 要关注的话题关键词。 2753 | * @return array 2754 | */ 2755 | function follow_trends( $trend_name ) 2756 | { 2757 | $params = array(); 2758 | $params['trend_name'] = $trend_name; 2759 | return $this->oauth->post( 'trends/follow', $params ); 2760 | } 2761 | 2762 | /** 2763 | * 取消对某话题的关注 2764 | * 2765 | * 对应API:{@link http://open.weibo.com/wiki/2/trends/destroy trends/destroy} 2766 | * 2767 | * @access public 2768 | * @param int $tid 要取消关注的话题ID。 2769 | * @return array 2770 | */ 2771 | function unfollow_trends( $tid ) 2772 | { 2773 | $this->id_format($tid); 2774 | 2775 | $params = array(); 2776 | $params['trend_id'] = $tid; 2777 | 2778 | return $this->oauth->post( 'trends/destroy', $params ); 2779 | } 2780 | 2781 | /** 2782 | * 返回指定用户的标签列表 2783 | * 2784 | * 对应API:{@link http://open.weibo.com/wiki/2/tags tags} 2785 | * 2786 | * @param int $uid 查询用户的ID。默认为当前用户。可选。 2787 | * @param int $page 指定返回结果的页码。可选。 2788 | * @param int $count 单页大小。缺省值20,最大值200。可选。 2789 | * @return array 2790 | */ 2791 | function get_tags( $uid = NULL, $page = 1, $count = 20 ) 2792 | { 2793 | $params = array(); 2794 | if ( $uid ) { 2795 | $params['uid'] = $uid; 2796 | } else { 2797 | $user_info = $this->get_uid(); 2798 | $params['uid'] = $user_info['uid']; 2799 | } 2800 | $this->id_format( $params['uid'] ); 2801 | $params['page'] = $page; 2802 | $params['count'] = $count; 2803 | return $this->oauth->get( 'tags', $params ); 2804 | } 2805 | 2806 | /** 2807 | * 批量获取用户的标签列表 2808 | * 2809 | * 对应API:{@link http://open.weibo.com/wiki/2/tags/tags_batch tags/tags_batch} 2810 | * 2811 | * @param string $uids 要获取标签的用户ID。最大20,逗号分隔。必填 2812 | * @return array 2813 | */ 2814 | function get_tags_batch( $uids ) 2815 | { 2816 | $params = array(); 2817 | if (is_array( $uids ) && !empty( $uids )) { 2818 | foreach ($uids as $k => $v) { 2819 | $this->id_format( $uids[$k] ); 2820 | } 2821 | $params['uids'] = join(',', $uids); 2822 | } else { 2823 | $params['uids'] = $uids; 2824 | } 2825 | return $this->oauth->get( 'tags/tags_batch', $params ); 2826 | } 2827 | 2828 | /** 2829 | * 返回用户感兴趣的标签 2830 | * 2831 | * 对应API:{@link http://open.weibo.com/wiki/2/tags/suggestions tags/suggestions} 2832 | * 2833 | * @access public 2834 | * @param int $count 单页大小。缺省值10,最大值10。可选。 2835 | * @return array 2836 | */ 2837 | function get_suggest_tags( $count = 10) 2838 | { 2839 | $params = array(); 2840 | $params['count'] = intval($count); 2841 | return $this->oauth->get( 'tags/suggestions', $params ); 2842 | } 2843 | 2844 | /** 2845 | * 为当前登录用户添加新的用户标签 2846 | * 2847 | * 对应API:{@link http://open.weibo.com/wiki/2/tags/create tags/create} 2848 | * 2849 | * @access public 2850 | * @param mixed $tags 要创建的一组标签,每个标签的长度不可超过7个汉字,14个半角字符。多个标签之间用逗号间隔,或由多个标签构成的数组。如:"abc,drf,efgh,tt"或array("abc", "drf", "efgh", "tt") 2851 | * @return array 2852 | */ 2853 | function add_tags( $tags ) 2854 | { 2855 | $params = array(); 2856 | if (is_array($tags) && !empty($tags)) { 2857 | $params['tags'] = join(',', $tags); 2858 | } else { 2859 | $params['tags'] = $tags; 2860 | } 2861 | return $this->oauth->post( 'tags/create', $params); 2862 | } 2863 | 2864 | /** 2865 | * 删除标签 2866 | * 2867 | * 对应API:{@link http://open.weibo.com/wiki/2/tags/destroy tags/destroy} 2868 | * 2869 | * @access public 2870 | * @param int $tag_id 标签ID,必填参数 2871 | * @return array 2872 | */ 2873 | function delete_tag( $tag_id ) 2874 | { 2875 | $params = array(); 2876 | $params['tag_id'] = $tag_id; 2877 | return $this->oauth->post( 'tags/destroy', $params ); 2878 | } 2879 | 2880 | /** 2881 | * 批量删除标签 2882 | * 2883 | * 对应API:{@link http://open.weibo.com/wiki/2/tags/destroy_batch tags/destroy_batch} 2884 | * 2885 | * @access public 2886 | * @param mixed $ids 必选参数,要删除的tag id,多个id用半角逗号分割,最多10个。或由多个tag id构成的数组。如:“553,554,555"或array(553, 554, 555) 2887 | * @return array 2888 | */ 2889 | function delete_tags( $ids ) 2890 | { 2891 | $params = array(); 2892 | if (is_array($ids) && !empty($ids)) { 2893 | $params['ids'] = join(',', $ids); 2894 | } else { 2895 | $params['ids'] = $ids; 2896 | } 2897 | return $this->oauth->post( 'tags/destroy_batch', $params ); 2898 | } 2899 | 2900 | 2901 | /** 2902 | * 验证昵称是否可用,并给予建议昵称 2903 | * 2904 | * 对应API:{@link http://open.weibo.com/wiki/2/register/verify_nickname register/verify_nickname} 2905 | * 2906 | * @param string $nickname 需要验证的昵称。4-20个字符,支持中英文、数字、"_"或减号。必填 2907 | * @return array 2908 | */ 2909 | function verify_nickname( $nickname ) 2910 | { 2911 | $params = array(); 2912 | $params['nickname'] = $nickname; 2913 | return $this->oauth->get( 'register/verify_nickname', $params ); 2914 | } 2915 | 2916 | 2917 | 2918 | /** 2919 | * 搜索用户时的联想搜索建议 2920 | * 2921 | * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/users search/suggestions/users} 2922 | * 2923 | * @param string $q 搜索的关键字,必须做URLencoding。必填,中间最好不要出现空格 2924 | * @param int $count 返回的记录条数,默认为10。 2925 | * @return array 2926 | */ 2927 | function search_users( $q, $count = 10 ) 2928 | { 2929 | $params = array(); 2930 | $params['q'] = $q; 2931 | $params['count'] = $count; 2932 | return $this->oauth->get( 'search/suggestions/users', $params ); 2933 | } 2934 | 2935 | 2936 | /** 2937 | * 搜索微博时的联想搜索建议 2938 | * 2939 | * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/statuses search/suggestions/statuses} 2940 | * 2941 | * @param string $q 搜索的关键字,必须做URLencoding。必填 2942 | * @param int $count 返回的记录条数,默认为10。 2943 | * @return array 2944 | */ 2945 | function search_statuses( $q, $count = 10) 2946 | { 2947 | $params = array(); 2948 | $params['q'] = $q; 2949 | $params['count'] = $count; 2950 | return $this->oauth->get( 'search/suggestions/statuses', $params ); 2951 | } 2952 | 2953 | 2954 | /** 2955 | * 搜索学校时的联想搜索建议 2956 | * 2957 | * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/schools search/suggestions/schools} 2958 | * 2959 | * @param string $q 搜索的关键字,必须做URLencoding。必填 2960 | * @param int $count 返回的记录条数,默认为10。 2961 | * @param int type 学校类型,0:全部、1:大学、2:高中、3:中专技校、4:初中、5:小学,默认为0。选填 2962 | * @return array 2963 | */ 2964 | function search_schools( $q, $count = 10, $type = 1) 2965 | { 2966 | $params = array(); 2967 | $params['q'] = $q; 2968 | $params['count'] = $count; 2969 | $params['type'] = $type; 2970 | return $this->oauth->get( 'search/suggestions/schools', $params ); 2971 | } 2972 | 2973 | /** 2974 | * 搜索公司时的联想搜索建议 2975 | * 2976 | * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/companies search/suggestions/companies} 2977 | * 2978 | * @param string $q 搜索的关键字,必须做URLencoding。必填 2979 | * @param int $count 返回的记录条数,默认为10。 2980 | * @return array 2981 | */ 2982 | function search_companies( $q, $count = 10) 2983 | { 2984 | $params = array(); 2985 | $params['q'] = $q; 2986 | $params['count'] = $count; 2987 | return $this->oauth->get( 'search/suggestions/companies', $params ); 2988 | } 2989 | 2990 | 2991 | /** 2992 | * @用户时的联想建议 2993 | * 2994 | * 对应API:{@link http://open.weibo.com/wiki/2/search/suggestions/at_users search/suggestions/at_users} 2995 | * 2996 | * @param string $q 搜索的关键字,必须做URLencoding。必填 2997 | * @param int $count 返回的记录条数,默认为10。 2998 | * @param int $type 联想类型,0:关注、1:粉丝。必填 2999 | * @param int $range 联想范围,0:只联想关注人、1:只联想关注人的备注、2:全部,默认为2。选填 3000 | * @return array 3001 | */ 3002 | function search_at_users( $q, $count = 10, $type=0, $range = 2) 3003 | { 3004 | $params = array(); 3005 | $params['q'] = $q; 3006 | $params['count'] = $count; 3007 | $params['type'] = $type; 3008 | $params['range'] = $range; 3009 | return $this->oauth->get( 'search/suggestions/at_users', $params ); 3010 | } 3011 | 3012 | 3013 | 3014 | 3015 | 3016 | /** 3017 | * 搜索与指定的一个或多个条件相匹配的微博 3018 | * 3019 | * 对应API:{@link http://open.weibo.com/wiki/2/search/statuses search/statuses} 3020 | * 3021 | * @param array $query 搜索选项。格式:array('key0'=>'value0', 'key1'=>'value1', ....)。支持的key: 3022 | * - q string 搜索的关键字,必须进行URLencode。 3023 | * - filter_ori int 过滤器,是否为原创,0:全部、1:原创、2:转发,默认为0。 3024 | * - filter_pic int 过滤器。是否包含图片,0:全部、1:包含、2:不包含,默认为0。 3025 | * - fuid int 搜索的微博作者的用户UID。 3026 | * - province int 搜索的省份范围,省份ID。 3027 | * - city int 搜索的城市范围,城市ID。 3028 | * - starttime int 开始时间,Unix时间戳。 3029 | * - endtime int 结束时间,Unix时间戳。 3030 | * - count int 单页返回的记录条数,默认为10。 3031 | * - page int 返回结果的页码,默认为1。 3032 | * - needcount boolean 返回结果中是否包含返回记录数,true:返回、false:不返回,默认为false。 3033 | * - base_app int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 3034 | * needcount参数不同,会导致相应的返回值结构不同 3035 | * 以上参数全部选填 3036 | * @return array 3037 | */ 3038 | function search_statuses_high( $query ) 3039 | { 3040 | return $this->oauth->get( 'search/statuses', $query ); 3041 | } 3042 | 3043 | 3044 | 3045 | /** 3046 | * 通过关键词搜索用户 3047 | * 3048 | * 对应API:{@link http://open.weibo.com/wiki/2/search/users search/users} 3049 | * 3050 | * @param array $query 搜索选项。格式:array('key0'=>'value0', 'key1'=>'value1', ....)。支持的key: 3051 | * - q string 搜索的关键字,必须进行URLencode。 3052 | * - snick int 搜索范围是否包含昵称,0:不包含、1:包含。 3053 | * - sdomain int 搜索范围是否包含个性域名,0:不包含、1:包含。 3054 | * - sintro int 搜索范围是否包含简介,0:不包含、1:包含。 3055 | * - stag int 搜索范围是否包含标签,0:不包含、1:包含。 3056 | * - province int 搜索的省份范围,省份ID。 3057 | * - city int 搜索的城市范围,城市ID。 3058 | * - gender string 搜索的性别范围,m:男、f:女。 3059 | * - comorsch string 搜索的公司学校名称。 3060 | * - sort int 排序方式,1:按更新时间、2:按粉丝数,默认为1。 3061 | * - count int 单页返回的记录条数,默认为10。 3062 | * - page int 返回结果的页码,默认为1。 3063 | * - base_app int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。 3064 | * 以上所有参数全部选填 3065 | * @return array 3066 | */ 3067 | function search_users_keywords( $query ) 3068 | { 3069 | return $this->oauth->get( 'search/users', $query ); 3070 | } 3071 | 3072 | 3073 | 3074 | /** 3075 | * 获取系统推荐用户 3076 | * 3077 | * 返回系统推荐的用户列表。 3078 | *
对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/hot suggestions/users/hot} 3079 | * 3080 | * @access public 3081 | * @param string $category 分类,可选参数,返回某一类别的推荐用户,默认为 default。如果不在以下分类中,返回空列表:
3082 | * - default:人气关注 3083 | * - ent:影视名星 3084 | * - hk_famous:港台名人 3085 | * - model:模特 3086 | * - cooking:美食&健康 3087 | * - sport:体育名人 3088 | * - finance:商界名人 3089 | * - tech:IT互联网 3090 | * - singer:歌手 3091 | * - writer:作家 3092 | * - moderator:主持人 3093 | * - medium:媒体总编 3094 | * - stockplayer:炒股高手 3095 | * @return array 3096 | */ 3097 | function hot_users( $category = "default" ) 3098 | { 3099 | $params = array(); 3100 | $params['category'] = $category; 3101 | 3102 | return $this->oauth->get( 'suggestions/users/hot', $params ); 3103 | } 3104 | 3105 | /** 3106 | * 获取用户可能感兴趣的人 3107 | * 3108 | * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/may_interested suggestions/users/may_interested} 3109 | * 3110 | * @access public 3111 | * @param int $page 返回结果的页码,默认为1。 3112 | * @param int $count 单页返回的记录条数,默认为10。 3113 | * @return array 3114 | * @ignore 3115 | */ 3116 | function suggestions_may_interested( $page = 1, $count = 10 ) 3117 | { 3118 | $params = array(); 3119 | $params['page'] = $page; 3120 | $params['count'] = $count; 3121 | return $this->oauth->get( 'suggestions/users/may_interested', $params); 3122 | } 3123 | 3124 | /** 3125 | * 根据一段微博正文推荐相关微博用户。 3126 | * 3127 | * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/by_status suggestions/users/by_status} 3128 | * 3129 | * @access public 3130 | * @param string $content 微博正文内容。 3131 | * @param int $num 返回结果数目,默认为10。 3132 | * @return array 3133 | */ 3134 | function suggestions_users_by_status( $content, $num = 10 ) 3135 | { 3136 | $params = array(); 3137 | $params['content'] = $content; 3138 | $params['num'] = $num; 3139 | return $this->oauth->get( 'suggestions/users/by_status', $params); 3140 | } 3141 | 3142 | /** 3143 | * 热门收藏 3144 | * 3145 | * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/favorites/hot suggestions/favorites/hot} 3146 | * 3147 | * @param int $count 每页返回结果数,默认20。选填 3148 | * @param int $page 返回页码,默认1。选填 3149 | * @return array 3150 | */ 3151 | function hot_favorites( $page = 1, $count = 20 ) 3152 | { 3153 | $params = array(); 3154 | $params['count'] = $count; 3155 | $params['page'] = $page; 3156 | return $this->oauth->get( 'suggestions/favorites/hot', $params); 3157 | } 3158 | 3159 | /** 3160 | * 把某人标识为不感兴趣的人 3161 | * 3162 | * 对应API:{@link http://open.weibo.com/wiki/2/suggestions/users/not_interested suggestions/users/not_interested} 3163 | * 3164 | * @param int $uid 不感兴趣的用户的UID。 3165 | * @return array 3166 | */ 3167 | function put_users_not_interested( $uid ) 3168 | { 3169 | $params = array(); 3170 | $params['uid'] = $uid; 3171 | return $this->oauth->post( 'suggestions/users/not_interested', $params); 3172 | } 3173 | 3174 | 3175 | 3176 | // ========================================= 3177 | 3178 | /** 3179 | * @ignore 3180 | */ 3181 | protected function request_with_pager( $url, $page = false, $count = false, $params = array() ) 3182 | { 3183 | if( $page ) $params['page'] = $page; 3184 | if( $count ) $params['count'] = $count; 3185 | 3186 | return $this->oauth->get($url, $params ); 3187 | } 3188 | 3189 | /** 3190 | * @ignore 3191 | */ 3192 | protected function request_with_uid( $url, $uid_or_name, $page = false, $count = false, $cursor = false, $post = false, $params = array()) 3193 | { 3194 | if( $page ) $params['page'] = $page; 3195 | if( $count ) $params['count'] = $count; 3196 | if( $cursor )$params['cursor'] = $cursor; 3197 | 3198 | if( $post ) $method = 'post'; 3199 | else $method = 'get'; 3200 | 3201 | if ( $uid_or_name !== NULL ) { 3202 | $this->id_format($uid_or_name); 3203 | $params['id'] = $uid_or_name; 3204 | } 3205 | 3206 | return $this->oauth->$method($url, $params ); 3207 | 3208 | } 3209 | 3210 | /** 3211 | * @ignore 3212 | */ 3213 | protected function id_format(&$id) { 3214 | if ( is_float($id) ) { 3215 | $id = number_format($id, 0, '', ''); 3216 | } elseif ( is_string($id) ) { 3217 | $id = trim($id); 3218 | } 3219 | } 3220 | 3221 | } 3222 | --------------------------------------------------------------------------------