saetv2.ex.class.php 105 KB

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