ระบบนี้เป็น api ของ tmtopup ไว้สำหรับ เติมเครดิต และ วันใช้งาน vip
ผมอยากจะเอาเจ้าสองตัวนี้มารวมกันแต่ไม่ให้ฟังก์ชั่นมันชนกัน บางฟังก์ชั่นมันใช้รวมกันได้
เพราะด้วยข้อจำกัด tmtopup มันรัน api ได้แค่ลิ้งค์เดียว เลยอยากจะเอา เติมเครดิต กับ วันใช้งาน vip มาโมรวมกันแต่ไม่ค่อยเซียนเลยมาขอคำแนะนำพี่ๆหน่อยครับ
ไม่รู้ว่าผมอธิบายเข้าใจไหม

Code 1 เติมเครดิต
<?php
require_once('config/config_global.php');
require_once('AES.php');
if(isset($_config['server']['id']) == false)
{
$_config['server']['id'] = 1;
}
mysql_connect($_config['db'][$_config['server']['id']]['dbhost'],$_config['db'][$_config['server']['id']]['dbuser'],$_config['db'][$_config['server']['id']]['dbpw']) or die('ERROR|DB_CONN_ERROR|' . mysql_error());
mysql_select_db($_config['db'][$_config['server']['id']]['dbname']) or die('ERROR|DB_SEL_ERROR|' . mysql_error());
// กำหนด API Passkey
define('API_PASSKEY', '112233');
// กำหนด field , จำนวน credit : @begin
$_TMN['50']['extcredits2'] = 50;
$_TMN['90']['extcredits2'] = 100;
$_TMN['150']['extcredits2'] = 150;
$_TMN['300']['extcredits2'] = 300;
$_TMN['500']['extcredits2'] = 500;
$_TMN['1000']['extcredits2'] = 1000;
// กำหนด field , จำนวน credit : @end
if($_SERVER['REMOTE_ADDR'] == '203.146.127.115' && isset($_GET['request']))
{
$aes = new Crypt_AES();
$aes->setKey(API_PASSKEY);
$_GET['request'] = base64_decode(strtr($_GET['request'], '-_,', '+/='));
$_GET['request'] = $aes->decrypt($_GET['request']);
if($_GET['request'] != false)
{
parse_str($_GET['request'],$request);
$request['Ref1'] = base64_decode($request['Ref1']);
// discuz x : @begin
$result = mysql_query('SELECT `uid` FROM `' . $_config['db'][$_config['server']['id']]['tablepre'] . 'common_member` WHERE `username`=\'' . mysql_real_escape_string($request['Ref1']) . '\' LIMIT 1') or die(mysql_error());
if(mysql_num_rows($result) == 1)
{
// initiate extcredit fields : @begin
$extcredit_fields = '';
$extcredit_logfields = '';
$request['cardcard_amount'] = round($request['cardcard_amount']);
foreach($_TMN[$request['cardcard_amount']] as $key=>$val)
{
if(!empty($extcredit_fields))
{
$extcredit_fields .= ',';
}
$extcredit_fields .= '`' . $key . '`=`' . $key . '`+' . $val;
$extcredit_logfields .= ',`' . $key . '`=' . $val;
}
// initiate extcredit fields : @end
$row = mysql_fetch_assoc($result);
if(mysql_query('UPDATE `' . $_config['db'][$_config['server']['id']]['tablepre'] . 'common_member_count` SET ' . $extcredit_fields . ' WHERE `uid`=' . mysql_real_escape_string($row['uid']) . ' LIMIT 1') == false)
{
echo 'ERROR|MYSQL_UDT_ERROR|' . mysql_error();
}
else
{
mysql_query('INSERT INTO `' . $_config['db'][$_config['server']['id']]['tablepre'] . 'common_credit_log` SET `uid`=' . $row['uid'] . ',`operation`=\'RCV\',`relatedid`=' . $row['uid'] . ',`dateline`=UNIX_TIMESTAMP()' . $extcredit_logfields);
echo 'SUCCEED|UID=' . $row['uid'];
}
}
else
{
echo 'ERROR|INCORRECT_USERNAME';
}
// discuz x : @end
}
else
{
echo 'ERROR|INVALID_PASSKEY';
}
}
else
{
echo 'ERROR|ACCESS_DENIED';
}
?>
Code 2 เติมวันใช้งาน vip
<?php
require_once('config/config_global.php');
require_once('AES.php');
if(isset($_config['server']['id']) == false)
{
$_config['server']['id'] = 1;
}
mysql_connect($_config['db'][$_config['server']['id']]['dbhost'],$_config['db'][$_config['server']['id']]['dbuser'],$_config['db'][$_config['server']['id']]['dbpw']) or die('ERROR|DB_CONN_ERROR|' . mysql_error());
mysql_select_db($_config['db'][$_config['server']['id']]['dbname']) or die('ERROR|DB_SEL_ERROR|' . mysql_error());
// กำหนด API Passkey
define('API_PASSKEY', '112233');
// กำหนด groupid ของ VIP
define('VIP_GROUPID', '0');
// กำหนด adminid ของ VIP
define('VIP_ADMINID', '-1');
// กำหนด field , จำนวน credit : @begin
$_TMN['50']['vip'] = 5;
$_TMN['90']['vip'] = 10;
$_TMN['150']['vip'] = 15;
$_TMN['300']['vip'] = 30;
$_TMN['500']['vip'] = 50;
$_TMN['1000']['vip'] = 100;
// กำหนด field , จำนวน credit : @end
if($_SERVER['REMOTE_ADDR'] == '203.146.127.115' && isset($_GET['request']))
{
$aes = new Crypt_AES();
$aes->setKey(API_PASSKEY);
$_GET['request'] = base64_decode(strtr($_GET['request'], '-_,', '+/='));
$_GET['request'] = $aes->decrypt($_GET['request']);
if($_GET['request'] != false)
{
parse_str($_GET['request'],$request);
$request['Ref1'] = base64_decode($request['Ref1']);
// discuz x : @begin
$result = mysql_query('SELECT `uid`,`groupexpiry` FROM `' . $_config['db'][$_config['server']['id']]['tablepre'] . 'common_member` WHERE `username`=\'' . mysql_real_escape_string($request['Ref1']) . '\' LIMIT 1') or die(mysql_error());
if(mysql_num_rows($result) == 1)
{
$row = mysql_fetch_assoc($result);
// initiate extcredit fields : @begin
if($row['groupexpiry'] < time())
{
$groupexpiry = time() + ($_TMN[$request['cardcard_amount']]['vip']*86400);
}
else
{
$groupexpiry = $row['groupexpiry'] + ($_TMN[$request['cardcard_amount']]['vip']*86400);
}
$groupterms = array();
$groupterms['main'] = array('time' => $groupexpiry);
$groupterms['ext'][VIP_GROUPID] = $groupexpiry;
$grouptermsnew = addslashes(serialize($groupterms));
// initiate extcredit fields : @end
if(mysql_query('UPDATE `' . $_config['db'][$_config['server']['id']]['tablepre'] . 'common_member` SET groupid=' . VIP_GROUPID . ',adminid=' . VIP_ADMINID . ',groupexpiry=' . $groupexpiry . ' WHERE uid=' . $row['uid']) == false)
{
echo 'ERROR|MYSQL_UDT_ERROR|' . mysql_error();
}
else
{
mysql_query('UPDATE `' . $_config['db'][$_config['server']['id']]['tablepre'] . 'common_member_field_forum` SET groupterms=\'' . $grouptermsnew . '\' WHERE uid=' . $row['uid']);
echo 'SUCCEED|UID=' . $row['uid'];
}
}
else
{
echo 'ERROR|INCORRECT_USERNAME';
}
// discuz x : @end
}
else
{
echo 'ERROR|INVALID_PASSKEY';
}
}
else
{
echo 'ERROR|ACCESS_DENIED';
}
?>