本帖最后由 xsflh 于 2010-9-19 13:40 编辑
<?php
define('YESWAN_SITE_ID', '301294');
define('YESWAN_SITE_KEY', '8ee579e3794cd84bf81d444c934b06e2');
define('YESWAN_API_CHKPASS_SUCCEED', 1);
define('YESWAN_API_CHKPASS_FAILED', -1);
$serverTimeOffset = date('Z');
$time = BeijingTimeStamp($serverTimeOffset);
if (!$_POST) {
exit('Invaild Request');
}
if ($time - $_POST['time'] > 1800) {
exit('Authracation has expiried');
}
$str = '';
ksort($_POST);
foreach ($_POST as $k=>$v) {
if (in_array($k, array('action', 'time', 'username', 'password'))) {
$str .= $k . '=' . $v . '&';
}
}
//php 32位加密
if ($_POST['mac'] != md5($str.YESWAN_SITE_KEY)) {
exit('Invaild Parameters');
}
$db_bbsurl = substr($db_bbsurl, -1) != '/' ? $db_bbsurl . '/' : $db_bbsurl;
$db_bbsurl = substr($db_bbsurl, 0, -4);
$return = array();
if ($_POST['action'] == 'verify') {
$return = array(
'sitename'
=> $db_bbsname,
'siteurl'
=> substr($db_bbsurl, -1) != '/' ? $db_bbsurl . '/' : $db_bbsurl,
'charset'
=> $db_charset,
);
} elseif ($_POST['action'] == 'login') {
$mysql_server_name="localhost"; //数据库服务器名称
$mysql_username="root"; // 连接数据库用户名
$mysql_password=""; // 连接数据库密码
$mysql_database="lanmei"; // 数据库的名字
$conn=mysql_connect($mysql_server_name, $mysql_username,$mysql_password);
// $sql = "SELECT uid, username, email, password FROM pw_members WHERE username='".$_POST['username']."'";
$sql="SELECT id ,username,password,email FROM user_tb where username='".$POST['username']."'";
//$query = mysql_query($sql);
//$result = array();
// $result = mysql_fetch_array($query);
$result=mysql_db_query($mysql_database, $sql, $conn);
$result = array();
if ($result['password'] != md5($_POST['password'])) {
$return = array('chkpass' => YESWAN_API_CHKPASS_FAILED);
} else {
$result['chkpass'] = YESWAN_API_CHKPASS_SUCCEED;
$return = $result;
}
}
$return = !is_array($return) || empty($return) ? array('error' => true) : $return;
$return['time'] = BeijingTimeStamp($serverTimeOffset);
$res = '';
ksort($return);
foreach ($return as $k=>$v) {
$res .= $k . '=' . $v . '&';
}
echo base64_encode($res);
function BeijingTimeStamp($serverTimeOffset) {
return $serverTimeOffset == 28800 ? time() : ( $serverTimeOffset <= 0 ? time() - 28800 + $serverTimeOffset : time() + 28800 - $serverTimeOffset );
}
?>
请大家帮忙看看。。
|