function tweet_post() { $args = func_get_args(); $cate = $args[2]; $content = format_str($_POST['text'], false); if (!$cate or !$content) { die("Invalid argument!"); } include_once 'sinaoauth.inc.php'; $c = new WeiboClient(SINA_AKEY, SINA_SKEY, $GLOBALS['user']['sinakey']['oauth_token'], $GLOBALS['user']['sinakey']['oauth_token_secret']); if ($_FILES['upload']['tmp_name']) { $msg = $c->upload($content, $_FILES['upload']['tmp_name']); } else { $msg = $c->update($content); } if ($msg === false || $msg === null) { echo "Error occured"; return false; } if (isset($msg['error_code']) && isset($msg['error'])) { echo 'Error_code: ' . $msg['error_code'] . '; Error: ' . $msg['error']; return false; } include_once "uuid.inc.php"; $v4uuid = str_replace("-", "", UUID::v4()); connect_db(); $add = "INSERT INTO pending_tweets (\r\n site_id, tweet_id, user_site_id, content, post_datetime,\r\n type, tweet_site_id,\r\n post_screenname, profile_image_url, source)\r\n VALUES (1, '{$v4uuid}', '" . $msg['user']['id'] . "', '{$content}', '" . date("Y-m-d H:i:s", strtotime($msg["created_at"])) . "',\r\n {$cate}, '" . $msg['id'] . "', '" . $msg["user"]["name"] . "', '" . $msg["user"]["profile_image_url"] . "', '" . $msg["source"] . "')"; if ($msg['thumbnail_pic']) { $add = "INSERT INTO pending_tweets (\r\n site_id, tweet_id, user_site_id, content, post_datetime,\r\n type, tweet_site_id,\r\n post_screenname, profile_image_url, source, thumbnail)\r\n VALUES (1, '{$v4uuid}', '" . $msg['user']['id'] . "', '{$content}', '" . date("Y-m-d H:i:s", strtotime($msg["created_at"])) . "',\r\n {$cate}, '" . $msg['id'] . "', '" . $msg["user"]["name"] . "', '" . $msg["user"]["profile_image_url"] . "', '" . $msg["source"] . "', '" . $msg['thumbnail_pic'] . "')"; } $added = mysql_query($add) or die("Could not add entry!"); echo "0"; }
private function status_bind($id, $text, $pic_id) { include_once ROOT_DIR . 'lib/user/user.class.php'; $this->mUser = new user(); $bind_info = $this->mUser->get_bind_info(); //获取绑定信息 include_once ROOT_PATH . 'lib/class/status.class.php'; $status = new status(); if (!$bind_info) { //do nothing! } else { //file_put_contents('d:/show.txt', '用户绑定了' , FILE_APPEND); $bind_info = $bind_info[0]; if ($bind_info['state'] == 1 && $bind_info['last_key']) { //file_put_contents('d:/show.txt', '用户开启同步了' , FILE_APPEND); include_once ROOT_PATH . 'lib/class/weibooauth.class.php'; $last_key = unserialize($bind_info['last_key']); $oauth = new WeiboClient(WB_AKEY, WB_SKEY, $last_key['oauth_token'], $last_key['oauth_token_secret']); //$oauth = new WeiboOAuth( WB_AKEY , WB_SKEY , 'e9b1d743a687550cec725e65fd204b6c' , '119934aabf1632d426533505c0f02e70' ); //判断是否发送了图片 if ($pic_id) { //file_put_contents('d:/show.txt', '用户发送了图片' , FILE_APPEND); //取出该图片的路径 //获取媒体信息 $pic_url = $status->getPicById($pic_id); $url = $pic_url[0]; //$url = 'http://127.0.0.1/3.jpg'; $content = $oauth->upload($text, $url); } else { $content = $text; $pattern = "/#([\\x{4e00}-\\x{9fa5}0-9A-Za-z_-\\s‘’“”'\"!\\?\$%&:;!?¥×\\*\\<\\>》《]+)[\\s#]/iu"; if (preg_match_all($pattern, $content, $topic)) { include_once ROOT_PATH . 'lib/class/shorturl.class.php'; $shorturl = new shorturl(); $link = ''; $tmp_url = ''; $topic_name = array(); foreach ($topic[1] as $key => $value) { $tmp_url = SNS_MBLOG . 'k.php?q=' . urlencode($value); $short_url = $shorturl->shorturl($tmp_url); $link .= $short_url; } $content = $content . $link; } // $content = $oauth->post( $oauth->updateURL() , array( 'status' => $content) ); $content = $oauth->update($content); //同步发送 } $syn_id = $content['id']; //返回点滴的ID $type = $bind_info['type']; //绑定类型 /** * 记录同步发送的点滴id */ $status->syn_relation($id, $syn_id, $type); } } }
<h2>发送新微博</h2> <form action="weibolist.php" > <input type="text" name="text" style="width:300px" /> <input type="submit" /> </form> <h2>发送图片微博</h2> <form action="weibolist.php" > <input type="text" name="text" style="width:300px" value="文字内容" /> <input type="text" name="pic" style="width:300px" value="图片url" /> <input type="submit" /> </form> <?php if (isset($_REQUEST['text']) || isset($_REQUEST['avatar'])) { if (isset($_REQUEST['pic'])) { $rr = $c->upload($_REQUEST['text'], $_REQUEST['pic']); } elseif (isset($_REQUEST['avatar'])) { $rr = $c->update_avatar($_REQUEST['avatar']); } else { $rr = $c->update($_REQUEST['text']); } echo "<p>发送完成</p>"; } ?> <?php if (is_array($ms)) { foreach ($ms as $item) { ?> <div style="padding:10px;margin:5px;border:1px solid #ccc"> <?php
public function sentShare($uid, $data) { global $_FANWE; static $client = NULL; if ($client === NULL) { $uid = (int) $uid; $bind = FS("User")->getUserBindByType($uid, 'sina'); $client = new WeiboClient($this->config['app_key'], $this->config['app_secret'], $bind['oauth_token'], $bind['oauth_token_secret']); } 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; }
<?php header('Content-Type:text/html;charset=utf-8'); session_start(); include_once 'oauth.php'; // include_once( 'config'.rand(1,3).'.php' ); include_once 'config.php'; $c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']); // print_r($_FILES["my_uploaded_file"]); if (isset($_FILES['my_uploaded_file']['tmp_name'])) { $msg1 = $c->upload(date("l dS \\of F Y h:i:s A"), $_FILES['my_uploaded_file']['tmp_name']); $msg2 = $c->user_timeline(1, 1); if (is_array($msg2)) { foreach ($msg2 as $item2) { echo $item2['original_pic']; } } } ?>
<?php session_start(); include_once 'config.php'; include_once 'weibooauth.php'; $c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']); header('Content-Type: text/html; charset=utf-8'); ?> <a href="weibolist.php">返回接口测试</a> <h2>照片接口测试</h2> <h2>广播照片上传</h2> <form action="photo_test.php" method="post" enctype="multipart/form-data"> <input type="file" name="pic" style="width:300px" value="图片url" /> <input type="submit" /> </form> <?php if ($_FILES) { $rr = $c->upload('', $_FILES['pic']['tmp_name']); print_r($rr); }
include_once 'weibooauth.php'; $oauth_token = trim($_REQUEST['oauth_token']); $oauth_token_secret = trim($_REQUEST['oauth_token_secret']); if (empty($oauth_token) or empty($oauth_token_secret)) { $oauth_token = @$_SESSION['last_key']['oauth_token']; $oauth_token_secret = @$_SESSION['last_key']['oauth_token_secret']; } $c = new WeiboClient(WB_AKEY, WB_SKEY, $oauth_token, $oauth_token_secret); error_reporting(0); $method = trim($_REQUEST['method']); $rtype = strtolower($_REQUEST['rtype']); $reqtype = trim($_REQUEST['reqtype']); $reqbody = trim($_REQUEST['reqbody']); if ($method == 'photo/upload.json') { $pic_path = $_FILES['pic']['tmp_name']; $result = $c->upload('', $pic_path); } else { switch (strtoupper($reqtype)) { case 'GET': $urls = explode('?', $method); $path = ''; $query = array(); if (!empty($urls)) { $path = isset($urls['0']) ? $urls['0'] : ''; $array = isset($urls['1']) ? explode('&', $urls['1']) : array(); if (!empty($array)) { foreach ($array as $value) { if ($value) { list($k, $v) = explode('=', $value); $query[$k] = $v; }
//用户名 $usertou = $arr['profile_image_url']; //用户头像地址 //============= $im = imagecreatefromjpeg("by.jpg"); $tou = imagecreatefromjpeg($usertou); $color = imagecolorallocate($im, 0, 0, 255); imagettftext($im, 12, 0, 270, 122, $color, "simhei.ttf", $username); imagettftext($im, 10, 0, 90, 220, $color, "simhei.ttf", "NO." . time()); imagecopy($im, $tou, 121, 131, 0, 0, 50, 50); imagejpeg($im, $userid . ".jpg"); //============= $t = "999999999999 http://www.php100.com"; $p = "http://localhost/sina12/" . $userid . ".jpg"; if (!empty($_POST['sub'])) { //$t 文字内容 //$p 我们上传的图片路径 $c->upload($t, $p); } ?> <img src="<?php echo $userid . ".jpg"; ?> "> <form action="" method="post"> <input type="submit" name="sub" value="发到微博"> </form>
/** * 发送新浪微博 */ function sendSinaWeibo($weibocontent, $P) { // 如果没有新浪的授权,直接返回 if (!$P['sinalastkey']) { return; } $c = new WeiboClient(WB_AKEY, WB_SKEY, $P['sinalastkey']['oauth_token'], $P['sinalastkey']['oauth_token_secret']); // 如果有图片,上传图片,发表有图片的微博 if ($weibocontent['imgurl']) { $rtn1 = $c->upload($weibocontent['text'], $weibocontent['imgurl']); } else { // 发表没有图片的微博 $rtn = $c->update($weibocontent['text']); } }
//if (isset($msg['name'])){ // echo($msg['name']); //} $SendToWeibo = new SaeTClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns=" http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>正在发布...</title> </head> <body> <?php if (isset($_REQUEST['text'])) { $c->upload($_REQUEST['text'], "http://ultramantest.sinaapp.com" . $_REQUEST['pic']); //echo "<p>发送完成</p>"; } echo "<script language='javascript' type='text/javascript'>"; echo "window.location.href='suc.php';"; echo "</script>"; ?> </body> </html>