首页 新闻 会员 周边 捐助

下面是开心给的OpenID的开发文档是用PHP写的,本人对PHP不了解,希望能有高人帮忙翻译成Javascript,谢谢了

0
悬赏园豆:100 [待解决问题]

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

}

展翅高飞的主页 展翅高飞 | 初学一级 | 园豆:84
提问于:2011-05-11 11:58
< >
分享
所有回答(1)
0

翻译不了JS。。。。。。JS貌似没这功能吧。。

翩若游龙 | 园豆:7 (初学一级) | 2011-05-11 17:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册