saetv2.ex.class.php 107 KB

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