现在的位置: 首页 > java > openfire > 正文
openfire与ucenter discuz注册进行整合
2012年05月02日 openfire, spark ⁄ 共 7400字 暂无评论

 function httpRequest($url,$post='',$method='GET',$limit=0,$returnHeader=FALSE,$cookie='',$bysocket=FALSE,$ip='',$timeout=15,$block=TRUE) {
    $return = '';
    $matches = parse_url($url);

    !isset($matches['host']) && $matches['host'] = '';
    !isset($matches['path']) && $matches['path'] = '';
    !isset($matches['query']) && $matches['query'] = '';
    !isset($matches['port']) && $matches['port'] = '';

    $host = $matches['host'];
    $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
    $port = !empty($matches['port']) ? $matches['port'] : 80;

    if(strtolower($method) == 'post') {
     $post = (is_array($post) and !empty($post)) ? http_build_query($post) : $post;
     $out = "POST $path HTTP/1.0rn";
     $out .= "Accept: */*rn";
     //$out .= "Referer: $boardurlrn";
     $out .= "Accept-Language: zh-cnrn";
     $out .= "Content-Type: application/x-www-form-urlencodedrn";
     $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
     $out .= "Host: $hostrn";
     $out .= 'Content-Length: '.strlen($post)."rn";
     $out .= "Connection: Closern";
     $out .= "Cache-Control: no-cachern";
     $out .= "Cookie: $cookiernrn";
     $out .= $post;
    } else {
     $out = "GET $path HTTP/1.0rn";
     $out .= "Accept: */*rn";
     //$out .= "Referer: $boardurlrn";
     $out .= "Accept-Language: zh-cnrn";
     $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
     $out .= "Host: $hostrn";
     $out .= "Connection: Closern";
     $out .= "Cookie: $cookiernrn";
    }

    $fp = fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);

    if(!$fp) return ''; else {
     $header = $content = '';

     stream_set_blocking($fp, $block);
     stream_set_timeout($fp, $timeout);
     fwrite($fp, $out);
     $status = stream_get_meta_data($fp);

     if(!$status['timed_out']) {//未超时
      while (!feof($fp)) {
       $header .= $h = fgets($fp);
       if($h && ($h == "rn" ||  $h == "n")) break;
      }

      $stop = false;
      while(!feof($fp) && !$stop) {
       $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
       $content .= $data;
       if($limit) {
        $limit -= strlen($data);
        $stop = $limit <= 0;
       }
      }
     }
  fclose($fp);

     return $returnHeader ? array($header,$content) : $content;
    }
 }
 
 echo httpRequest('http://192.168.1.102:9090/plugins/userService/userservice?type=add&secret=123456&username=1111111111111&password=drowssap&name=franz&email=franz@kafka.com'); 

 

 

以上是参考的代码  php实现httprequest

 

修改discuz代码如下:修改 class_member.php 在 source class目录下的这个文件

在589行下添加如下代码:

 //
 $url='http://www.dfdsaf.cn:9090/plugins/userService/userservice?type=add&secret=23423&username='.$_G['gp_username'].'&password='.$_G['gp_password'].'&name='.$_G['gp_username'].'&email='.$_G['gp_email'] .'';
   $method='GET';
    $limit=0;
    $returnHeader=FALSE;
    $cookie='';
    $bysocket=FALSE;
    $ip='';
    $timeout=15;$block=TRUE;
    $matches = parse_url($url);
   

    !isset($matches['host']) && $matches['host'] = '';
    !isset($matches['path']) && $matches['path'] = '';
    !isset($matches['query']) && $matches['query'] = '';
    !isset($matches['port']) && $matches['port'] = '';

    $host = $matches['host'];
    $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
    $port = !empty($matches['port']) ? $matches['port'] : 80;

    if(strtolower($method) == 'post') {
     $post = (is_array($post) and !empty($post)) ? http_build_query($post) : $post;
     $out = "POST $path HTTP/1.0rn";
     $out .= "Accept: */*rn";
     //$out .= "Referer: $boardurlrn";
     $out .= "Accept-Language: zh-cnrn";
     $out .= "Content-Type: application/x-www-form-urlencodedrn";
     $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
     $out .= "Host: $hostrn";
     $out .= 'Content-Length: '.strlen($post)."rn";
     $out .= "Connection: Closern";
     $out .= "Cache-Control: no-cachern";
     $out .= "Cookie: $cookiernrn";
     $out .= $post;
    } else {
     $out = "GET $path HTTP/1.0rn";
     $out .= "Accept: */*rn";
     //$out .= "Referer: $boardurlrn";
     $out .= "Accept-Language: zh-cnrn";
     $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
     $out .= "Host: $hostrn";
     $out .= "Connection: Closern";
     $out .= "Cookie: $cookiernrn";
    }

    $fp = fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);

    if(!$fp) return ''; else {
     $header = $content = '';

     stream_set_blocking($fp, $block);
     stream_set_timeout($fp, $timeout);
     fwrite($fp, $out);
     $status = stream_get_meta_data($fp);

     if(!$status['timed_out']) {//未超时
      while (!feof($fp)) {
       $header .= $h = fgets($fp);
       if($h && ($h == "rn" ||  $h == "n")) break;
      }

      $stop = false;
      while(!feof($fp) && !$stop) {
       $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
       $content .= $data;
       if($limit) {
        $limit -= strlen($data);
        $stop = $limit <= 0;
       }
      }
     }
  fclose($fp);

 
    }
 
 
 //

这样就能实现了discuz注册 也往openfire用户库注册了

 

 

discuz与 openfire  spark进行密码同步 。修改 souce/include/spacecp/space_profile.php  在 

loaducenter();
 $ucresult = uc_user_edit($_G['username'], $_G['gp_oldpassword'], $_G['gp_newpassword'], $emailnew != $_G['member']['email'] ? $emailnew : '', $ignorepassword, $_G['gp_questionidnew'], $_G['gp_answernew']);
 if($ucresult == -1) {
  showmessage('profile_passwd_wrong', '', array(), array('return' => true));
 } elseif($ucresult == -4) {
  showmessage('profile_email_illegal', '', array(), array('return' => true));
 } elseif($ucresult == -5) {
  showmessage('profile_email_domain_illegal', '', array(), array('return' => true));
 } elseif($ucresult == -6) {
  showmessage('profile_email_duplicate', '', array(), array('return' => true));
 } 下添加如下代码
emailnew != $_G['member']['email'] ? $emailnew : $_G['member']['email'];
// 
$url='http://www.ew.cn:9090/plugins/userService/userservice?type=update&secret=xueyiwang&username='.$_G['username'].'&password='.$_G['gp_newpassword'].'&name='.$_G['username'].'&email='.$emailnew .'';

 
 $method='GET';
    $limit=0;
    $returnHeader=FALSE;
    $cookie='';
    $bysocket=FALSE;
    $ip='';
    $timeout=15;$block=TRUE;
    $matches = parse_url($url);
   

    !isset($matches['host']) && $matches['host'] = '';
    !isset($matches['path']) && $matches['path'] = '';
    !isset($matches['query']) && $matches['query'] = '';
    !isset($matches['port']) && $matches['port'] = '';

    $host = $matches['host'];
    $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
    $port = !empty($matches['port']) ? $matches['port'] : 80;

    if(strtolower($method) == 'post') {
     $post = (is_array($post) and !empty($post)) ? http_build_query($post) : $post;
     $out = "POST $path HTTP/1.0rn";
     $out .= "Accept: */*rn";
     //$out .= "Referer: $boardurlrn";
     $out .= "Accept-Language: zh-cnrn";
     $out .= "Content-Type: application/x-www-form-urlencodedrn";
     $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
     $out .= "Host: $hostrn";
     $out .= 'Content-Length: '.strlen($post)."rn";
     $out .= "Connection: Closern";
     $out .= "Cache-Control: no-cachern";
     $out .= "Cookie: $cookiernrn";
     $out .= $post;
    } else {
     $out = "GET $path HTTP/1.0rn";
     $out .= "Accept: */*rn";
     //$out .= "Referer: $boardurlrn";
     $out .= "Accept-Language: zh-cnrn";
     $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
     $out .= "Host: $hostrn";
     $out .= "Connection: Closern";
     $out .= "Cookie: $cookiernrn";
    }

    $fp = fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);

    if(!$fp) return ''; else {
     $header = $content = '';

     stream_set_blocking($fp, $block);
     stream_set_timeout($fp, $timeout);
     fwrite($fp, $out);
     $status = stream_get_meta_data($fp);

     if(!$status['timed_out']) {//未超时
      while (!feof($fp)) {
       $header .= $h = fgets($fp);
       if($h && ($h == "rn" ||  $h == "n")) break;
      }

      $stop = false;
      while(!feof($fp) && !$stop) {
       $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
       $content .= $data;
       if($limit) {
        $limit -= strlen($data);
        $stop = $limit <= 0;
       }
      }
     }
  fclose($fp);

 
    }
 

// 这样就能实现用户修改密码与 同步了

给我留言

您必须 [ 登录 ] 才能发表留言!

×