首頁 > php教程 > php手册 > 下面是开心给的OpenID的开发文档是用PHP写的,本人对PHP不了解,

下面是开心给的OpenID的开发文档是用PHP写的,本人对PHP不了解,

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-06 19:45:59
原創
1011 人瀏覽過

?php $api_key = 'xxx'; $secret = 'xxx'; $url = 'http://rest.kaixin001.com/api/rest.php'; $session_key = $_GET['session_key']; if (empty($session_key)) { $session_key = $_COOKIE["kx_connect_session_key"]; } else { setcookie("kx_connect_sess

$api_key = 'xxx';

$secret = 'xxx';

$url = 'http://rest.kaixin001.com/api/rest.php';

$session_key = $_GET['session_key'];

if (empty($session_key)) {

$session_key = $_COOKIE["kx_connect_session_key"];

} else {

setcookie("kx_connect_session_key", $session_key, time()+3600*4);

}

$param = array( 'api_key' => $api_key, 'method' => 'users.getInfo', 'uids' => '100099,100100', 'format' => 'json', 'session_key' => $session_key, );

$query = buildQuery($param, $secret);

$result = postRequest($url, $query);

$result = json_decode($result);

function buildQuery($param, $secret) {

$param['call_id'] = microtime(true);

$param['v'] = '1.0';

ksort($param);

$request_str = '';

foreach ($param as $key => $value) {

$request_str .= $key . '=' . $value; // 没有分割符

}

$sig = $request_str . $secret;

$sig = md5($sig);

$param['sig'] = $sig;

$query = http_build_query($param);

return $query;

}

function postRequest($url, $post_string) {
$useragent = 'kaixin001.com API PHP5 Client 1.1 (curl) ' . phpversion(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url);

if (strlen($post_string) >= 3) {

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

}

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$result = curl_exec($ch);

curl_close($ch);

return $result;

}

function url_base64_encode($str) {

$search = array ('+', '/');

$replace = array ('*', '-');

$basestr = base64_encode($str);

return str_replace( $search, $replace, $basestr );

}

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
javascript - 為什麼上面是fasle,下面是true
來自於 1970-01-01 08:00:00
0
0
0
桌面桌布下載
來自於 1970-01-01 08:00:00
0
0
0
課件怎麼沒有前面的下載啊
來自於 1970-01-01 08:00:00
0
0
0
頁面模板從那裡可以下載
來自於 1970-01-01 08:00:00
0
0
0
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板