Discuz!登录,注册,退出接口.

27 篇文章 0 订阅

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

 现在用Discuz! 6了.网上找了几个现成的接口都不能用,后来看见csdn论坛上面几个人说直接看文档.

文档很详细,照着文档写了个简单

需要配置的地方不多.

1.用户名,密码(如果没有用户就算注册进去了.)

'username'  => 'username',
  'password'  => md5('000000'),
  'email'   => 'linjin@ine.net.cn',

2.接口操作方式(登录,注册,退出)

$action  = 'login';  // 登录,注册
//$action  = 'logout'; // 退出

3.Discuz!的URL.

JsGoto("http://127.0.0.1/bbs/api/passport.php".
  "?action=$action".
  "&auth=".rawurlencode($auth).
  "&forward=".rawurlencode($forward).
  "&verify=$verify");

4.其它细节Discuz!文档

Discuz! Passport 接口技术文档

http://www.discuz.net/usersguide/advanced_passport.htm#title

<? php

// ///
/*
*
    * Passport 加密函数
    *
    * @param        string        等待加密的原字串
    * @param        string        私有密匙(用于解密和加密)
    *
    * @return    string        原字串经过私有密匙加密后的结果
    
*/
    
function  passport_encrypt( $txt ,   $key ) {

        
//  使用随机数发生器产生 0~32000 的值并 MD5()
         srand (( double ) microtime ()  *   1000000 );
        
$encrypt_key   =   md5 ( rand ( 0 ,   32000 ));

        
//  变量初始化
         $ctr   =   0 ;
        
$tmp   =   '' ;

        
//  for 循环,$i 为从 0 开始,到小于 $txt 字串长度的整数
         for ( $i   =   0 $i   <   strlen ( $txt );  $i ++ ) {
            
//  如果 $ctr = $encrypt_key 的长度,则 $ctr 清零
             $ctr   =   $ctr   ==   strlen ( $encrypt_key ?   0   :   $ctr ;
            
//  $tmp 字串在末尾增加两位,其第一位内容为 $encrypt_key 的第 $ctr 位,
            // 第二位内容为 $txt 的第 $i 位与 $encrypt_key 的 $ctr 位取异或。然后 $ctr = $ctr + 1

             $tmp   .=   $encrypt_key [ $ctr ] . ( $txt [ $i ^   $encrypt_key [ $ctr ++ ]);
        }

        
//  返回结果,结果为 passport_key() 函数返回值的 base64 编码结果
         return   base64_encode (passport_key( $tmp ,   $key ));

    }

    
/* *
    * Passport 解密函数
    *
    * @param        string        加密后的字串
    * @param        string        私有密匙(用于解密和加密)
    *
    * @return    string        字串经过私有密匙解密后的结果
    
*/
    
function  passport_decrypt( $txt ,   $key ) {

        
//  $txt 的结果为加密后的字串经过 base64 解码,然后与私有密匙一起,
        // 经过 passport_key() 函数处理后的返回值

         $txt   =  passport_key( base64_decode ( $txt ) ,   $key );

        
//  变量初始化
         $tmp   =   '' ;

        
//  for 循环,$i 为从 0 开始,到小于 $txt 字串长度的整数
         for  ( $i   =   0 $i   <   strlen ( $txt );  $i ++ ) {
            
//  $tmp 字串在末尾增加一位,其内容为 $txt 的第 $i 位,
            // 与 $txt 的第 $i + 1 位取异或。然后 $i = $i + 1

             $tmp   .=   $txt [ $i ^   $txt [ ++ $i ];
        }

        
//  返回 $tmp 的值作为结果
         return   $tmp ;

    }

    
/* *
    * Passport 密匙处理函数
    *
    * @param        string        待加密或待解密的字串
    * @param        string        私有密匙(用于解密和加密)
    *
    * @return    string        处理后的密匙
    
*/
    
function  passport_key( $txt ,   $encrypt_key ) {

        
//  将 $encrypt_key 赋为 $encrypt_key 经 md5() 后的值
         $encrypt_key   =   md5 ( $encrypt_key );

        
//  变量初始化
         $ctr   =   0 ;
        
$tmp   =   '' ;

        
//  for 循环,$i 为从 0 开始,到小于 $txt 字串长度的整数
         for ( $i   =   0 $i   <   strlen ( $txt );  $i ++ ) {
            
//  如果 $ctr = $encrypt_key 的长度,则 $ctr 清零
             $ctr   =   $ctr   ==   strlen ( $encrypt_key ?   0   :   $ctr ;
            
//  $tmp 字串在末尾增加一位,其内容为 $txt 的第 $i 位,
            // 与 $encrypt_key 的第 $ctr + 1 位取异或。然后 $ctr = $ctr + 1

             $tmp   .=   $txt [ $i ^   $encrypt_key [ $ctr ++ ];
        }

        
//  返回 $tmp 的值作为结果
         return   $tmp ;

    }

    
/* *
    * Passport 信息(数组)编码函数
    *
    * @param        array        待编码的数组
    *
    * @return    string        数组经编码后的字串
    
*/
    
function  passport_encode( $array ) {

        
//  数组变量初始化
         $arrayenc   =   array ();

        
//  遍历数组 $array,其中 $key 为当前元素的下标,$val 为其对应的值
         foreach ( $array   as   $key   =>   $val ) {
            
//  $arrayenc 数组增加一个元素,其内容为 "$key=经过 urlencode() 后的 $val 值"
             $arrayenc []  =   $key . ' = ' . urlencode ( $val );
        }

        
//  返回以 "&" 连接的 $arrayenc 的值(implode),例如 $arrayenc = array('aa', 'bb', 'cc', 'dd'),
        // 则 implode('&', $arrayenc) 后的结果为 ”aa&bb&cc&dd"

         return   implode ( ' & ' ,   $arrayenc );

    }

    
function  JsWrite( $msg
    {
        
echo   " <script language="javascript"> " ;
        
echo   $msg ;
        
echo   " </script> " ;
    }

    
function  JsGoto( $url
    {
        
$msg   =   " location.href = '$url'; " ;
        JsWrite(
$msg );
        
exit ;
    }

$passport_key   =   '' ;

$member   =   array
        (
        
' cookietime '   =>   time () ,
        
' time '           =>   time () ,
        
' username '       =>   'username ' ,
        
' password '       =>   md5 ( '0000 00 ' ) ,
        
' email '           =>   ' linjin@ine.net.cn ' ,
        
' credits '       =>   '' ,
        
' regip '           =>   '' ,
        
' regdate '       =>   '' ,
        
' msn '           =>   ''
        );


$action          =   ' login ' ;   //  登录,注册
//$action        = 'logout'; // 退出

$auth          =  passport_encrypt(passport_encode( $member ) ,   $passport_key );
$forward      =   ' http://127.0.0.1/bbs/index.php ' ;
$verify          =   md5 ( $action . $auth . $forward . $passport_key );

/*
header("Location: http://127.0.0.1/bbs/api/passport.php".
        "?action=$action".
        "&auth=".rawurlencode($auth).
        "&forward=".rawurlencode($forward).
        "&verify=$verify");
*/  


JsGoto(
" http://127.0.0.1/bbs/api/passport.php " .  
        
" ?action=$action " .
        
" &auth= " . rawurlencode ( $auth ) .
        
" &forward= " . rawurlencode ( $forward ) .
        
" &verify=$verify " );



?>
以下是Discuz! X的config_global.php配置文件的注释教程: ```php <?php /** * Discuz! X - 配置文件 * * 版权所有 (C) 2001-2019 Comsenz Inc. * This is NOT a freeware, use is subject to license terms * * $Id: config_global.php 36360 2019-11-18 00:28:51Z nemohou $ */ // ---------------------------- CONFIG DB ----------------------------- // /** * 数据库设置 * * type 数据库类型,可选值为 mysql 或 mysqli * server 数据库服务器 * port 数据库端口 * username 数据库用户名 * password 数据库密码 * dbname 数据库名 * pconnect 是否启用持久连接 * charset 数据库字符集,可选值为 gbk, big5, utf8, latin1, etc. * setnames 是否将字符集强制设为 utf8 * tablepre 表名前缀 * dbdebug 是否启用数据库调试模式 */ $_config['db']['1']['dbtype'] = 'mysql'; $_config['db']['1']['dbhost'] = 'localhost'; $_config['db']['1']['dbport'] = '3306'; $_config['db']['1']['dbuser'] = 'root'; $_config['db']['1']['dbpw'] = 'password'; $_config['db']['1']['dbname'] = 'discuz'; $_config['db']['1']['pconnect'] = '0'; $_config['db']['1']['charset'] = 'utf8'; $_config['db']['1']['setnames'] = '1'; $_config['db']['1']['tablepre'] = 'pre_'; $_config['db']['1']['dbdebug'] = 'false'; // -------------------------- CONFIG MEMORY --------------------------- // /** * 内存变量缓存设置 * * type 缓存类型,可选值为 filecache 或 memcache 或 apc * ttl 缓存失效时间,单位为秒 * prefix 缓存前缀,建议修改,避免同服务器中的程序引起冲突 * servers memcache 缓存服务器地址和端口,可指定多个,格式为数组 */ $_config['memory']['prefix'] = 'discuz_'; $_config['memory']['eaccelerator'] = false; $_config['memory']['apc'] = false; $_config['memory']['xcache'] = false; $_config['memory']['file']['server'] = array(); $_config['memory']['memcache']['server'] = array( array('127.0.0.1', 11211, 1), // 第一个参数为 memcache 服务器的地址,第二个参数为端口,第三个参数为权重,用于负载均衡,默认为1 ); // ----------------------------- CONFIG CACHE --------------------------- // /** * 数据缓存设置 * * type 缓存类型,可选值为 filecache 或 memcache 或 apc * ttl 缓存失效时间,单位为秒 * prefix 缓存前缀,建议修改,避免同服务器中的程序引起冲突 * filecache 设置缓存的目录,仅对 filecache 缓存有效 * servers memcache 缓存服务器地址和端口,可指定多个,格式为数组 * compress 是否启用 memcache 的压缩功能 */ $_config['cache']['type'] = 'filecache'; $_config['cache']['file']['server'] = array( array('localhost', 11211, 1), ); $_config['cache']['memcache']['server'] = array( array('localhost', 11211, 1), ); $_config['cache']['apc'] = false; $_config['cache']['ttl'] = 0; $_config['cache']['prefix'] = 'discuz_'; $_config['cache']['file']['dir'] = './data/cache/'; $_config['cache']['memcache']['compress'] = false; // ----------------------------- CONFIG SMTP --------------------------- // /** * 邮件设置 * * maildefault 默认的邮件发送方式,可选值为 smtp 或 sendmail * smtp 以下 SMTP 设置仅在 maildefault 为 smtp 时有效 * server SMTP 服务器地址 * port SMTP 服务器端口 * auth 是否启用 SMTP 认证,可选值为 true 或 false * username SMTP 服务器用户名 * password SMTP 服务器密码 * sendmail 以下 Sendmail 设置仅在 maildefault 为 sendmail 时有效 * server Sendmail 服务器地址 * sendmail_path Sendmail 程序路径 * * 注意:不同的邮件发送方式对应的设置选项不同,具体请参见官方文档 */ $_config['mail']['maildefault'] = 'smtp'; $_config['mail']['smtp']['server'] = 'smtp.exmail.qq.com'; $_config['mail']['smtp']['port'] = '25'; $_config['mail']['smtp']['auth'] = '1'; $_config['mail']['smtp']['username'] = 'admin@example.com'; $_config['mail']['smtp']['password'] = 'password'; $_config['mail']['sendmail']['server'] = '/usr/sbin/sendmail'; $_config['mail']['sendmail']['sendmail_path'] = ''; // ----------------------------- CONFIG SECURITY --------------------------- // /** * 安全设置 * * authkey 论坛加密密钥,建议修改,长度为 64 个字符 * cookiepre cookie 前缀,建议修改,避免同服务器中的程序引起冲突 * cachelist 缓存前缀列表,建议修改,避免同服务器中的程序引起冲突 * attackevasive 是否启用防抵制攻击功能,可选值为 0、1、2、3 或 4 * 0 表示关闭防抵制攻击功能 * 1 表示启用 cookie 刷新方式防抵制攻击功能 * 2 表示启用限制代理访问功能防抵制攻击功能 * 3 表示启用 cookie 刷新与限制代理访问两种方式的防抵制攻击功能 * 4 表示启用加强版防抵制攻击功能 * 注意:启用加强版防抵制攻击功能后,可能会影响网站的访问速度 * admincp_allow_ip 允许访问后台的 IP 地址列表,多个 IP 之间用英文逗号隔开 * admincp_check_ip 是否启用后台 IP 验证功能,可选值为 0 或 1 * admincp_cpsession 是否启用后台 session 验证功能,可选值为 0 或 1 */ $_config['security']['authkey'] = '1234567890123456789012345678901234567890123456789012345678901234'; $_config['security']['cookiepre'] = 'discuz_'; $_config['security']['cachelist'] = ''; $_config['security']['attackevasive'] = '0'; $_config['security']['admincp_allow_ip'] = ''; $_config['security']['admincp_check_ip'] = '1'; $_config['security']['admincp_cpsession'] = '1'; // ----------------------------- CONFIG SYSTEM --------------------------- // /** * 系统设置 * * debug 是否启用调试模式,可选值为 true 或 false * cookie_domain cookie 作用域 * cookie_path cookie 作用路径 * attachdir 附件上传目录,相对于论坛根目录的路径 * attachurl 附件 URL 地址 * attachimgpost 是否允许在帖子中显示图片附件,可选值为 0 或 1 * attachrefcheck 是否检查附件引用,可选值为 0 或 1 * attachsave 是否在服务器上保存上传的附件,可选值为 0 或 1 * attachimgmaxsize 图片类附件上传大小,单位为字节 * attachimgthumb 是否生成缩略图,可选值为 0 或 1 * attachimgquality 缩略图质量,取值范围为 1-100 * attachimgwatermark 是否添加水印,可选值为 0 或 1 * attachimgwatermarktype 水印类型,可选值为 text、image 或 none * attachimgwatermarktext 水印文字,当水印类型为 text 时有效 * attachimgwatermarktrans 水印透明度,取值范围为 1-100,当水印类型为 text 时有效 * attachimgwatermarkfile 水印图片文件名,当水印类型为 image 时有效 * attachimgwatermarkpos 水印位置,可选值为 1-9,当水印类型为 image 时有效 * refererhotlink 是否开启防盗链功能,可选值为 0 或 1 * hotlink_protect_key 防盗链密钥,如果不设置,则系统自动生成一个密钥 */ $_config['debug'] = false; $_config['cookie']['cookie_domain'] = ''; $_config['cookie']['cookie_path'] = '/'; $_config['attachdir'] = './data/attachment'; $_config['attachurl'] = 'attachment/'; $_config['attachimgpost'] = '1'; $_config['attachrefcheck'] = '1'; $_config['attachsave'] = '1'; $_config['attachimgmaxsize'] = '2048000'; $_config['attachimgthumb'] = '1'; $_config['attachimgquality'] = '80'; $_config['attachimgwatermark'] = '1'; $_config['attachimgwatermarktype'] = 'text'; $_config['attachimgwatermarktext'] = 'Discuz!'; $_config['attachimgwatermarktrans'] = '50'; $_config['attachimgwatermarkfile'] = ''; $_config['attachimgwatermarkpos'] = '9'; $_config['refererhotlink'] = '0'; $_config['hotlink_protect_key'] = ''; // ----------------------------- CONFIG OUTPUT --------------------------- // /** * 输出设置 * * output_gzip 是否启用 Gzip 压缩输出,可选值为 0 或 1 * output_charset 输出页面字符集,可选值为 gb2312、gbk、big5、utf-8 或 iso-8859-1 * output_language 输出页面语言,可选值为 en、zh-cn、zh-tw * output_encoding 输出页面编码格式,可选值为 xml、html、xhtml */ $_config['output']['gzip'] = '0'; $_config['output']['charset'] = 'utf-8'; $_config['output']['language'] = 'zh-cn'; $_config['output']['encoding'] = 'html'; ``` 以上就是Discuz! X的config_global.php配置文件的注释教程,希望能够帮助到你。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值