saetv2.ex.class.php 104 KB

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