示例#1
0
/**
 * Call the Yahoo Contact API
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $guid obtained from getacctok
 * @param string $access_token obtained from getacctok
 * @param string $access_token_secret obtained from getacctok
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $passOAuthInHeader pass the OAuth credentials in HTTP header
 * @return response string with token or empty array on error
 */
function call_yql($consumer_key, $consumer_secret, $querynum, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    if ($querynum == 1) {
        $url = 'http://query.yahooapis.com/v1/yql';
        // Show my profile
        $params['q'] = 'select * from social.profile where guid=me';
    } elseif ($querynum == 2) {
        $url = 'http://query.yahooapis.com/v1/yql';
        // Find my friends
        $params['q'] = 'select * from social.connections where owner_guid=me';
    } else {
        // Since this information is public, use the non oauth endpoint 'public'
        $url = 'http://query.yahooapis.com/v1/public/yql';
        // Find all sushi restaurants in SF order by number of ratings desc
        $params['q'] = 'select Title,Address,Rating from local.search where query="sushi" and location="san francisco, ca"|sort(field="Rating.TotalRatings",descending="true")';
    }
    $params['format'] = 'json';
    $params['callback'] = 'cbfunc';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost) {
        $request_url = $url;
        logit("call_yql:INFO:request_url:{$request_url}");
        logit("call_yql:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 80, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("call_yql:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("call_yql:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
示例#2
0
/**
* Call twitter to get a list of the user's follow requests
* @param string $access_token obtained from get_request_token
* @param string $access_token_secret obtained from get_request_token
* @return response string or empty array on error
*/
function getFollowers($access_token, $access_token_secret)
{
    $retarr = array();
    // return value
    $response = array();
    //$url = 'http://api.twitter.com/1/statuses/update.json';
    $url = 'http://api.twitter.com/1.1/friendships/incoming.json';
    //$params['status'] = $status_message;
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = OAUTH_CONSUMER_KEY;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig('GET', $url, $params, OAUTH_CONSUMER_SECRET, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    $query_parameter_string = oauth_http_build_query($params, true);
    $header = build_oauth_header($params, "Twitter API");
    $headers[] = $header;
    // POST or GET the request
    $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
    //logit("tweet:INFO:request_url:$request_url");
    $response = do_get($request_url, 80, $headers);
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            //logit("tweet:INFO:response:");
            //print(json_pretty_print($body));
        }
        $retarr = $response;
    }
    return $retarr;
}
示例#3
0
function get_user_info($appid, $appkey, $access_token, $access_token_secret, $openid)
{
    //获取用户信息的接口地址, 不要更改!!
    $url = "http://openapi.qzone.qq.com/user/get_user_info";
    $info = do_get($url, $appid, $appkey, $access_token, $access_token_secret, $openid);
    $arr = array();
    $arr = json_decode($info, true);
    return $arr;
}
示例#4
0
/**
 * Call the Yahoo Contact API
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $guid obtained from getacctok
 * @param string $access_token obtained from getacctok
 * @param string $access_token_secret obtained from getacctok
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $passOAuthInHeader pass the OAuth credentials in HTTP header
 * @return response string with token or empty array on error
 */
function callcontact($consumer_key, $consumer_secret, $guid, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true, $_count)
{
    $retarr = array();
    // return value
    $response = array();
    $url = 'http://social.yahooapis.com/v1/user/' . $guid . '/contacts?count=' . $_count;
    $params['format'] = 'xml';
    $params['view'] = 'compact';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    //$params['oauth_signature'] =
    // oauth_compute_hmac_sig($usePost? 'POST' : 'GET', $url, $params,
    // $consumer_secret, $access_token_secret);
    echo ',';
    echo $params['oauth_nonce'];
    echo ',';
    echo $params['oauth_timestamp'];
    echo ',';
    echo oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    exit(0);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost && 0) {
        $request_url = $url;
        logit("callcontact:INFO:request_url:{$request_url}");
        logit("callcontact:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 80, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("callcontact:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("callcontact:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
示例#5
0
/**
 * Refresh an access token using an expired request token
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $old_access_token obtained previously
 * @param string $old_token_secret obtained previously
 * @param string $oauth_session_handle obtained previously
 * @param bool $usePost use HTTP POST instead of GET (default false)
 * @param bool $useHmacSha1Sig use HMAC-SHA1 signature (default false)
 * @return response string with token or empty array on error
 */
function refresh_access_token($consumer_key, $consumer_secret, $old_access_token, $old_token_secret, $oauth_session_handle, $usePost = false, $useHmacSha1Sig = true, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    $url = 'https://api.login.yahoo.com/oauth/v2/get_token';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $old_access_token;
    $params['oauth_session_handle'] = $oauth_session_handle;
    // compute signature and add it to the params list
    if ($useHmacSha1Sig) {
        $params['oauth_signature_method'] = 'HMAC-SHA1';
        $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $old_token_secret);
    } else {
        $params['oauth_signature_method'] = 'PLAINTEXT';
        $params['oauth_signature'] = oauth_compute_plaintext_sig($consumer_secret, $old_token_secret);
    }
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost) {
        $request_url = $url;
        logit("refacctok:INFO:request_url:{$request_url}");
        logit("refacctok:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 443, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("refacctok:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 443, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        $body_parsed = oauth_parse_str($body);
        if (!empty($body_parsed)) {
            logit("getacctok:INFO:response_body_parsed:");
            print_r($body_parsed);
        }
        $retarr = $response;
        $retarr[] = $body_parsed;
    }
    return $retarr;
}
示例#6
0
 function get_request_token($callback = 'oob', $usePost = false, $useHmacSha1Sig = true, $passOAuthInHeader = false)
 {
     $retarr = array();
     // return value
     $response = array();
     $params['oauth_version'] = '1.0';
     $params['oauth_nonce'] = mt_rand();
     $params['oauth_timestamp'] = time();
     $params['oauth_consumer_key'] = $this->consumer_key;
     $params['oauth_callback'] = $callback;
     $headers = array();
     // compute signature and add it to the params list
     if ($useHmacSha1Sig) {
         $params['oauth_signature_method'] = 'HMAC-SHA1';
         $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $this->reqUrl, $params, $this->consumer_secret, null);
     } else {
         $params['oauth_signature_method'] = 'PLAINTEXT';
         $params['oauth_signature'] = oauth_compute_plaintext_sig($this->consumer_secret, null);
     }
     // Pass OAuth credentials in a separate header or in the query string
     if ($passOAuthInHeader) {
         $query_parameter_string = oauth_http_build_query($params, true);
         $header = build_oauth_header($params, "Twitter API");
         $headers[] = $header;
     } else {
         $query_parameter_string = oauth_http_build_query($params);
     }
     // POST or GET the request
     if ($usePost) {
         $request_url = $this->reqUrl;
         logit("getreqtok:INFO:request_url:{$request_url}");
         logit("getreqtok:INFO:post_body:{$query_parameter_string}");
         $headers[] = 'Content-Type: application/x-www-form-urlencoded';
         $response = do_post($request_url, $query_parameter_string, 80, $headers);
     } else {
         $request_url = $this->reqUrl . ($query_parameter_string ? '?' . $query_parameter_string : '');
         logit("getreqtok:INFO:request_url:{$request_url}");
         $response = do_get($request_url, 80, $headers);
     }
     // extract successful response
     if (!empty($response)) {
         list($info, $header, $body) = $response;
         $body_parsed = oauth_parse_str($body);
         if (!empty($body_parsed)) {
             logit("getreqtok:INFO:response_body_parsed:");
         }
         $retarr = $response;
         $retarr[] = $body_parsed;
     }
     return $retarr;
 }
 function userInfo()
 {
     $url = "http://openapi.qzone.qq.com/user/get_user_info";
     $me = do_get($url, QZONE_KEY, QZONE_SECRET, $_SESSION['qzone']['access_token']['oauth_token'], $_SESSION['qzone']['access_token']['oauth_token_secret'], $_SESSION['qzone']["openid"]);
     $me = json_decode($me);
     $user['id'] = $_SESSION['qzone']["openid"];
     $user['uname'] = $me->nickname;
     $user['province'] = 0;
     $user['city'] = 0;
     $user['location'] = '';
     $user['userface'] = $me->figureurl_2;
     $user['sex'] = 0;
     //print_r($user);
     return $user;
 }
示例#8
0
 function userInfo()
 {
     $access_token = Openbiz::$app->getSessionContext()->getVar('qzone_access_token');
     $url = "http://openapi.qzone.qq.com/user/get_user_info";
     $me = do_get($url, $this->akey, $this->skey, $access_token['oauth_token'], $access_token['oauth_token_secret'], $access_token["openid"]);
     $me = json_decode($me);
     $user['id'] = $access_token["openid"];
     $user['uname'] = $me->nickname;
     $user['type'] = $this->type;
     $user['province'] = 0;
     $user['city'] = 0;
     $user['location'] = '';
     $user['userface'] = $me->figureurl_2;
     $user['sex'] = $me->gender == '男' ? 1 : 0;
     return $user;
 }
示例#9
0
/**
* Call twitter to post a tweet
* @param string $consumer_key obtained when you registered your app
* @param string $consumer_secret obtained when you registered your app
* @param string $status_message
* @param string $access_token obtained from get_request_token
* @param string $access_token_secret obtained from get_request_token
* @param bool $usePost use HTTP POST instead of GET
* @param bool $passOAuthInHeader pass OAuth credentials in HTTP header
* @return response string or empty array on error
*/
function post_tweet($consumer_key, $consumer_secret, $status_message, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    //$url = 'http://api.twitter.com/1/statuses/update.json';
    $url = 'http://api.twitter.com/1.1/friendships/incoming.json';
    //$params['status'] = $status_message;
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "Twitter API");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost) {
        $request_url = $url;
        logit("tweet:INFO:request_url:{$request_url}");
        logit("tweet:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 80, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("tweet:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("tweet:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
示例#10
0
/**
 * Call the Yahoo Contact API
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $guid obtained from getacctok
 * @param string $access_token obtained from getacctok
 * @param string $access_token_secret obtained from getacctok
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $passOAuthInHeader pass the OAuth credentials in HTTP header
 * @return response string with token or empty array on error
 */
function postcontact($consumer_key, $consumer_secret, $guid, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    $post_body = '{"contact":{"fields":[{"type":"name","value":{"givenName":"John","middleName":"","familyName":"Doe","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""}},{"type":"email","value":"*****@*****.**"}]}}';
    $url = 'http://social.yahooapis.com/v1/user/' . $guid . '/contacts';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
        $request_url = $url;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
        $request_url = $url . '?' . $query_parameter_string;
    }
    // POST or GET the request
    if ($usePost) {
        logit("postcontact:INFO:request_url:{$request_url}");
        logit("postcontact:INFO:post_body:{$post_body}");
        $headers[] = 'Content-Type: application/json';
        $response = do_post($request_url, $post_body, 80, $headers);
    } else {
        logit("postcontact:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("postcontact:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
示例#11
0
function list_album($appid, $appkey, $access_token, $access_token_secret, $openid)
{
    //获取相册列表的接口地址, 不要更改!!
    $url = "http://openapi.qzone.qq.com/photo/list_album";
    echo do_get($url, $appid, $appkey, $access_token, $access_token_secret, $openid);
}
示例#12
0
 public function get_user_info()
 {
     //获取用户信息的接口地址, 不要更改!!
     $url = "http://openapi.qzone.qq.com/user/get_user_info";
     $info = do_get($url, $this->appid, $this->appkey, $_SESSION["token"], $_SESSION["secret"], $_SESSION["openid"]);
     $arr = array();
     $arr = json_decode($info, true);
     return $arr;
 }
示例#13
0
include_once dirname(__FILE__) . '/config.php';
include_once dirname(__FILE__) . '/OAuth.php';
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
$request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', BASE_URL . '/api.php/social/rest/people/@me/@self');
$request->set_parameter('xoauth_requestor_id', 1);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
echo "-----Test1 /people/@me/@self\n";
var_dump($res);
$request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', BASE_URL . '/api.php/social/rest/people/@me/@friends');
$request->set_parameter('xoauth_requestor_id', 1);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
echo "-----Test2 /people/@me/@friends\n";
var_dump($res);
$request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', BASE_URL . '/api.php/social/rest/people/@me/@friends', array('filterBy' => 'hasApp'));
$request->set_parameter('xoauth_requestor_id', 1);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
echo "-----Test3 /people/@me/@friends?filterBy=hasApp\n";
var_dump($res);
function do_get($uri, $data = '')
{
    $h = curl_init();
    curl_setopt($h, CURLOPT_URL, $uri . '?' . $data);
    curl_setopt($h, CURLOPT_POST, false);
    curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($h);
    curl_close($h);
    return $result;
}
示例#14
0
function yim_auth_get_request_token($username, $password)
{
    $url = 'https://login.yahoo.com/WSLogin/V1/get_auth_token';
    $params['oauth_consumer_key'] = OAUTH_CONSUMER_KEY;
    $params['login'] = $username;
    $params['passwd'] = $password;
    $query_param_string = oauth_http_build_query($params);
    $url = $url . '?' . $query_param_string;
    $response = do_get($url, 443);
    yim_fail_if_not_ok($response, 'Invalid credentials');
    $request_token_response = $response[2];
    $request_token_arr = split("=", $request_token_response);
    return $request_token_arr[1];
}
    echo '</html>';
    exit;
}
//解析返回参数
$result = array();
parse_str($access_str, $result);
//将access token,openid保存起来!!!
//在demo演示中,直接保存在全局变量中.
//为避免网站存在多个子域名或同一个主域名不同服务器造成的session无法共享问题
//请开发者按照本SDK中comm/session.php中的注释对session.php进行必要的修改,以解决上述2个问题,
$_SESSION["qq_token"] = $result["oauth_token"];
$_SESSION["qq_token_secret"] = $result["oauth_token_secret"];
$_SESSION["qq_openid"] = $result["openid"];
date_default_timezone_set("PRC");
$url = "http://openapi.qzone.qq.com/user/get_user_info";
$info = do_get($url, $_SESSION["appid"], $_SESSION["appkey"], $_SESSION["qq_token"], $_SESSION["qq_token_secret"], $_SESSION["qq_openid"]);
$arr = array();
$arr = json_decode($info, true);
if ($arr && $arr["nickname"]) {
    $_SESSION["qq_nickname"] = $arr["nickname"];
    $go_url = "/index.php?app=third_login&act=qq_callback&qq_token=" . $_SESSION["qq_token"] . "&qq_token_secret=" . $_SESSION["qq_token_secret"] . "&qq_openid=" . $_SESSION["qq_openid"] . "&qq_nickname=" . urlencode($_SESSION["qq_nickname"]);
    header("location:{$go_url}");
    exit;
} else {
    exit("can't get user info.");
}
/*echo '<html lang="zh-cn">';
echo '<head>';
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
echo '</head>';
echo '<body>';
示例#16
0
function process($user, $action)
{
    say("< " . $action);
    $request = json_decode($action, true);
    if (empty($request)) {
        say("ERROR: invalid request body");
        return;
    }
    if (!array_key_exists("method", $request) || !array_key_exists("resource", $request) || !array_key_exists("msg_id", $request)) {
        say("ERROR: missing mandatory property");
        return;
    }
    $method = $request["method"];
    $response = NULL;
    if ($method == "POST" && $request["resource"] == "/slideshare") {
        $response = get_slideshare($request);
    } else {
        if ($method == "POST") {
            $response = do_post($user, $request);
        } else {
            if ($method == "PUT") {
                $response = do_put($user, $request);
            } else {
                if ($method == "GET") {
                    $response = do_get($user, $request);
                } else {
                    if ($method == "DELETE") {
                        $response = do_delete($user, $request);
                    } else {
                        if ($method == "SUBSCRIBE") {
                            $response = do_subscribe($user, $request);
                        } else {
                            if ($method == "UNSUBSCRIBE") {
                                $response = do_unsubscribe($user, $request);
                            } else {
                                if ($method == "NOTIFY") {
                                    $response = do_notify($user, $request);
                                } else {
                                    // this is an unknown request
                                    $response = array("code" => "failed", "reason" => "unknown command " . $method . " " . $resource);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $response['msg_id'] = $request['msg_id'];
    //header("Content-type: application/json");
    send($user, json_encode($response));
}
示例#17
0
function sendOAuthGET($endpoint, $oauth_consumer_key, $oauth_consumer_secret, $accept_type, $more_headers = false, $signature = false)
{
    $test_token = '';
    $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
    if ($signature == "HMAC-SHA256") {
        $hmac_method = new OAuthSignatureMethod_HMAC_SHA256();
    }
    $test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, NULL);
    $parms = array();
    $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, "GET", $endpoint, $parms);
    $acc_req->sign_request($hmac_method, $test_consumer, $test_token);
    // Pass this back up "out of band" for debugging
    global $LastOAuthBodyBaseString;
    $LastOAuthBodyBaseString = $acc_req->get_signature_base_string();
    $header = $acc_req->to_header();
    $header = $header . "\r\nAccept: " . $accept_type . "\r\n";
    if ($more_headers === false) {
        $more_headers = array();
    }
    foreach ($more_headers as $more) {
        $header = $header . $more . "\r\n";
    }
    global $LastGETHeader;
    $LastGETHeader = $header;
    return do_get($endpoint, $header);
}
示例#18
0
文件: tp.php 项目: kingmook/sakai
    if ($lti_message_type == "ToolProxyRegistrationRequest") {
        $reg_key = $_POST['reg_key'];
        $reg_password = $_POST['reg_password'];
    } else {
        echo "</pre>";
        die("lti_message_type not supported " . $lti_message_type);
    }
}
$cur_url = curPageURL();
$cur_base = str_replace("tp.php", "", $cur_url);
require_once 'tp_messages.php';
$launch_presentation_return_url = $_POST['launch_presentation_return_url'];
$tc_profile_url = $_POST['tc_profile_url'];
if (strlen($tc_profile_url) > 1) {
    echo "Retrieving profile from " . $tc_profile_url . "\n";
    $tc_profile_json = do_get($tc_profile_url);
    echo "Retrieved " . strlen($tc_profile_json) . " characters.\n";
    echo "</pre>\n";
    togglePre("Retrieved Consumer Profile", $tc_profile_json);
    $tc_profile = json_decode($tc_profile_json);
    if ($tc_profile == null) {
        die("Unable to parse tc_profile error=" . json_last_error());
    }
} else {
    die("We must have a tc_profile_url to continue...");
}
// Find the registration URL
echo "<pre>\n";
$tc_guid = $tc_profile->guid;
echo "Tool Consumer guid: " . $tc_guid . "\n";
$tc_services = $tc_profile->service_offered;