saetv2.ex.class.php 112 KB

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