/** * 此函数,供Callback处调用,如果返回false,认证失败,否则返回以下哈希表: * lastkey -> callback得到的lastkey * oauth_token -> 上述lastkey中的oauth_token * oauth_token_secret -> 上述lastkey中的oauth_token_secret * user_id -> 用户ID * user_name -> 用户昵称 * user_email -> 用户邮箱 */ function AuthCallback_netease() { // 取得网易Auth对象 $o = new ONAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['request_token']['oauth_token'], $_SESSION['request_token']['oauth_token_secret']); // 取得lastkey $last_key = $o->getAccessToken($_REQUEST['oauth_token']); if ($last_key) { $rtn = array(); $rtn['last_key'] = $last_key; $rtn['oauth_token'] = $last_key['oauth_token']; $rtn['oauth_token_secret'] = $last_key['oauth_token_secret']; $client = new TBlog(CONSUMER_KEY, CONSUMER_SECRET, $last_key['oauth_token'], $last_key['oauth_token_secret']); $user = $client->verify_credentials(); $rtn['user_id'] = $user['screen_name']; $rtn['user_name'] = $user['name']; $rtn['user_email'] = $user['email']; return $rtn; } else { return $last_key; } }
<?php define("CONSUMER_KEY", 'vPZ6aL6A6rSjXXb9'); define("CONSUMER_SECRET", 'JKO1d2btX8UjGehUX3pFOWdorWmVE1eU'); define("ACCESS_TOKEN", '74dd94519b1d410278283098b1c0baf0'); define("ACCESS_TOKEN_SECRET", 'a6e7d72f1b0f3db8f41a18c1d66f5063'); include_once 'api/tblog.class.php'; if ($_POST['submit'] == '上传') { $tblog = new TBlog(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); if (isset($_FILES['element_1'])) { $target_path = 'saestor://images/temp_' . $_FILES['element_1']['name']; move_uploaded_file($_FILES['element_1']['tmp_name'], $target_path); $url = $tblog->upload($_REQUEST['text'], $target_path); $s = new SaeStorage(); $s->delete('images', 'temp_' . $_FILES['element_1']['name']); } } ?> <!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> <link rel="stylesheet" type="text/css" href="view.css" media="all"> <script type="text/javascript" src="view.js"></script> </head> <body id="main_body" > <img id="top" src="top.png" alt=""> <div id="form_container">
/** * 发送网易微博 */ function sendNeteaseWeibo($row, $P) { // 如果没有得到本类微博的授权,不发表 if (!$P['neteaselastkey']) { return false; } $option = $P['typeoption']['netease']; if (!$option) { return false; } // 准备微博文字和图片 getWeiboText($row, $option, $weibocontent); try { $c = new TBlog(CONSUMER_KEY, CONSUMER_SECRET, $P['neteaselastkey']['oauth_token'], $P['neteaselastkey']['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=netease:id={$rtninfo['id']}"; }