<script type="text/javascript"><!-- google_ad_client = "pub-0241434510974184"; /* auto-http.cn 右边 ,468x60 */ google_ad_slot = "0902256228"; google_ad_width = 468; google_ad_height = 60; // --></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
这个是Discuz!注册的接口代码.
注册的时候,页面可以不用跳转到Discuz!.
修改如下配置:
1.代码第5行.获取Discuz!的密钥.
路径: /Discuz!/forumdata/cache/cache_settings.php
// 密钥文件
$authkey = 'd99eb99UFBPcE0mv';//论坛的 authkey
2.代码7~13行,修改传递用的用户名,密码.
$array = array (
'action' => 'register', // login,register
'username' => 'username',
'password' => '000000',
'questionid' => '',
'answer' => '',);
3.140~141行.获取登录状态
登录状态:
1.登录成功,插入新用户
0.用户已经注册过了,或者注册失败.
$returnFlg = implode('', file('http://127.0.0.1/bbs/api/userprofile.php?sign='.$sign.'&'.$urlstr));
echo $returnFlg ;
<?
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
Discuz! orumdatacachecache_settings.php
$authkey
=
'
ece1b5LV9brA5wXR
'
;
//
论坛的authkey
$array
=
array
(
'
action
'
=>
'
register
'
,
//
login,register
'
username
'
=>
'
usename
'
,
'
password
'
=>
'
000000
'
,
'
questionid
'
=>
''
,
'
answer
'
=>
''
,
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$sign
=
$url
=
''
;
foreach
(
$array
as
$key
=>
$val
){
$sign
.=
'
&
'
.
$key
.
'
=
'
.
$val
;
$urlstr
.=
$key
.
'
=
'
.
rawurlencode
(
$val
)
.
'
&
'
;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$sign
=
md5
(
$sign
.
$authkey
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
///
/*
*
*Passport加密函数
*
*@paramstring等待加密的原字串
*@paramstring私有密匙(用于解密和加密)
*
*@returnstring原字串经过私有密匙加密后的结果
*/
function
passport_encrypt(
$txt
,
$key
){
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
使用随机数发生器产生0~32000的值并MD5()
srand
((
double
)
microtime
()
*
1000000
);
$encrypt_key
=
md5
(
rand
(
0
,
32000
));
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
变量初始化
$ctr
=
0
;
$tmp
=
''
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
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
++
]);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
返回结果,结果为passport_key()函数返回值的base64编码结果
return
base64_encode
(passport_key(
$tmp
,
$key
));
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
/*
*
*Passport解密函数
*
*@paramstring加密后的字串
*@paramstring私有密匙(用于解密和加密)
*
*@returnstring字串经过私有密匙解密后的结果
*/
function
passport_decrypt(
$txt
,
$key
){
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
$txt的结果为加密后的字串经过base64解码,然后与私有密匙一起,
//经过passport_key()函数处理后的返回值
$txt
=
passport_key(
base64_decode
(
$txt
)
,
$key
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
变量初始化
$tmp
=
''
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
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
];
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
返回$tmp的值作为结果
return
$tmp
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
/*
*
*Passport密匙处理函数
*
*@paramstring待加密或待解密的字串
*@paramstring私有密匙(用于解密和加密)
*
*@returnstring处理后的密匙
*/
function
passport_key(
$txt
,
$encrypt_key
){
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
将$encrypt_key赋为$encrypt_key经md5()后的值
$encrypt_key
=
md5
(
$encrypt_key
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
变量初始化
$ctr
=
0
;
$tmp
=
''
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
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
++
];
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
返回$tmp的值作为结果
return
$tmp
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
/*
*
*Passport信息(数组)编码函数
*
*@paramarray待编码的数组
*
*@returnstring数组经编码后的字串
*/
function
passport_encode(
$array
){
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
数组变量初始化
$arrayenc
=
array
();
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
遍历数组$array,其中$key为当前元素的下标,$val为其对应的值
foreach
(
$array
as
$key
=>
$val
){
//
$arrayenc数组增加一个元素,其内容为"$key=经过urlencode()后的$val值"
$arrayenc
[]
=
$key
.
'
=
'
.
urlencode
(
$val
);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
返回以"&"连接的$arrayenc的值(implode),例如$arrayenc=array('aa','bb','cc','dd'),
//则implode('&',$arrayenc)后的结果为”aa&bb&cc&dd"
return
implode
(
'
&
'
,
$arrayenc
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$returnFlg
=
implode
(
''
,
file
(
'
http://192.168.0.118:433/Discuz/api/userprofile.php?sign=
'
.
$sign
.
'
&
'
.
$urlstr
));
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
echo
$returnFlg
;
/*
if($returnFlg=="1")
{
header("Location:http://192.168.0.118:433/Discuz/index.php");
}
*/