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

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

WBOY
WBOYOriginal
2016-06-06 19:45:591003browse

?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 );

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn