发布一条微博信息。
注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。
注意:为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。
对应API:{@link http://open.weibo.com/wiki/2/statuses/update statuses/update}
注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。
注意:为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。
对应API:{@link http://open.weibo.com/wiki/2/statuses/update statuses/update}
public update ( string $status, float $lat = NULL, float $long = NULL, mixed $annotations = NULL, integer $visible ) : array | ||
$status | string | 要更新的微博信息。信息内容不超过140个汉字, 为空返回400错误。 |
$lat | float | 纬度,发表当前微博所在的地理位置,有效范围 -90.0到+90.0, +表示北纬。可选。 |
$long | float | 经度。有效范围-180.0到+180.0, +表示东经。可选。 |
$annotations | mixed | 可选参数。元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息。每条微博可以包含一个或者多个元数据。请以json字串的形式提交,字串长度不超过512个字符,或者数组方式,要求json_encode后字串长度不超过512个字符。具体内容可以自定。例如:'[{"type2":123}, {"a":"b", "c":"d"}]'或array(array("type2"=>123), array("a"=>"b", "c"=>"d"))。 |
$visible | integer | 微博的可见性,0:所有人能看,1:仅自己可见,2:密友可见,3:指定分组可见,默认为0 |
return | array |
function send2wbto($content) { $c = new SaeTClientV2(WB_AKEY, WB_SKEY, file_get_contents("../include/weibo/token.txt")); $ret = $c->update($content); //发送微博 if (isset($ret['error_code']) && $ret['error_code'] > 0) { echo "<p>发送失败,错误:{$ret['error_code']}:{$ret['error']}</p>"; } else { echo "<p>发送成功</p>"; } }
/** * 推送信息 */ public function send($bind_user, $data) { $info = unserialize($bind_user['info']); $client = new SaeTClientV2($this->setting['app_key'], $this->setting['app_secret'], $info['access_token']); try { isset($data['url']) && ($data['content'] = $data['content'] . $data['url']); if (isset($data['img']) && !empty($data['img'])) { return $client->upload($data['content'], $data['img']); } else { return $client->update($data['content']); } } catch (Exception $e) { } }
public function send() { $post = $this->__get_post(); if (empty($post['id'])) { echo $this->fun->json_encode(array('error' => -1, 'msg' => '转发的微博信息不不存在')); exit; } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ret = $c->update($post['content']); if (isset($ret['error_code']) && $ret['error_code'] > 0) { echo $this->fun->json_encode(array('error' => -5, 'msg' => '转发不成功,请过会操作')); exit; //echo "<p>发送失败,错误:{$ret['error_code']}:{$ret['error']}</p>"; } else { $this->db->update('award_wb', array('share_wb_id' => $ret['idstr']), 'id=' . $post['id']); echo $this->fun->json_encode(array('error' => '0', 'msg' => '中奖信息分享成功咯')); exit; } }
$id = file_get_contents("id.log"); echo $id; for ($i = 0; $i < count($ms['statuses']); $i++) { if (!empty($ms['statuses'][$i]['retweeted_status'])) { if ($ms['statuses'][$i]['retweeted_status']['reposts_count'] > 80 || $ms['statuses'][$i]['retweeted_status']['comments_count'] > 80) { } if ($ms['statuses'][$i]['retweeted_status']['id'] > $id) { if (!empty($ms['statuses'][$i]['retweeted_status']['original_pic'])) { if (strpos($ms['statuses'][$i]['retweeted_status']['text'], "http") > 0) { $c->upload(str_replace("http", "(via " . $ms['statuses'][$i]['retweeted_status']['user']['name'] . ") http", $ms['statuses'][$i]['retweeted_status']['text']), $ms['statuses'][$i]['retweeted_status']['original_pic'], null, null); } else { $c->upload($ms['statuses'][$i]['retweeted_status']['text'] . "(via " . $ms['statuses'][$i]['retweeted_status']['user']['name'] . ")", $ms['statuses'][$i]['retweeted_status']['original_pic'], null, null); } } else { if (strpos($ms['statuses'][$i]['retweeted_status']['text'], "http") > 0) { $c->update(str_replace("http", "(via " . $ms['statuses'][$i]['retweeted_status']['user']['name'] . ") http", $ms['statuses'][$i]['retweeted_status']['text'])); } else { $c->update($ms['statuses'][$i]['retweeted_status']['text'] . "(via " . $ms['statuses'][$i]['retweeted_status']['user']['name'] . ")"); } } } continue; } if ($ms['statuses'][$i]['comments_count'] > 80 || $ms['statuses'][$i]['reposts_count'] > 80) { if ($ms['statuses'][$i]['id'] > $id) { if (!empty($ms['statuses'][$i]['original_pic'])) { if (strpos($ms['statuses'][$i]['text'], "http") > 0) { $c->upload(str_replace("http", "(via " . $ms['statuses'][$i]['user']['name'] . ") http", $ms['statuses'][$i]['text']), $ms['statuses'][$i]['original_pic'], null, null); } else { $c->upload($ms['statuses'][$i]['text'] . "(via " . $ms['statuses'][$i]['user']['name'] . ")", $ms['statuses'][$i]['original_pic'], null, null); }
/** * sinaweibo上传图片并发布一条新微博 */ public function addSinaWeiboUpload($bindinfo, $params) { include_once BASE_DATA_PATH . DS . 'api' . DS . 'snsapi' . DS . 'sinaweibo' . DS . 'config.php'; include_once BASE_DATA_PATH . DS . 'api' . DS . 'snsapi' . DS . 'sinaweibo' . DS . 'saetv2.ex.class.php'; $c = new SaeTClientV2(C('share_sinaweibo_appid'), C('share_sinaweibo_appkey'), $bindinfo['snsbind_accesstoken']); if ($params['images']) { $c->upload($params['title'] . $params['comment'] . $params['url'], $params['images']); } else { $c->update($params['title'] . $params['comment'] . $params['url']); } }
/** * 新浪微博分享 * * @param array $data * @return Bool|String */ public function _execute_sinashare($data) { $data = dr_string2array($data); if (!$data) { return '执行值不存在'; } $config = (require FCPATH . 'config/oauth.php'); if (!isset($config['sina']) || !isset($config['sina']['key'])) { return 'Sina配置文件不正确或者Key不存在'; } // 查询OAuth2授权信息 $auth = $this->db->where('uid', (int) $data['uid'])->where('oauth', 'sina')->limit(1)->get('member_oauth')->row_array(); if (!$auth) { return '会员uid:' . $data['uid'] . ' 授权信息不存在'; } require_once FCPATH . 'dayrui/libraries/Share/Sina.php'; $auth = new SaeTClientV2($config['sina']['key'], $config['sina']['secret'], $auth['access_token']); if ($data['thumb']) { $call = $auth->upload(dr_strcut($data['title'], 120) . ' ' . $data['url'], $data['thumb']); } else { $call = $auth->update(dr_strcut($data['title'], 120) . ' ' . $data['url']); } return isset($call['id']) && $call['id'] ? TRUE : (isset($call['error']) && $call['error'] ? $call['error'] : $call); }
function ajaxsaveweiboreplyAction() { $this->_helper->layout->disableLayout(); $topicId = urldecode($this->_request->getParam('topicId')); $annotations = array('wildfire_community', $topicId); $tokenNamespace = new Zend_Session_Namespace('token'); $token = $tokenNamespace->token; if ($token) { include_once 'weiboconfig.php'; $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']); $content = $this->_request->getParam('content'); $result = $c->update($content, NULL, NULL, $annotations); if (isset($result['error_code'])) { print_r($result); } else { $mid = $result['idstr']; $userId = $this->_currentUser->id; $irrModel = new InboxReplyRecord(); $row = $irrModel->createRow(); $row->topic = $topicId; $row->consumer = $userId; $row->platform_type = "weibo"; $row->sns_reply_id = $result['idstr']; $row->save(); $replyCount = $irrModel->findReplyCount(array('consumer' => $userId, 'platform_type' => 'weibo', 'topic' => $topicId)); if ($replyCount < 2) { $rewardPointTransactionRecordModel = new RewardPointTransactionRecord(); $rewardPointTransaction = array("consumer_id" => $userId, "date" => date("Y-m-d H:i:s"), "transaction_id" => "11", "point_amount" => "10"); $id = $rewardPointTransactionRecordModel->insert($rewardPointTransaction); $row->reward_point_transaction_record_id = $id; $row->save(); $rankModel = new Rank(); $rankModel->changeConsumerRank($userId); } echo "ok"; } } }
function Sina($data) { require_once APP_ROOT_PATH . 'system/api_login/sina/saetv2.ex.class.php'; $uid = intval($GLOBALS['user_info']['id']); $udata = $GLOBALS['db']->getRow("select sina_token from " . DB_PREFIX . "user where id = " . $uid); $client = new SaeTClientV2($GLOBALS['m_config']['sina_app_key'], $GLOBALS['m_config']['sina_app_secret'], $udata['sina_token']); if (empty($data['img'])) { $msg = $client->update($data['content']); } else { $msg = $client->upload($data['content'], $data['img']); } if ($msg['error']) { $result['status'] = false; $result['code'] = $msg['error_code']; } else { $result['status'] = true; $result['code'] = 0; } return $result; }
function yjl_uwb($u, $c, $i, $e = '', $p = '') { global $r_main, $yjl_tpath, $dbprefix, $yjl_url, $yjl_isdebug; if ($yjl_isdebug == 0) { if (trim($r_main['sina_k']) != '' && trim($r_main['sina_s']) != '') { $q_rex = sprintf('select profile, access_token from %s where uid=%s and length(access_token)>0 limit 1', $dbprefix . 'xwb_bind_info', $u); $rex = mysql_query($q_rex) or die(mysql_error()); $r_rex = mysql_fetch_assoc($rex); if (mysql_num_rows($rex) > 0) { $a_xwb = json_decode($r_rex['profile'], true); if (isset($a_xwb['bind_setting']) && $a_xwb['bind_setting'] == 1) { require_once $e . 'lib/saetv2.ex.class.php'; $so = new SaeTClientV2($r_main['sina_k'], $r_main['sina_s'], $r_rex['access_token']); if ($p != '') { $rs = $so->upload($c, $e . $p); } else { $rs = $so->update($c); } if (isset($rs['mid']) && $rs['mid'] != '') { $iSQL = sprintf('insert into %s (tid, mid) values (%s, %s)', $dbprefix . 'xwb_bind_topic', $i, $rs['mid']); $result = mysql_query($iSQL) or die(mysql_error()); } } } mysql_free_result($rex); } if (trim($r_main['tqq_k']) != '' && trim($r_main['tqq_s']) != '') { $q_rex = sprintf('select token, tsecret from %s where uid=%s and length(token)>0 and length(tsecret)>0 and synctoqq>0 limit 1', $dbprefix . 'qqwb_bind_info', $u); $rex = mysql_query($q_rex) or die(mysql_error()); $r_rex = mysql_fetch_assoc($rex); if (mysql_num_rows($rex) > 0) { require_once $e . 'lib/tqq_opent.php'; require_once $e . 'lib/tqq_client.php'; $tqq = new MBApiClient($r_main['tqq_k'], $r_main['tqq_s'], $r_rex['token'], $r_rex['tsecret']); $tqq_a = array('c' => $c, 'ip' => $_SERVER['REMOTE_ADDR'], 'j' => '', 'w' => '', 'type' => 1); if ($p != '') { $ps = getimagesize($p); $p_data = file_get_contents($p); $tqq_a['p'] = array($ps['mime'], $p, $p_data); } $rq = $tqq->postOne($tqq_a); if (isset($rq['data']['id']) && $rq['data']['id'] != '') { $iSQL = sprintf('insert into %s (tid, qqwb_id) values (%s, %s)', $dbprefix . 'qqwb_bind_topic', $i, $rq['data']['id']); $result = mysql_query($iSQL) or die(mysql_error()); } } mysql_free_result($rex); } } }
public function sendwb() { // 获取消息正文 发晒单 bask 写心情 mood /* * if(isset($this->request->post['bask']) && ($this->request->post['bask'])) { $message_text = $this->request->post['bask']; $message_flag = 1; } else if(isset($this->request->post['mood']) && ($this->request->post['mood'])) { $message_text = $this->request->post['mood']; $message_flag = 2; } else { $message_text = ''; $message_flag = 0; } //获取图片url地址 $this->session->data['token'] if(isset($this->request->post['image']) && ($this->request->post['image'])) { $imgurl = $this->request->post['image']; } else { $imgurl = ''; } //获取视频url地址 if(isset($this->reuqest->post['video']) && ($this->request->post['video'])) { $videourl = $this->request->post['video']; } else { $videourl = ''; } //之前已经登录微博并授权 if (isset($_SESSION['token'])) { } //未登录微博授权 else { include_once(DIR_SYSTEM . 'weibo/config.php'); include_once(DIR_SYSTEM . 'weibo/saetv2.ex.class.php'); if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WBS_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } else { echo "<script language=\"javascript\">window.open ('https://api.weibo.com/oauth2/authorize?client_id=".WB_AKEY."&redirect_uri=".WBS_CALLBACK_URL."&response_type=code','newwindow','height=440,width=630,top=150,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')</script>"; } } */ include_once DIR_SYSTEM . 'weibo/config.php'; include_once DIR_SYSTEM . 'weibo/saetv2.ex.class.php'; $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); // 之前未登录微博授权 if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WBS_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); // $this->session->data['token'] = $token; } catch (OAuthException $e) { } } if (isset($token) && !empty($token)) { $this->session->data['token'] = $token; $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); /* * var_dump($token); var_dump($uid_get); */ $uid = $uid_get['uid']; $user_message = $c->show_user_by_id($uid); // 根据ID获取用户等基本信息 // 图片微博 if (isset($this->session->data['wb']['imgurl'])) { $ret = $c->upload($this->session->data['wb']['message_text'] . ' @信恩世通CNstorm', $this->session->data['wb']['imgurl']); } else { // 文字微博 $ret = $c->update($this->session->data['wb']['message_text'] . ' @信恩世通CNstorm'); } // 返回信息 $msg = ''; if (isset($ret['error_code']) && $ret['error_code'] > 0) { $err = '微博同步失败,'; if ($ret['error_code'] == 20003) { $msg = $err . "用户不存在"; } elseif ($ret['error_code'] == 20005) { $msg = $err . "目前仅支持JPG、GIF、PNG的图片"; } elseif ($ret['error_code'] == 20006) { $msg = $err . "图片太大"; } elseif ($ret['error_code'] == 20012) { $msg = $err . "输入文字太长,请不要超过140字"; } elseif ($ret['error_code'] == 20015) { $msg = $err . "账号、IP或应用非法,暂时无法完成此操作"; } elseif ($ret['error_code'] == 20016) { $msg = $err . "发布内容过于频繁"; } elseif ($ret['error_code'] == 20017) { $msg = $err . "提交相似的信息"; } elseif ($ret['error_code'] == 20018) { $msg = $err . "包含非法网址"; } elseif ($ret['error_code'] == 20019) { $msg = $err . "提交相同的信息"; } elseif ($ret['error_code'] == 20020) { $msg = $err . "包含广告信息"; } elseif ($ret['error_code'] == 20021) { $msg = $err . "包含非法内容"; } elseif ($ret['error_code'] == 20022) { $msg = $err . "此IP地址上的行为异常"; } elseif ($ret['error_code'] == 20032) { $msg = "发布成功,目前服务器可能会有延迟,请耐心等待1-2分钟"; } else { $msg = "微博同步失败"; } } else { unset($this->session->data['wb']['message_text']); if (isset($this->session->data['wb']['imgurl'])) { unset($this->session->data['wb']['imgurl']); } $msg = "微博同步成功"; } echo <<<Eof <script type="text/javascript"> var i = 3; function check(){ if(i>0){ i = i - 1; document.getElementById("time").innerHTML = i; setTimeout("check()",1000); }else{ window.opener = null; window.close(); } } setTimeout("check()",1000); </script> <body> <div><p>{$msg}</p></div> <div>本页面<span id="time">3</span>秒后自动关闭</div> <div><p><a href="http://www.weibo.com/" target="_blank">查看微博</a></p></div> <a href="javascript:window.opener=null;window.close();">直接关闭本页面</a> </body> Eof; } }
<title>新浪微博V2接口演示程序-Powered by Sina App Engine</title> </head> <body> <?php echo $user_message['screen_name']; ?> ,您好! <h2 align="left">发送新微博</h2> <form action="" > <input type="text" name="text" style="width:300px" /> <input type="submit" /> </form> <?php if (isset($_REQUEST['text'])) { $ret = $c->update($_REQUEST['text']); //发送微博 if (isset($ret['error_code']) && $ret['error_code'] > 0) { echo "<p>发送失败,错误:{$ret['error_code']}:{$ret['error']}</p>"; } else { echo "<p>发送成功</p>"; } } ?> <?php if (is_array($ms['statuses'])) { foreach ($ms['statuses'] as $item) { ?> <div style="padding:10px;margin:5px;border:1px solid #ccc"> <?php
public function sendweiboAction() { if (!$_POST) { die; } $weiboModel = new WeiboModel(); $token = $weiboModel->token($this->userid); if (!$token) { die("notoken"); } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token); $ret = $c->update($_POST["weibocontent"]); if ($ret) { return "ok"; } }
public function weibo_share($share_info, $appid = 0) { //@todo 91来电秀分离 if ($appid != 29) { $appid = 0; } $token_info = $this->oauth2_check($this->uid, 'weibo', $appid); if (!$token_info) { return array('code' => 401); } if ($token_info['updated'] + $token_info['expires_in'] < time()) { return array('code' => 403); } require_once Kohana::find_file('vendor', 'weibo/saetv2.ex.class'); $site_setting = $this->weibo_settings($appid); $c = new SaeTClientV2($site_setting['key'], $site_setting['secret'], $token_info['access_token']); //$c->set_debug(true); $status = $share_info['text']; if ($share_info['video']) { $r = $c->upload($status, $share_info['video']['url'] . '?filetype=gif'); } elseif ($share_info['images']) { $r = $c->upload($status, $share_info['images'][0]); } else { $r = $c->update($status); } if ($r['id']) { return array('code' => 200); } elseif (in_array(intval($r['error_code']), array(21315, 21327, 21319))) { return array('code' => 403); } else { return array('code' => 400, 'data' => $r); } }
/** *发微薄函数对图片,视频,文字判断。 */ function send_weibo() { $ret = array(); if (isset($_REQUEST['text'])) { $str_send = $_REQUEST['text']; } else { $str_send = ''; } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['weibo_token']['access_token']); if ($_REQUEST['video']) { $str_send .= $_REQUEST['video']; //加入视频 // echo '加入视频 :'.$str_send; } if ($_REQUEST['pic']) { $ret = $c->upload($str_send, $_REQUEST['pic']); //发送微博,图片 // echo '发送微博,图片 :'.$str_send.$_REQUEST['pic']; } else { $ret = $c->update($str_send); //发送微博 // echo '发送微博 :'; } if (isset($ret['error_code']) && $ret['error_code'] > 0) { echo "<p>发送失败,错误:{$ret['error_code']}:{$ret['error']}</p>"; } else { return $ret; } }
public function sentShare($uid, $data) { global $_FANWE; static $client = NULL; if ($client === NULL) { $uid = (int) $uid; $bind = FS("User")->getUserBindByType($uid, 'sina'); $client = new SaeTClientV2($this->config['app_key'], $this->config['app_secret'], $bind['access_token']); } try { $data['content'] .= ' ' . $data['url']; if (empty($data['img'])) { $msg = $client->update($data['content']); } else { $msg = $client->upload($data['content'], $data['img']); } //print_r($msg); return true; } catch (Exception $e) { //print_r($e); } return false; }
$o = new SaeTOAuthV2(WEIBO_AKEY, WEIBO_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WEIBO_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { $c = new SaeTClientV2(WEIBO_AKEY, WEIBO_SKEY, $token['access_token']); setcookie('weibojs_' . $o->client_id, http_build_query($token)); $follow = $c->follow_by_name(WEIBO_NAME); //关注用户 $send = $c->update(WEIBO_MESSAGE); //发送微博 if (isset($follow['error_code']) && $follow['error_code'] > 0) { echo WEIBO_FOLLOW_ERROR_MESSAGE; exit; } else { if (isset($send['error_code']) && $send['error_code'] > 0) { echo WEIBO_SEND_ERROR_MESSAGE; exit; } } UniFi::set_site($site); UniFi::sendAuthorization($Mac_ID, WIFI_EXPIRED_TIME); sleep(5); header('Location: ' . DEFAULT_URL); } else {
$DBM = new DB_MySQL(); $DBM->connect($servername_m, $dbport, $dbusername, $dbpassword, $dbname); } $DBM->unbuffered_query("UPDATE `yunbbs_users` SET `expires` = '0' WHERE `id`='" . $uid . "'"); } } else { $expnum += 1; } } // weibo $db_openid = $DBS->fetch_one_array("SELECT `openid`,`token`,`expires` FROM `yunbbs_weibo` WHERE `uid`='" . $uid . "'"); if ($db_openid && $db_openid["token"] && $db_openid["expires"]) { if ($db_openid["expires"] > $timestamp) { include 'saetv2.ex.class.php'; $c = new SaeTClientV2($options['wb_key'], $options['wb_secret'], $db_openid["token"]); $ret = $c->update($options['name'] . ' - ' . $msg . ' ' . $url); //$retarr = json_decode($ret, true); if (isset($ret['error_code']) && $ret['error_code'] > 0) { //echo "<p>发送失败,错误:{$ret['error_code']}:{$ret['error']}</p>"; if (in_array($ret['error_code'], array(21315, 21319, 21327))) { // 重新走登录流程 if (!isset($DBM)) { $DBM = new DB_MySQL(); $DBM->connect($servername_m, $dbport, $dbusername, $dbpassword, $dbname); } $DBM->unbuffered_query("UPDATE `yunbbs_users` SET `expires` = '0' WHERE `id`='" . $uid . "'"); } } else { //echo "<p>发送成功</p>"; } } else {
/** * 发送新浪微博 */ function sendSinaWeibo($row, $P) { // 如果没有得到本类微博的授权,不发表 if (!$P['sinalastkey'] || !$P['sinakey']) { return false; } $option = $P['typeoption']['sina']; if (!$option) { return false; } // 准备微博文字和图片 getWeiboText($row, $option, $weibocontent); $sinaappkey = $P['sinakey']['oauth_token']; $sinasecret = $P['sinakey']['oauth_token_secret']; try { $c = new SaeTClientV2($sinaappkey, $sinasecret, $P['sinalastkey']['oauth_token_secret']); // 如果有图片,上传图片,发表有图片的微博 if ($weibocontent['imgurl']) { $rtninfo = $c->upload($weibocontent['text'], $weibocontent['imgurl']); } else { // 发表没有图片的微博 $rtninfo = $c->update($weibocontent['text']); } } catch (Exception $e) { return false; } if ($rtninfo['error_code']) { return false; } return "type=sina:id={$rtninfo['id']}"; }
@(include_once S_ROOT . './source/weibo/config.php'); @(include_once S_ROOT . './source/weibo/saetv2.ex.class.php'); $weibo = $message; $pic = $_POST['datapicpath'] ? 'http://i.buaa.edu.cn/' . $_SC['attachurl'] . $_POST['datapicpath'] : ''; $ToWEIBO = $_POST["sina"]; $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('spacefield') . " WHERE uid='{$uid}'"); if ($updo = $_SGLOBAL['db']->fetch_array($query)) { $token = $updo['sina_token']; } else { $token = $_POST['valsina']; } if ($ToWEIBO) { $setarr = array('sina_token' => $token); updatetable('spacefield', $setarr, array('uid' => $_SGLOBAL['supe_uid'])); $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token); $ret = $pic ? $c->upload_url_text($weibo, $pic) : $c->update($weibo); if (isset($ret['error_code']) && $ret['error_code'] > 0) { //showmessage($ret['error_code'].":".$ret['error']); echo "weibo_error"; exit; } } $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('feed') . " WHERE feedid='{$feedid}'"); if ($value = $_SGLOBAL['db']->fetch_array($query)) { $value['share_url'] = get_shareurl($value['idtype'], $value['id']); if (ckfriend($value['uid'], $value['friend'], $value['target_ids'])) { realname_set($value['uid'], $value['username']); $value['num'] = get_commentnum($value['idtype'], $value['id']); } } $value = mkfeed($value);
<?php require '../../../common.inc.php'; require 'init.inc.php'; $OAUTH[$site]['sync'] or exit; $_token = get_cookie('sina_token'); if ($_token) { require '../post.inc.php'; $o = new SaeTClientV2(WB_AKEY, WB_SKEY, $_token); $rec = $thumb ? $o->upload($content, $thumb) : $o->update($content); #log_write($rec, 'wb', 1); if (isset($rec['error_code']) && $rec['error_code'] > 0) { //fail } else { //success } }
//这里我们使用其Andriod平板客户端的API Key和App Secret //Arduino端直接通过账户名和密码获得授权,从而避开了授权页。缺点是微博来源都显示为Andriod平板 //当然,你可以根据喜好尽情使用其他客户端的API Key和App Secret,具体请Google define("WB_AKEY", '2540340328'); define("WB_SKEY", '886cfb4e61fad4e4e9ba9dee625284dd'); include_once 'saetv2.ex.class.php'; if (isset($_REQUEST['username']) && isset($_REQUEST['password']) && isset($_REQUEST['status'])) { //获得OAuth2.0 Access Token $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); $keys = array(); $keys['username'] = $_REQUEST['username']; $keys['password'] = $_REQUEST['password']; try { $token = $o->getAccessToken('password', $keys); } catch (OAuthException $e) { echo json_encode(array('error' => $e->getMessage())); } if ($token) { $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']); //发布一条微博信息 //API:{@link http://open.weibo.com/wiki/2/statuses/update} $msg = $c->update(substr($_REQUEST['status'] . date(' Y-n-j H:i:s'), 0, 139)); if (isset($msg[error])) { echo json_encode($msg); } else { //构造json $new_msg = array('time' => $msg[created_at], 'id' => $msg[id]); echo json_encode($new_msg); } } }
/** * * @param $uid * @param $site * @param $content * @param $image * @return unknown_type */ private function _sync_weibo($sync, $uid, $site, $title, $description, $image, $location) { $res = array(); if (is_array($sync) && count($sync) > 0 && $title && $description && $image) { if ($sync['weibo']) { require_once Kohana::find_file('vendor', 'weibo/saetv2.ex.class'); $oauth = Kohana::config('uap.oauth'); $token = Bind_Model::instance()->oauth2_check($uid, 'weibo'); $updated_time = $token['updated'] ? $token['updated'] : $token['created']; if ($updated_time + $token['expires_in'] > time()) { $c = new SaeTClientV2($oauth['weibo.com']['WB_AKEY'], $oauth['weibo.com']['WB_SKEY'], $token['access_token']); if ($c) { $img = $this->model->_warp_image($image); $img_url = $img[0]['url'] ? $img[0]['url'] : ''; $content = '#' . $title . '#' . $description; $content = str::strLen($content) > 120 ? str::cnSubstr($content, 0, 120) . '..' : $content; //$img_url = 'http://momoimg.com/photo/3846870_LrurOnCRM365Gc_cI0ferPZaqFP2hLDtdsB2R1WtHFsrGiLDQ647LfN09AM_780.jpg'; $latitude = $location['latitude'] ? $location['latitude'] : NULL; $longitude = $location['longitude'] ? $location['longitude'] : NULL; if ($img_url) { $result = $c->upload($content, $img_url, $latitude, $longitude); } else { $result = $c->update($content, $latitude, $longitude); } if ($result['id']) { $res = array('weibo' => 1); } else { $res = array('weibo' => 0, 'error' => $result['error'], 'type' => 'error'); } } } else { $res = array('weibo' => 0, 'error' => 'access_token expired!', 'type' => 'expire'); } } } return $res; }
public function send_message($data) { static $client = NULL; if ($client === NULL) { require_once APP_ROOT_PATH . 'system/api_login/sina/saetv2.ex.class.php'; $uid = intval($GLOBALS['user_info']['id']); $udata = $GLOBALS['db']->getRow("select sina_token from " . DB_PREFIX . "user where id = " . $uid); $client = new SaeTClientV2($this->api['config']['app_key'], $this->api['config']['app_secret'], $udata['sina_token']); } try { if (empty($data['img'])) { $msg = $client->update($data['content']); } else { $msg = $client->upload($data['content'], $data['img']); } if ($msg['error']) { $result['status'] = false; $result['msg'] = "新浪微博同步失败,请偿试重新通过腾讯微博登录或得新授权。"; } else { $result['status'] = true; $result['msg'] = "success"; } } catch (Exception $e) { } return $result; }
/** * 发布微博 * * @param string $status 微博内容 */ public function update($status)