柳暗花明笔记

    开心网openid接口(php),取刚登陆用户的信息

    所属分类:[ php&web ] 猫哲学家 发表于:2012-07-28 18:15 浏览:465

    开心网openid接口,取刚登陆用户的信息,我测试过,可行,呵呵!欢迎交流。

    //  users.getInfo接口调用PHP实例 $api_key = 'xxxxxx'; $secret = 'xxxxxx'; $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.getLoggedInUser', //'uids' => '100099,100100', 'format' => 'json', 'session_key' => $session_key, ); $query = buildQuery($param, $secret); $result = postRequest($url, $query); $result = json_decode($result); print_r($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 
    上一编文章 开心网openid接口(php),取其它用户信息 下一编文章 ucenter home 的uid大于16777216怎么办呢?
    最近文章
    发表评论